]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
added back support for SRC_RTT features. Help from Jon Kay patch.
authorwessels <>
Mon, 25 Aug 1997 08:17:45 +0000 (08:17 +0000)
committerwessels <>
Mon, 25 Aug 1997 08:17:45 +0000 (08:17 +0000)
src/cache_cf.cc
src/cf.data.pre
src/defines.h
src/neighbors.cc
src/peer_select.cc
src/store.cc
src/structs.h
src/typedefs.h

index 190597fdac4cc5f175fe71b0b54939e8a75bc5fd..8714dc102cfd05640049d0e484d71cf4cdf54598 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cache_cf.cc,v 1.217 1997/07/26 04:48:23 wessels Exp $
+ * $Id: cache_cf.cc,v 1.218 1997/08/25 02:17:45 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -523,6 +523,8 @@ parse_peer(peer ** head)
            p->options |= NEIGHBOR_MCAST_RESPONDER;
        } else if (!strncasecmp(token, "weight=", 7)) {
            p->weight = atoi(token + 7);
+       } else if (!strncasecmp(token, "closest-only", 12)) {
+           p->options |= NEIGHBOR_CLOSEST_ONLY;
        } else if (!strncasecmp(token, "ttl=", 4)) {
            p->mcast.ttl = atoi(token + 4);
            if (p->mcast.ttl < 0)
index 300d8ae9aef64eddb2b493e7f2aa9f2a6667dcae..2fd6b3788af9fd7909e4c2a64234c765241174e8 100644 (file)
@@ -143,6 +143,7 @@ DOC_START
                     default
                     round-robin
                     multicast-responder
+                    closest-only
 
                     use 'proxy-only' to specify that objects fetched
                     from this cache should not be saved locally.
@@ -175,6 +176,10 @@ DOC_START
                     not be sent directly to the peer, but ICP replies
                     will be accepted from it.
 
+                    'closest-only' indicates that, for ICP_OP_MISS
+                    replies, we'll only forward CLOSEST_PARENT_MISSes
+                    and never FIRST_PARENT_MISSes.
+
        NOTE: non-ICP neighbors must be specified as 'parent'.
 
 cache_host hostname type 3128 3130
index 2f2e5feefb5ecaea6fbb199622bdef86f5c0b077..d3bcb8b1c8ed5ff2797a59e5fd79a547455302f5 100644 (file)
 #define HIER_MAX_DEFICIT  20
 
 /* bitfields for peer->options */
-#define NEIGHBOR_PROXY_ONLY 0x01
-#define NEIGHBOR_NO_QUERY   0x02
-#define NEIGHBOR_DEFAULT_PARENT   0x04
-#define NEIGHBOR_ROUNDROBIN   0x08
-#define NEIGHBOR_MCAST_RESPONDER 0x10
+#define NEIGHBOR_PROXY_ONLY            0x01
+#define NEIGHBOR_NO_QUERY              0x02
+#define NEIGHBOR_DEFAULT_PARENT                0x04
+#define NEIGHBOR_ROUNDROBIN            0x08
+#define NEIGHBOR_MCAST_RESPONDER       0x10
+#define NEIGHBOR_CLOSEST_ONLY          0x20
 
 #define ICP_FLAG_HIT_OBJ     0x80000000ul
 #define ICP_FLAG_SRC_RTT     0x40000000ul
index 40d596c11a4679e88f2ca04677e32ca903226176..02b0a589dfded8aa82b8c6e622f0a52267e0ce62 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: neighbors.cc,v 1.156 1997/08/10 04:42:42 wessels Exp $
+ * $Id: neighbors.cc,v 1.157 1997/08/25 02:17:47 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -123,7 +123,7 @@ static CNCB peerCheckConnectDone;
 static void peerCountMcastPeersDone _PARAMS((void *data));
 static void peerCountMcastPeersStart _PARAMS((void *data));
 static void peerCountMcastPeersSchedule _PARAMS((peer * p, time_t when));
-static void peerCountHandleIcpReply _PARAMS((peer * p, peer_t type, icp_opcode op, void *data));
+static IRCB peerCountHandleIcpReply;
 
 static icp_common_t echo_hdr;
 static u_short echo_port;
@@ -444,9 +444,6 @@ neighborsUdpPing(request_t * request,
     }
     if (entry->swap_status != NO_SWAP)
        fatal_dump("neighborsUdpPing: bad swap_status");
-    mem->w_rtt = 0;
-    mem->e_pings_closest_parent = NULL;
-    mem->p_rtt = 0;
     mem->start_ping = current_time;
     mem->icp_reply_callback = callback;
     mem->ircb_data = callback_data;
@@ -655,7 +652,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc
            /* if we reach here, source-ping reply is the first 'parent',
             * so fetch directly from the source */
            debug(15, 6) ("Source is the first to respond.\n");
-           mem->icp_reply_callback(NULL, ntype, opcode, mem->ircb_data);
+           mem->icp_reply_callback(NULL, ntype, header, mem->ircb_data);
        }
     } else if (opcode == ICP_OP_MISS) {
        if (p == NULL) {
@@ -664,14 +661,15 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc
        } else if (ntype != PEER_PARENT) {
            (void) 0;           /* ignore MISS from non-parent */
        } else {
-           mem->icp_reply_callback(p, ntype, opcode, mem->ircb_data);
+           mem->icp_reply_callback(p, ntype, header, mem->ircb_data);
        }
     } else if (opcode == ICP_OP_HIT || opcode == ICP_OP_HIT_OBJ) {
        if (p == NULL) {
            debug(15, 1) ("Ignoring HIT from non-peer %s\n",
                inet_ntoa(from->sin_addr));
        } else {
-           mem->icp_reply_callback(p, ntype, ICP_OP_HIT, mem->ircb_data);
+           header->opcode = ICP_OP_HIT;
+           mem->icp_reply_callback(p, ntype, header, mem->ircb_data);
        }
     } else if (opcode == ICP_OP_DECHO) {
        if (p == NULL) {
@@ -681,7 +679,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc
            debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
            debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
        } else {
-           mem->icp_reply_callback(p, ntype, opcode, mem->ircb_data);
+           mem->icp_reply_callback(p, ntype, header, mem->ircb_data);
        }
     } else if (opcode == ICP_OP_SECHO) {
        if (p) {
@@ -690,7 +688,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc
        } else if (!Config.onoff.source_ping) {
            debug(15, 1) ("Unsolicited SECHO from %s\n", inet_ntoa(from->sin_addr));
        } else {
-           mem->icp_reply_callback(NULL, ntype, opcode, mem->ircb_data);
+           mem->icp_reply_callback(NULL, ntype, header, mem->ircb_data);
        }
     } else if (opcode == ICP_OP_DENIED) {
        if (p == NULL) {
@@ -707,7 +705,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc
            }
        }
     } else if (opcode == ICP_OP_MISS_NOFETCH) {
-       mem->icp_reply_callback(p, ntype, opcode, mem->ircb_data);
+       mem->icp_reply_callback(p, ntype, header, mem->ircb_data);
     } else {
        debug(15, 0) ("neighborsUdpAck: Unexpected ICP reply: %s\n", opcode_d);
     }
@@ -949,7 +947,7 @@ peerCountMcastPeersDone(void *data)
 }
 
 static void
-peerCountHandleIcpReply(peer * p, peer_t type, icp_opcode op, void *data)
+peerCountHandleIcpReply(peer * p, peer_t type, icp_common_t *hdr, void *data)
 {
     ps_state *psstate = data;
     psstate->icp.n_recv++;
index db3625152efe44c95af5286d9c46e407e40bb046..08674d1982f6fe7cd37b96a3d4479503c45e3153 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: peer_select.cc,v 1.25 1997/08/24 00:37:05 wessels Exp $
+ * $Id: peer_select.cc,v 1.26 1997/08/25 02:17:48 wessels Exp $
  *
  * DEBUG: section 44    Peer Selection Algorithm
  * AUTHOR: Duane Wessels
@@ -68,8 +68,10 @@ static char *DirectStr[] =
 static void peerSelectFoo _PARAMS((ps_state *));
 static void peerPingTimeout _PARAMS((void *data));
 static void peerSelectCallbackFail _PARAMS((ps_state * psstate));
-static void peerHandleIcpReply _PARAMS((peer * p, peer_t type, icp_opcode op, void *data));
+static IRCB peerHandleIcpReply;
 static void peerSelectStateFree _PARAMS((ps_state * psstate));
+static void peerIcpParentMiss _PARAMS((peer *, icp_common_t *, ps_state *));
+static int peerCheckNetdbDirect _PARAMS((ps_state * psstate));
 
 static void
 peerSelectStateFree(ps_state * psstate)
@@ -208,6 +210,29 @@ peerSelectCallbackFail(ps_state * psstate)
     /* XXX When this happens, the client request just hangs */
 }
 
+static int
+peerCheckNetdbDirect(ps_state * psstate)
+{
+    peer *p = psstate->closest_parent_miss;
+    int myrtt;
+    int myhops;
+    if (p == NULL)
+       return 0;
+    myrtt = netdbHostRtt(psstate->request->host);
+debug(44, 3) ("peerCheckNetdbDirect: MY RTT = %d\n", myrtt);
+debug(44, 3) ("peerCheckNetdbDirect: closest_parent_miss RTT = %d\n",
+       psstate->icp.p_rtt);
+    if (myrtt && myrtt < psstate->icp.p_rtt)
+       return 1;
+    myhops = netdbHostHops(psstate->request->host);
+debug(44, 3) ("peerCheckNetdbDirect: MY hops = %d\n", myhops);
+debug(44, 3) ("peerCheckNetdbDirect: minimum_direct_hops = %d\n",
+       Config.minDirectHops);
+    if (myhops && myhops <= Config.minDirectHops)
+       return 1;
+    return 0;
+}
+
 static void
 peerSelectFoo(ps_state * psstate)
 {
@@ -274,7 +299,17 @@ peerSelectFoo(ps_state * psstate)
        }
        debug_trap("peerSelect: neighborsUdpPing returned 0");
     }
-    if ((p = psstate->first_parent_miss)) {
+    if (peerCheckNetdbDirect(psstate)) {
+       code = CLOSEST_DIRECT;
+       debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], request->host);
+       hierarchyNote(&request->hier, code, &psstate->icp, request->host);
+       peerSelectCallback(psstate, NULL);
+    } else if ((p = psstate->closest_parent_miss)) {
+       code = CLOSEST_PARENT_MISS;
+       debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], p->host);
+       hierarchyNote(&request->hier, code, &psstate->icp, p->host);
+       peerSelectCallback(psstate, p);
+    } else if ((p = psstate->first_parent_miss)) {
        code = FIRST_PARENT_MISS;
        debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], p->host);
        hierarchyNote(&request->hier, code, &psstate->icp, p->host);
@@ -314,25 +349,49 @@ peerSelectInit(void)
     memset(&PeerStats, '\0', sizeof(PeerStats));
 }
 
+static void
+peerIcpParentMiss(peer * p, icp_common_t * header, ps_state * ps)
+{
+    int rtt;
+    int hops;
+    if (Config.onoff.query_icmp) {
+       if (BIT_TEST(header->flags, ICP_FLAG_SRC_RTT)) {
+           rtt = header->pad & 0xFFFF;
+           hops = (header->pad >> 16) & 0xFFFF;
+           if (rtt > 0 && rtt < 0xFFFF)
+               netdbUpdatePeer(ps->request, p, rtt, hops);
+           if (rtt && (ps->icp.p_rtt == 0 || rtt < ps->icp.p_rtt)) {
+               ps->closest_parent_miss = p;
+               ps->icp.p_rtt = rtt;
+           }
+       }
+    }
+    /* if closest-only is set, the don't allow FIRST_PARENT_MISS */
+    if (BIT_TEST(p->options, NEIGHBOR_CLOSEST_ONLY))
+       return;
+    /* set FIRST_MISS if thre is no CLOSEST parent */
+    if (ps->closest_parent_miss != NULL)
+       return;
+    rtt = tvSubMsec(ps->icp.start, current_time) / p->weight;
+    if (ps->icp.w_rtt == 0 || rtt < ps->icp.w_rtt) {
+       ps->first_parent_miss = p;
+       ps->icp.w_rtt = rtt;
+    }
+}
 
 static void
-peerHandleIcpReply(peer * p, peer_t type, icp_opcode op, void *data)
+peerHandleIcpReply(peer * p, peer_t type, icp_common_t * header, void *data)
 {
     ps_state *psstate = data;
-    int w_rtt;
+    icp_opcode op = header->opcode;
     request_t *request = psstate->request;
     debug(44, 3) ("peerHandleIcpReply: %s %s\n",
        IcpOpcodeStr[op],
        psstate->entry->url);
     psstate->icp.n_recv++;
     if (op == ICP_OP_MISS || op == ICP_OP_DECHO) {
-       if (type == PEER_PARENT) {
-           w_rtt = tvSubMsec(psstate->icp.start, current_time) / p->weight;
-           if (psstate->icp.w_rtt == 0 || w_rtt < psstate->icp.w_rtt) {
-               psstate->first_parent_miss = p;
-               psstate->icp.w_rtt = w_rtt;
-           }
-       }
+       if (type == PEER_PARENT)
+           peerIcpParentMiss(p, header, psstate);
     } else if (op == ICP_OP_HIT || op == ICP_OP_HIT_OBJ) {
        hierarchyNote(&request->hier,
            type == PEER_PARENT ? PARENT_HIT : SIBLING_HIT,
index d21f669d0d9ecfcfb21628a98d31946e394f218e..3a2a5f9ca379bf1bf8092e3612831467af765638 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.280 1997/08/10 05:05:33 wessels Exp $
+ * $Id: store.cc,v 1.281 1997/08/25 02:17:49 wessels Exp $
  *
  * DEBUG: section 20    Storeage Manager
  * AUTHOR: Harvest Derived
@@ -1334,6 +1334,8 @@ storeDoRebuildFromDisk(void *data)
            RB->invalid++;
            continue;
        }
+       if (strncmp(url, "http://internal.squid", 21) == 0)
+           continue;
        storeSwapFullPath(sfileno, swapfile);
        if (x != 9) {
            RB->invalid++;
@@ -2770,12 +2772,6 @@ storeMemObjectDump(MemObject * mem)
     debug(20, 1) ("MemObject->e_swap_buf: %p %s\n",
        mem->e_swap_buf,
        checkNullString(mem->e_swap_buf));
-    debug(20, 1) ("MemObject->w_rtt: %d\n",
-       mem->w_rtt);
-    debug(20, 1) ("MemObject->e_pings_closest_parent: %p\n",
-       mem->e_pings_closest_parent);
-    debug(20, 1) ("MemObject->p_rtt: %d\n",
-       mem->p_rtt);
     debug(20, 1) ("MemObject->start_ping: %d.%06d\n",
        mem->start_ping.tv_sec,
        mem->start_ping.tv_usec);
index e6dd6d454b3fcef7ce2f6693326d4adbad89b630..1575826cbf023cf93259cb48301ba88315d8687b 100644 (file)
@@ -407,6 +407,7 @@ struct _icp_ping_data {
     int n_replies_expected;
     int timeout;
     int w_rtt;
+    int p_rtt;
 };
 
 struct _HierarchyLogEntry {
@@ -730,9 +731,6 @@ struct _store_client {
 struct _MemObject {
     mem_hdr *data;
     char *e_swap_buf;
-    int w_rtt;                 /* weighted RTT in msec */
-    peer *e_pings_closest_parent;      /* parent with best RTT to source */
-    int p_rtt;                 /* parent's RTT to source */
     int e_swap_buf_len;
     unsigned char pending_list_size;
     int e_current_len;
index a69ff7354449b5cf837333b7cbec681c37f89edb..eb16323baa19cf0e2ecab5cbc20efb2c934b7b6c 100644 (file)
@@ -89,7 +89,7 @@ typedef int HASHCMP _PARAMS((const char *, const char *));
 typedef unsigned int HASHHASH _PARAMS((const char *, unsigned int));
 typedef void IDCB _PARAMS((void *));
 typedef void IPH _PARAMS((const ipcache_addrs *, void *));
-typedef void IRCB _PARAMS((peer *, peer_t, icp_opcode, void *data));
+typedef void IRCB _PARAMS((peer *, peer_t, icp_common_t *, void *data));
 typedef void PSC _PARAMS((peer *, void *));
 typedef void RH _PARAMS((void *data, char *result));