mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Remember when we received which service desc.
svn:r1536
This commit is contained in:
parent
4d14b786da
commit
b07b2cef29
@ -734,7 +734,7 @@ static int connection_ap_handshake_process_socks(connection_t *conn) {
|
||||
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 {
|
||||
|
@ -369,7 +369,7 @@ static int directory_handle_command_get(connection_t *conn,
|
||||
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 */
|
||||
|
10
src/or/or.h
10
src/or/or.h
@ -1078,10 +1078,18 @@ int rend_encode_service_descriptor(rend_service_descriptor_t *desc,
|
||||
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 ***************************/
|
||||
|
@ -57,7 +57,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) {
|
||||
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 *rend_client_get_random_intro(char *query) {
|
||||
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;
|
||||
}
|
||||
|
@ -143,12 +143,6 @@ int rend_get_service_id(crypto_pk_env_t *pk, char *out)
|
||||
#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 @@ int rend_valid_service_id(char *query) {
|
||||
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 @@ int rend_cache_store(char *desc, int desc_len)
|
||||
}
|
||||
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 @@ int rend_cache_store(char *desc, int desc_len)
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user