]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Removed 'method bits' hack from ICP query/reply. This will break
authorwessels <>
Fri, 11 Sep 1998 23:07:41 +0000 (23:07 +0000)
committerwessels <>
Fri, 11 Sep 1998 23:07:41 +0000 (23:07 +0000)
interoperability.  Instead the ICP server treats all queries as
METHOD_GET.

The ICP client code, however, uses an array of the most recent
8192 keys sent in ICP queries.  The reqnum is an index to this
array, so we can look up the key for an ICP reply easily.

Also changed storeKeyPublic and storeKeyPrivate to NOT use snprintf, but
just pass integers 'id' and 'method' directly to md5update.

src/client_side.cc
src/icmp.cc
src/icp_v2.cc
src/icp_v3.cc
src/neighbors.cc
src/protos.h
src/store.cc
src/store_key_md5.cc
src/structs.h

index 26f870e6c7dd7de0272c72fd93e1200e0e409518..f321d7ff36ca1cd3cb4273caa2cad6e7baf63e92 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.391 1998/09/04 23:04:39 wessels Exp $
+ * $Id: client_side.cc,v 1.392 1998/09/11 17:07:41 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -1503,7 +1503,7 @@ clientWriteComplete(int fd, char *bufnotused, size_t size, int errflag, void *da
     int done;
     http->out.size += size;
     debug(33, 5) ("clientWriteComplete: FD %d, sz %d, err %d, off %d, len %d\n",
-       fd, size, errflag, (int) http->out.offset, objectLen(entry));
+       fd, size, errflag, (int) http->out.offset, entry ? objectLen(entry) : 0);
     if (size > 0) {
        kb_incr(&Counter.client_http.kbytes_out, size);
        if (isTcpHit(http->log_type))
index d6d50a391e9104496648a3e581ecd4e55c8d5d82..749b965f2da8d3e177e0772a2610870a750ebc1c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: icmp.cc,v 1.63 1998/09/04 23:04:51 wessels Exp $
+ * $Id: icmp.cc,v 1.64 1998/09/11 17:07:43 wessels Exp $
  *
  * DEBUG: section 37    ICMP Routines
  * AUTHOR: Duane Wessels
@@ -126,11 +126,7 @@ icmpHandleSourcePing(const struct sockaddr_in *from, const char *buf)
     const char *url;
     xmemcpy(&header, buf, sizeof(icp_common_t));
     url = buf + sizeof(icp_common_t);
-    if (neighbors_do_private_keys && header.reqnum) {
-       key = storeKeyPrivate(url, METHOD_GET, header.reqnum);
-    } else {
-       key = storeKeyPublic(url, METHOD_GET);
-    }
+    key = icpGetCacheKey(url, (int) header.reqnum);
     debug(37, 3) ("icmpHandleSourcePing: from %s, key '%s'\n",
        inet_ntoa(from->sin_addr), storeKeyText(key));
     /* call neighborsUdpAck even if ping_status != PING_WAITING */
index 1a1ca93d0755f167e0451644d60d3b78af58313e..9b8c34c43cb59a76db65f2e762268b64ab3a8eae 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: icp_v2.cc,v 1.50 1998/09/04 23:04:52 wessels Exp $
+ * $Id: icp_v2.cc,v 1.51 1998/09/11 17:07:43 wessels Exp $
  *
  * DEBUG: section 12    Internet Cache Protocol
  * AUTHOR: Duane Wessels
@@ -191,7 +191,6 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len)
     icp_common_t *reply;
     int src_rtt = 0;
     u_num32 flags = 0;
-    method_t method;
     int rtt = 0;
     int hops = 0;
     xmemcpy(&header, buf, sizeof(icp_common_t));
@@ -203,10 +202,6 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len)
     header.flags = ntohl(header.flags);
     header.pad = ntohl(header.pad);
 
-    method = header.reqnum >> 24;
-    /* Squid-1.1 doesn't use the "method bits" for METHOD_GET */
-    if (METHOD_NONE == method || METHOD_ENUM_END <= method)
-       method = METHOD_GET;
     switch (header.opcode) {
     case ICP_QUERY:
        /* We have a valid packet */
@@ -217,7 +212,7 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len)
            icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
            break;
        }
-       if ((icp_request = urlParse(method, url)) == NULL) {
+       if ((icp_request = urlParse(METHOD_GET, url)) == NULL) {
            reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0);
            icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
            break;
@@ -248,7 +243,7 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len)
                flags |= ICP_FLAG_SRC_RTT;
        }
        /* The peer is allowed to use this cache */
-       key = storeKeyPublic(url, method);
+       key = storeKeyPublic(url, METHOD_GET);
        entry = storeGet(key);
        debug(12, 5) ("icpHandleIcpV2: OPCODE %s\n", icp_opcode_str[header.opcode]);
        if (icpCheckUdpHit(entry, icp_request)) {
@@ -293,10 +288,7 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len)
            icp_opcode_str[header.opcode],
            inet_ntoa(from.sin_addr),
            url);
-       if (neighbors_do_private_keys && header.reqnum)
-           key = storeKeyPrivate(url, method, header.reqnum);
-       else
-           key = storeKeyPublic(url, method);
+       key = icpGetCacheKey(url, (int) header.reqnum);
        /* call neighborsUdpAck even if ping_status != PING_WAITING */
        neighborsUdpAck(key, &header, &from);
        break;
@@ -539,3 +531,25 @@ icpCount(void *buf, int which, size_t len, int delay)
            Counter.icp.hits_recv++;
     }
 }
+
+#define N_QUERIED_KEYS 8192
+#define N_QUERIED_KEYS_MASK 8191
+static cache_key queried_keys[N_QUERIED_KEYS][MD5_DIGEST_CHARS];
+
+int
+icpSetCacheKey(const cache_key *key)
+{
+    static int reqnum = 0;
+    if (++reqnum < 0)
+       reqnum = 1;
+    storeKeyCopy(queried_keys[reqnum & N_QUERIED_KEYS_MASK], key);
+    return reqnum;
+}
+
+const cache_key *
+icpGetCacheKey(const char *url, int reqnum)
+{
+    if (neighbors_do_private_keys && reqnum)
+       return queried_keys[reqnum & N_QUERIED_KEYS_MASK];
+    return storeKeyPublic(url, METHOD_GET);
+}
index cf662b71c0ffb6d41c53f43e2b5a0c45192b9f24..a0de45cb83ca118f4be73a385c8286fe2228fe1a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: icp_v3.cc,v 1.24 1998/08/18 16:00:24 wessels Exp $
+ * $Id: icp_v3.cc,v 1.25 1998/09/11 17:07:44 wessels Exp $
  *
  * DEBUG: section 12    Internet Cache Protocol
  * AUTHOR: Duane Wessels
@@ -47,7 +47,6 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len)
     request_t *icp_request = NULL;
     int allow = 0;
     aclCheck_t checklist;
-    method_t method;
     xmemcpy(&header, buf, sizeof(icp_common_t));
     /*
      * Only these fields need to be converted
@@ -57,10 +56,6 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len)
     header.flags = ntohl(header.flags);
     header.pad = ntohl(header.pad);
 
-    method = header.reqnum >> 24;
-    /* Squid-1.1 doesn't use the "method bits" for METHOD_GET */
-    if (METHOD_NONE == method || METHOD_ENUM_END <= method)
-       method = METHOD_GET;
     switch (header.opcode) {
     case ICP_QUERY:
        /* We have a valid packet */
@@ -71,7 +66,7 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len)
            icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
            break;
        }
-       if ((icp_request = urlParse(method, url)) == NULL) {
+       if ((icp_request = urlParse(METHOD_GET, url)) == NULL) {
            reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0);
            icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
            break;
@@ -95,7 +90,7 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len)
            break;
        }
        /* The peer is allowed to use this cache */
-       key = storeKeyPublic(url, method);
+       key = storeKeyPublic(url, METHOD_GET);
        entry = storeGet(key);
        debug(12, 5) ("icpHandleIcpV3: OPCODE %s\n",
            icp_opcode_str[header.opcode]);
@@ -134,10 +129,7 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len)
            icp_opcode_str[header.opcode],
            inet_ntoa(from.sin_addr),
            url);
-       if (neighbors_do_private_keys && header.reqnum)
-           key = storeKeyPrivate(url, method, header.reqnum);
-       else
-           key = storeKeyPublic(url, method);
+       key = icpGetCacheKey(url, (int) header.reqnum);
        /* call neighborsUdpAck even if ping_status != PING_WAITING */
        neighborsUdpAck(key, &header, &from);
        break;
index 7476255c592f8152eb19f1d5553239518c296bba..8a6c94bd226bb3effa908bc3ba2923f886e76f2f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: neighbors.cc,v 1.243 1998/09/11 15:56:43 wessels Exp $
+ * $Id: neighbors.cc,v 1.244 1998/09/11 17:07:45 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -360,6 +360,7 @@ neighborsUdpPing(request_t * request,
     mem->ping_reply_callback = callback;
     mem->ircb_data = callback_data;
     *timeout = 0.0;
+    reqnum = icpSetCacheKey(entry->key);
     for (i = 0, p = first_ping; i++ < Config.npeers; p = p->next) {
        if (p == NULL)
            p = Config.peers;
@@ -371,7 +372,6 @@ neighborsUdpPing(request_t * request,
            p->host, url);
        if (p->type == PEER_MULTICAST)
            mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
-       reqnum = mem->reqnum;
        debug(15, 3) ("neighborsUdpPing: key = '%s'\n", storeKeyText(entry->key));
        debug(15, 3) ("neighborsUdpPing: reqnum = %d\n", reqnum);
 
@@ -977,6 +977,7 @@ peerCountMcastPeersStart(void *data)
     StoreEntry *fake;
     MemObject *mem;
     icp_common_t *query;
+    int reqnum;
     LOCAL_ARRAY(char, url, MAX_URL);
     assert(p->type == PEER_MULTICAST);
     p->mcast.flags &= ~PEER_COUNT_EVENT_PENDING;
@@ -995,8 +996,9 @@ peerCountMcastPeersStart(void *data)
     mem->ping_reply_callback = peerCountHandleIcpReply;
     mem->ircb_data = psstate;
     mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
-    p->mcast.reqnum = mem->reqnum;
-    query = icpCreateMessage(ICP_QUERY, 0, url, p->mcast.reqnum, 0);
+    p->mcast.id = mem->id;
+    reqnum = icpSetCacheKey(fake->key);
+    query = icpCreateMessage(ICP_QUERY, 0, url, reqnum, 0);
     icpUdpSend(theOutIcpConnection,
        &p->in_addr,
        query,
index 5c27cb335a9ddde5f2f079b0a42f0c572a628908..0b8647f5a033caa1a4157102cb52b105a19686ac 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.261 1998/09/10 19:50:55 wessels Exp $
+ * $Id: protos.h,v 1.262 1998/09/11 17:07:46 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -491,6 +491,8 @@ extern int icpCheckUdpHit(StoreEntry *, request_t * request);
 extern void icpConnectionsOpen(void);
 extern void icpConnectionShutdown(void);
 extern void icpConnectionClose(void);
+extern int icpSetCacheKey(const cache_key *key);
+extern const cache_key * icpGetCacheKey(const char *url, int reqnum);
 
 extern void ipcache_nbgethostbyname(const char *name,
     IPH * handler,
index 848486b8bee68e696f8b37fff2fc73fc756628cd..26a010587bb684f8953c58721e7169f5e7bed999 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.456 1998/09/10 19:50:56 wessels Exp $
+ * $Id: store.cc,v 1.457 1998/09/11 17:07:48 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager
  * AUTHOR: Harvest Derived
@@ -86,7 +86,7 @@ static MemObject *new_MemObject(const char *, const char *);
 static void destroy_MemObject(StoreEntry *);
 static FREE destroy_StoreEntry;
 static void storePurgeMem(StoreEntry *);
-static unsigned int getKeyCounter(method_t);
+static int getKeyCounter(void);
 static int storeKeepInMemory(const StoreEntry *);
 static OBJH storeCheckCachableStats;
 
@@ -279,13 +279,13 @@ storeGet(const cache_key * key)
     return (StoreEntry *) hash_lookup(store_table, key);
 }
 
-static unsigned int
-getKeyCounter(method_t method)
+static int
+getKeyCounter(void)
 {
-    static unsigned int key_counter = 0;
-    if (++key_counter == (1 << 24))
+    static int key_counter = 0;
+    if (++key_counter < 0)
        key_counter = 1;
-    return (method << 24) | key_counter;
+    return key_counter;
 }
 
 void
@@ -301,10 +301,10 @@ storeSetPrivateKey(StoreEntry * e)
        storeHashDelete(e);
     }
     if (mem != NULL) {
-       mem->reqnum = getKeyCounter(mem->method);
-       newkey = storeKeyPrivate(mem->url, mem->method, mem->reqnum);
+       mem->id = getKeyCounter();
+       newkey = storeKeyPrivate(mem->url, mem->method, mem->id);
     } else {
-       newkey = storeKeyPrivate("JUNK", METHOD_NONE, getKeyCounter(METHOD_NONE));
+       newkey = storeKeyPrivate("JUNK", METHOD_NONE, getKeyCounter());
     }
     assert(hash_lookup(store_table, newkey) == NULL);
     EBIT_SET(e->flag, KEY_PRIVATE);
index 1a57f7147a2e18de054d5372ee9a72253418a8ad..d2e11e59e1384ce7ef71ee7f7f2b457664880d84 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_key_md5.cc,v 1.14 1998/09/03 18:39:06 wessels Exp $
+ * $Id: store_key_md5.cc,v 1.15 1998/09/11 17:07:50 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager MD5 Cache Keys
  * AUTHOR: Duane Wessels
@@ -92,21 +92,17 @@ storeKeyHashHash(const void *key, unsigned int n)
 }
 
 const cache_key *
-storeKeyPrivate(const char *url, method_t method, int num)
+storeKeyPrivate(const char *url, method_t method, int id)
 {
     static cache_key digest[MD5_DIGEST_CHARS];
     MD5_CTX M;
-    int n;
-    char key_buf[MAX_URL + 100];
-    assert(num > 0);
+    assert(id > 0);
     debug(20, 3) ("storeKeyPrivate: %s %s\n",
        RequestMethodStr[method], url);
-    n = snprintf(key_buf, sizeof(key_buf), "%d %s %s",
-       num,
-       RequestMethodStr[method],
-       url);
     MD5Init(&M);
-    MD5Update(&M, (unsigned char *) key_buf, n);
+    MD5Update(&M, (unsigned char *) &id, sizeof(id));
+    MD5Update(&M, (unsigned char *) &method, sizeof(method));
+    MD5Update(&M, (unsigned char *) url, strlen(url));
     MD5Final(digest, &M);
     return digest;
 }
@@ -116,13 +112,9 @@ storeKeyPublic(const char *url, method_t method)
 {
     static cache_key digest[MD5_DIGEST_CHARS];
     MD5_CTX M;
-    int n;
-    char key_buf[MAX_URL + 100];
-    n = snprintf(key_buf, sizeof(key_buf), "%s %s",
-       RequestMethodStr[method],
-       url);
     MD5Init(&M);
-    MD5Update(&M, (unsigned char *) key_buf, n);
+    MD5Update(&M, (unsigned char *) &method, sizeof(method));
+    MD5Update(&M, (unsigned char *) url, strlen(url));
     MD5Final(digest, &M);
     return digest;
 }
index 6f6f5ac689a4eaf5193cc64ec82c698f2d81f48f..95db79c995422716016e3006ff50727d97e8a568 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.219 1998/09/09 20:05:54 wessels Exp $
+ * $Id: structs.h,v 1.220 1998/09/11 17:07:50 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -995,7 +995,7 @@ struct _peer {
        int n_times_counted;
        int n_replies_expected;
        int ttl;
-       u_num32 reqnum;
+       int id;
        int flags;
     } mcast;
     PeerDigest digest;
@@ -1167,7 +1167,7 @@ struct _MemObject {
     } abort;
     char *log_url;
     dlink_node lru;
-    u_num32 reqnum;
+    int id;
     ssize_t object_sz;
     size_t swap_hdr_sz;
 };