/*
- * $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
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))
/*
- * $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
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 */
/*
- * $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
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));
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 */
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;
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)) {
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;
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);
+}
/*
- * $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
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
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 */
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;
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]);
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;
/*
- * $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
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;
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);
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;
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,
/*
- * $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/
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,
/*
- * $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
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;
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
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);
/*
- * $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
}
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;
}
{
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;
}
/*
- * $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/
int n_times_counted;
int n_replies_expected;
int ttl;
- u_num32 reqnum;
+ int id;
int flags;
} mcast;
PeerDigest digest;
} abort;
char *log_url;
dlink_node lru;
- u_num32 reqnum;
+ int id;
ssize_t object_sz;
size_t swap_hdr_sz;
};