[or-cvs] Remember when we received which service desc.
Nick Mathewson
nickm at seul.org
Wed Apr 7 22:00:57 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv6441/src/or
Modified Files:
connection_edge.c directory.c or.h rendclient.c rendcommon.c
Log Message:
Remember when we received which service desc.
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- connection_edge.c 7 Apr 2004 19:57:39 -0000 1.148
+++ connection_edge.c 7 Apr 2004 22:00:54 -0000 1.149
@@ -734,7 +734,7 @@
strcpy(conn->rend_query, socks->address); /* this strcpy is safe -RD */
log_fn(LOG_INFO,"Got a hidden service request for ID '%s'", conn->rend_query);
/* see if we already have it cached */
- if (rend_cache_lookup(conn->rend_query, &descp, &desc_len) == 1) {
+ if (rend_cache_lookup_desc(conn->rend_query, &descp, &desc_len) == 1) {
conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
return connection_ap_handshake_attach_circuit(conn);
} else {
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- directory.c 7 Apr 2004 19:57:39 -0000 1.84
+++ directory.c 7 Apr 2004 22:00:54 -0000 1.85
@@ -369,7 +369,7 @@
const char *descp;
int desc_len;
- switch(rend_cache_lookup(url+strlen(rend_fetch_url), &descp, &desc_len)) {
+ switch(rend_cache_lookup_desc(url+strlen(rend_fetch_url), &descp, &desc_len)) {
case 1: /* valid */
snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n\r\n",
desc_len); /* can't include descp here, because it's got nuls */
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.304
retrieving revision 1.305
diff -u -d -r1.304 -r1.305
--- or.h 7 Apr 2004 21:36:03 -0000 1.304
+++ or.h 7 Apr 2004 22:00:54 -0000 1.305
@@ -1078,10 +1078,18 @@
rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, int len);
int rend_get_service_id(crypto_pk_env_t *pk, char *out);
+typedef struct rend_cache_entry_t {
+ int len; /* Length of desc */
+ time_t received; /* When did we get the descriptor? */
+ char *desc; /* Service descriptor */
+ rend_service_descriptor_t *parsed; /* Parsed value of 'desc' */
+} rend_cache_entry_t;
+
void rend_cache_init(void);
void rend_cache_clean(void);
int rend_valid_service_id(char *query);
-int rend_cache_lookup(char *query, const char **desc, int *desc_len);
+int rend_cache_lookup_desc(char *query, const char **desc, int *desc_len);
+int rend_cache_lookup_entry(char *query, rend_cache_entry_t **entry_out);
int rend_cache_store(char *desc, int desc_len);
/********************************* rendservice.c ***************************/
Index: rendclient.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendclient.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- rendclient.c 6 Apr 2004 21:25:11 -0000 1.24
+++ rendclient.c 7 Apr 2004 22:00:54 -0000 1.25
@@ -57,7 +57,7 @@
assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY);
assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query));
- if(rend_cache_lookup(introcirc->rend_query, &descp, &desc_len) < 1) {
+ if(rend_cache_lookup_desc(introcirc->rend_query, &descp, &desc_len) < 1) {
log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.",
introcirc->rend_query);
goto err;
@@ -281,7 +281,7 @@
char *choice;
char *nickname;
- if(rend_cache_lookup(query, &descp, &desc_len) < 1) {
+ if(rend_cache_lookup_desc(query, &descp, &desc_len) < 1) {
log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", query);
return NULL;
}
Index: rendcommon.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendcommon.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- rendcommon.c 6 Apr 2004 20:25:18 -0000 1.20
+++ rendcommon.c 7 Apr 2004 22:00:54 -0000 1.21
@@ -143,12 +143,6 @@
#define REND_CACHE_MAX_AGE 24*60*60
#define REND_CACHE_MAX_SKEW 60*60
-typedef struct rend_cache_entry_t {
- int len; /* Length of desc */
- char *desc; /* Service descriptor */
- rend_service_descriptor_t *parsed; /* Parsed value of 'desc' */
-} rend_cache_entry_t;
-
static strmap_t *rend_cache = NULL;
/* Initializes the service descriptor cache.
@@ -193,26 +187,35 @@
return 1;
}
+int rend_cache_lookup_entry(char *query, rend_cache_entry_t **e)
+{
+ assert(rend_cache);
+ if (!rend_valid_service_id(query))
+ return -1;
+ *e = strmap_get_lc(rend_cache, query);
+ if (!*e)
+ return 0;
+ return 1;
+}
+
/* 'query' is a base-32'ed service id. If it's malformed, return -1.
* Else look it up.
* If it is found, point *desc to it, and write its length into
* *desc_len, and return 1.
* If it is not found, return 0.
*/
-int rend_cache_lookup(char *query, const char **desc, int *desc_len)
+int rend_cache_lookup_desc(char *query, const char **desc, int *desc_len)
{
rend_cache_entry_t *e;
- assert(rend_cache);
- if (!rend_valid_service_id(query))
- return -1;
- e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, query);
- if (!e)
- return 0;
+ int r;
+ r = rend_cache_lookup_entry(query,&e);
+ if (r <= 0) return r;
*desc = e->desc;
*desc_len = e->len;
return 1;
}
+
/* Calculate desc's service id, and store it.
* Return -1 if it's malformed or otherwise rejected, else return 0.
*/
@@ -252,6 +255,7 @@
}
if (e && e->len == desc_len && !memcmp(desc,e->desc,desc_len)) {
log_fn(LOG_WARN,"We already have this service descriptor");
+ e->received = time(NULL);
rend_service_descriptor_free(parsed);
return -1;
}
@@ -262,6 +266,7 @@
rend_service_descriptor_free(e->parsed);
tor_free(e->desc);
}
+ e->received = time(NULL);
e->parsed = parsed;
e->len = desc_len;
e->desc = tor_malloc(desc_len);
More information about the tor-commits
mailing list