Use descriptor ID when purging last hid fetch cache

Stop using an onion address since it's not indexed with that anymore in the
last hid serv request cache. Instead use a base32 encoded descriptor ID
contained in the rend_data_t object.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
This commit is contained in:
David Goulet 2015-04-27 16:21:47 -04:00 committed by Nick Mathewson
parent 9a364026d3
commit d33327ec22
4 changed files with 48 additions and 35 deletions

View File

@ -2149,7 +2149,7 @@ link_apconn_to_circ(entry_connection_t *apconn, origin_circuit_t *circ,
* that an attempt to connect to a hidden service just * that an attempt to connect to a hidden service just
* succeeded. Tell rendclient.c. */ * succeeded. Tell rendclient.c. */
rend_client_note_connection_attempt_ended( rend_client_note_connection_attempt_ended(
ENTRY_TO_EDGE_CONN(apconn)->rend_data->onion_address); ENTRY_TO_EDGE_CONN(apconn)->rend_data);
} }
if (cpath) { /* we were given one; use it */ if (cpath) { /* we were given one; use it */

View File

@ -102,8 +102,7 @@ connection_mark_unattached_ap_,(entry_connection_t *conn, int endreason,
* but we should fix it someday anyway. */ * but we should fix it someday anyway. */
if ((edge_conn->on_circuit != NULL || edge_conn->edge_has_sent_end) && if ((edge_conn->on_circuit != NULL || edge_conn->edge_has_sent_end) &&
connection_edge_is_rendezvous_stream(edge_conn)) { connection_edge_is_rendezvous_stream(edge_conn)) {
rend_client_note_connection_attempt_ended( rend_client_note_connection_attempt_ended(edge_conn->rend_data);
edge_conn->rend_data->onion_address);
} }
if (base_conn->marked_for_close) { if (base_conn->marked_for_close) {

View File

@ -474,9 +474,8 @@ rend_client_introduction_acked(origin_circuit_t *circ,
/** Contains the last request times to hidden service directories for /** Contains the last request times to hidden service directories for
* certain queries; each key is a string consisting of the * certain queries; each key is a string consisting of the
* concatenation of a base32-encoded HS directory identity digest, a * concatenation of a base32-encoded HS directory identity digest and
* base32-encoded HS descriptor ID, and a hidden service address * base32-encoded HS descriptor ID; each value is a pointer to a time_t
* (without the ".onion" part); each value is a pointer to a time_t
* holding the time of the last request for that descriptor ID to that * holding the time of the last request for that descriptor ID to that
* HS directory. */ * HS directory. */
static strmap_t *last_hid_serv_requests_ = NULL; static strmap_t *last_hid_serv_requests_ = NULL;
@ -492,8 +491,7 @@ get_last_hid_serv_requests(void)
} }
#define LAST_HID_SERV_REQUEST_KEY_LEN (REND_DESC_ID_V2_LEN_BASE32 + \ #define LAST_HID_SERV_REQUEST_KEY_LEN (REND_DESC_ID_V2_LEN_BASE32 + \
REND_DESC_ID_V2_LEN_BASE32 + \ REND_DESC_ID_V2_LEN_BASE32)
REND_SERVICE_ID_LEN_BASE32)
/** Look up the last request time to hidden service directory <b>hs_dir</b> /** Look up the last request time to hidden service directory <b>hs_dir</b>
* for descriptor ID <b>desc_id_base32</b>. If <b>set</b> is non-zero, * for descriptor ID <b>desc_id_base32</b>. If <b>set</b> is non-zero,
@ -554,20 +552,23 @@ directory_clean_last_hid_serv_requests(time_t now)
} }
} }
/** Remove all requests related to the hidden service named /** Remove all requests related to the descriptor ID <b>desc_id</b> from the
* <b>onion_address</b> from the history of times of requests to * history of times of requests to hidden service directories.
* hidden service directories. * <b>desc_id</b> is an unencoded descriptor ID of size DIGEST_LEN.
* *
* This is called from rend_client_note_connection_attempt_ended(), which * This is called from rend_client_note_connection_attempt_ended(), which
* must be idempotent, so any future changes to this function must leave * must be idempotent, so any future changes to this function must leave it
* it idempotent too. * idempotent too. */
*/
static void static void
purge_hid_serv_from_last_hid_serv_requests(const char *onion_address) purge_hid_serv_from_last_hid_serv_requests(const char *desc_id)
{ {
strmap_iter_t *iter; strmap_iter_t *iter;
strmap_t *last_hid_serv_requests = get_last_hid_serv_requests(); strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
/* XXX023 tor_assert(strlen(onion_address) == REND_SERVICE_ID_LEN_BASE32); */ char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
/* Key is stored with the base32 encoded desc_id. */
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_id,
DIGEST_LEN);
for (iter = strmap_iter_init(last_hid_serv_requests); for (iter = strmap_iter_init(last_hid_serv_requests);
!strmap_iter_done(iter); ) { !strmap_iter_done(iter); ) {
const char *key; const char *key;
@ -575,9 +576,9 @@ purge_hid_serv_from_last_hid_serv_requests(const char *onion_address)
strmap_iter_get(iter, &key, &val); strmap_iter_get(iter, &key, &val);
/* XXX023 tor_assert(strlen(key) == LAST_HID_SERV_REQUEST_KEY_LEN); */ /* XXX023 tor_assert(strlen(key) == LAST_HID_SERV_REQUEST_KEY_LEN); */
if (tor_memeq(key + LAST_HID_SERV_REQUEST_KEY_LEN - if (tor_memeq(key + LAST_HID_SERV_REQUEST_KEY_LEN -
REND_SERVICE_ID_LEN_BASE32, REND_DESC_ID_V2_LEN_BASE32,
onion_address, desc_id_base32,
REND_SERVICE_ID_LEN_BASE32)) { REND_DESC_ID_V2_LEN_BASE32)) {
iter = strmap_iter_next_rmv(last_hid_serv_requests, iter); iter = strmap_iter_next_rmv(last_hid_serv_requests, iter);
tor_free(val); tor_free(val);
} else { } else {
@ -1213,28 +1214,28 @@ rend_client_desc_trynow(const char *query)
"unavailable (try again later).", "unavailable (try again later).",
safe_str_client(query)); safe_str_client(query));
connection_mark_unattached_ap(conn, END_STREAM_REASON_RESOLVEFAILED); connection_mark_unattached_ap(conn, END_STREAM_REASON_RESOLVEFAILED);
rend_client_note_connection_attempt_ended(query); rend_client_note_connection_attempt_ended(rend_data);
} }
} SMARTLIST_FOREACH_END(base_conn); } SMARTLIST_FOREACH_END(base_conn);
} }
/** Clear temporary state used only during an attempt to connect to /** Clear temporary state used only during an attempt to connect to the
* the hidden service named <b>onion_address</b>. Called when a * hidden service with <b>rend_data</b>. Called when a connection attempt
* connection attempt has ended; it is possible for this to be called * has ended; it is possible for this to be called multiple times while
* multiple times while handling an ended connection attempt, and * handling an ended connection attempt, and any future changes to this
* any future changes to this function must ensure it remains * function must ensure it remains idempotent. */
* idempotent.
*/
void void
rend_client_note_connection_attempt_ended(const char *onion_address) rend_client_note_connection_attempt_ended(const rend_data_t *rend_data)
{ {
unsigned int have_onion = 0;
rend_cache_entry_t *cache_entry = NULL; rend_cache_entry_t *cache_entry = NULL;
/* Ignore return value; we find an entry, or we don't. */
(void) rend_cache_lookup_entry(onion_address, -1, &cache_entry);
log_info(LD_REND, "Connection attempt for %s has ended; " if (*rend_data->onion_address != '\0') {
"cleaning up temporary state.", /* Ignore return value; we find an entry, or we don't. */
safe_str_client(onion_address)); (void) rend_cache_lookup_entry(rend_data->onion_address, -1,
&cache_entry);
have_onion = 1;
}
/* Clear the timed_out flag on all remaining intro points for this HS. */ /* Clear the timed_out flag on all remaining intro points for this HS. */
if (cache_entry != NULL) { if (cache_entry != NULL) {
@ -1244,7 +1245,20 @@ rend_client_note_connection_attempt_ended(const char *onion_address)
} }
/* Remove the HS's entries in last_hid_serv_requests. */ /* Remove the HS's entries in last_hid_serv_requests. */
purge_hid_serv_from_last_hid_serv_requests(onion_address); if (have_onion) {
unsigned int replica;
for (replica = 0; replica < ARRAY_LENGTH(rend_data->descriptor_id);
replica++) {
const char *desc_id = rend_data->descriptor_id[replica];
purge_hid_serv_from_last_hid_serv_requests(desc_id);
}
log_info(LD_REND, "Connection attempt for %s has ended; "
"cleaning up temporary state.",
safe_str_client(rend_data->onion_address));
} else {
/* We only have an ID for a fetch. Probably used by HSFETCH. */
purge_hid_serv_from_last_hid_serv_requests(rend_data->desc_id_fetch);
}
} }
/** Return a newly allocated extend_info_t* for a randomly chosen introduction /** Return a newly allocated extend_info_t* for a randomly chosen introduction

View File

@ -41,7 +41,7 @@ int rend_client_receive_rendezvous(origin_circuit_t *circ,
size_t request_len); size_t request_len);
void rend_client_desc_trynow(const char *query); void rend_client_desc_trynow(const char *query);
void rend_client_note_connection_attempt_ended(const char *onion_address); void rend_client_note_connection_attempt_ended(const rend_data_t *rend_data);
extend_info_t *rend_client_get_random_intro(const rend_data_t *rend_query); extend_info_t *rend_client_get_random_intro(const rend_data_t *rend_query);
int rend_client_any_intro_points_usable(const rend_cache_entry_t *entry); int rend_client_any_intro_points_usable(const rend_cache_entry_t *entry);