diff options
author | Roger Dingledine <arma@torproject.org> | 2004-04-18 09:04:37 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-04-18 09:04:37 +0000 |
commit | e9ebefc8bff3c472b22dd336aa41f8c59064087c (patch) | |
tree | 4d256e7ffcb4ee9e0f5846b74fcdd5290cf8f3b5 | |
parent | bce1fc43a23153a5935cfeb53839deb07389c881 (diff) | |
download | tor-e9ebefc8bff3c472b22dd336aa41f8c59064087c.tar tor-e9ebefc8bff3c472b22dd336aa41f8c59064087c.tar.gz |
bugfix: you mean we're supposed to reuse fresh descriptors and
refetch stale ones, not reuse stale ones and refetch fresh ones?
svn:r1667
-rw-r--r-- | src/or/connection_edge.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 46577ae32..c5fdd47fa 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -746,20 +746,35 @@ static int connection_ap_handshake_process_socks(connection_t *conn) { } else { /* it's a hidden-service request */ rend_cache_entry_t *entry; + int r; 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_entry(conn->rend_query, &entry) == 1 && -#define NUM_SECONDS_BEFORE_REFETCH (60*15) - entry->received + NUM_SECONDS_BEFORE_REFETCH < time(NULL)) { - conn->state = AP_CONN_STATE_CIRCUIT_WAIT; - return connection_ap_handshake_attach_circuit(conn); - } else { + r = rend_cache_lookup_entry(conn->rend_query, &entry); + if(r<0) { + log_fn(LOG_WARN,"Invalid service descriptor %s", conn->rend_query); + return -1; + } + if(r==0) { conn->state = AP_CONN_STATE_RENDDESC_WAIT; + log_fn(LOG_INFO, "Unknown descriptor %s. Fetching.", conn->rend_query); rend_client_refetch_renddesc(conn->rend_query); return 0; } + if(r>0) { +#define NUM_SECONDS_BEFORE_REFETCH (60*15) + if(time(NULL) - entry->received < NUM_SECONDS_BEFORE_REFETCH) { + conn->state = AP_CONN_STATE_CIRCUIT_WAIT; + log_fn(LOG_INFO, "Descriptor is here and fresh enough. Great."); + return connection_ap_handshake_attach_circuit(conn); + } else { + conn->state = AP_CONN_STATE_RENDDESC_WAIT; + log_fn(LOG_INFO, "Stale descriptor %s. Refetching.", conn->rend_query); + rend_client_refetch_renddesc(conn->rend_query); + return 0; + } + } } return 0; } |