Merge remote-tracking branch 'origin/maint-0.2.2'

Conflicts:
	src/or/rendclient.c
This commit is contained in:
Nick Mathewson 2011-06-02 15:07:08 -04:00
commit 587cc31140
5 changed files with 63 additions and 6 deletions

13
changes/bug3309 Normal file
View File

@ -0,0 +1,13 @@
o Minor bugfixes:
- Clear the table recording the time of the last request for each
hidden service descriptor from each HS directory on SIGNAL
NEWNYM. Previously, we would clear our HS descriptor cache on
SIGNAL NEWNYM, but if we had previously retrieved a descriptor
(or tried to) from every directory responsible for it, we would
refuse to fetch it again for up to 15 minutes. Bugfix on
0.2.2.25-alpha; fixes bug 3309.
o Minor features:
- Log (at info level) when purging pieces of hidden-service-client
state on SIGNAL NEWNYM.

View File

@ -1027,8 +1027,7 @@ signewnym_impl(time_t now)
circuit_expire_all_dirty_circs(); circuit_expire_all_dirty_circs();
addressmap_clear_transient(); addressmap_clear_transient();
rend_cache_purge(); rend_client_purge_state();
rend_client_cancel_descriptor_fetches();
time_of_last_signewnym = now; time_of_last_signewnym = now;
signewnym_is_pending = 0; signewnym_is_pending = 0;
} }

View File

@ -28,6 +28,16 @@ static extend_info_t *rend_client_get_random_intro_impl(
const rend_cache_entry_t *rend_query, const rend_cache_entry_t *rend_query,
const int strict, const int warnings); const int strict, const int warnings);
/** Purge all potentially remotely-detectable state held in the hidden
* service client code. Called on SIGNAL NEWNYM. */
void
rend_client_purge_state(void)
{
rend_cache_purge();
rend_client_cancel_descriptor_fetches();
rend_client_purge_last_hid_serv_requests();
}
/** Called when we've established a circuit to an introduction point: /** Called when we've established a circuit to an introduction point:
* send the introduction request. */ * send the introduction request. */
void void
@ -378,7 +388,17 @@ rend_client_introduction_acked(origin_circuit_t *circ,
* certain queries; keys are strings consisting of base32-encoded * certain queries; keys are strings consisting of base32-encoded
* hidden service directory identities and base32-encoded descriptor IDs; * hidden service directory identities and base32-encoded descriptor IDs;
* values are pointers to timestamps of the last requests. */ * values are pointers to timestamps of the last requests. */
static strmap_t *last_hid_serv_requests = NULL; static strmap_t *last_hid_serv_requests_ = NULL;
/** Returns last_hid_serv_requests_, initializing it to a new strmap if
* necessary. */
static strmap_t *
get_last_hid_serv_requests(void)
{
if (!last_hid_serv_requests_)
last_hid_serv_requests_ = strmap_new();
return last_hid_serv_requests_;
}
/** 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,
@ -392,6 +412,7 @@ lookup_last_hid_serv_request(routerstatus_t *hs_dir,
char hsdir_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1]; char hsdir_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
char hsdir_desc_comb_id[2 * REND_DESC_ID_V2_LEN_BASE32 + 1]; char hsdir_desc_comb_id[2 * REND_DESC_ID_V2_LEN_BASE32 + 1];
time_t *last_request_ptr; time_t *last_request_ptr;
strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
base32_encode(hsdir_id_base32, sizeof(hsdir_id_base32), base32_encode(hsdir_id_base32, sizeof(hsdir_id_base32),
hs_dir->identity_digest, DIGEST_LEN); hs_dir->identity_digest, DIGEST_LEN);
tor_snprintf(hsdir_desc_comb_id, sizeof(hsdir_desc_comb_id), "%s%s", tor_snprintf(hsdir_desc_comb_id, sizeof(hsdir_desc_comb_id), "%s%s",
@ -417,8 +438,7 @@ directory_clean_last_hid_serv_requests(time_t now)
{ {
strmap_iter_t *iter; strmap_iter_t *iter;
time_t cutoff = now - REND_HID_SERV_DIR_REQUERY_PERIOD; time_t cutoff = now - REND_HID_SERV_DIR_REQUERY_PERIOD;
if (!last_hid_serv_requests) strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
last_hid_serv_requests = strmap_new();
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;
@ -435,6 +455,26 @@ directory_clean_last_hid_serv_requests(time_t now)
} }
} }
/** Purge the history of request times to hidden service directories,
* so that future lookups of an HS descriptor will not fail because we
* accessed all of the HSDir relays responsible for the descriptor
* recently. */
void
rend_client_purge_last_hid_serv_requests(void)
{
/* Don't create the table if it doesn't exist yet (and it may very
* well not exist if the user hasn't accessed any HSes)... */
strmap_t *old_last_hid_serv_requests = last_hid_serv_requests_;
/* ... and let get_last_hid_serv_requests re-create it for us if
* necessary. */
last_hid_serv_requests_ = NULL;
if (old_last_hid_serv_requests != NULL) {
log_info(LD_REND, "Purging client last-HS-desc-request-time table");
strmap_free(old_last_hid_serv_requests, _tor_free);
}
}
/** Determine the responsible hidden service directories for <b>desc_id</b> /** Determine the responsible hidden service directories for <b>desc_id</b>
* and fetch the descriptor belonging to that ID from one of them. Only * and fetch the descriptor belonging to that ID from one of them. Only
* send a request to hidden service directories that we did not try within * send a request to hidden service directories that we did not try within

View File

@ -12,6 +12,8 @@
#ifndef _TOR_RENDCLIENT_H #ifndef _TOR_RENDCLIENT_H
#define _TOR_RENDCLIENT_H #define _TOR_RENDCLIENT_H
void rend_client_purge_state(void);
void rend_client_introcirc_has_opened(origin_circuit_t *circ); void rend_client_introcirc_has_opened(origin_circuit_t *circ);
void rend_client_rendcirc_has_opened(origin_circuit_t *circ); void rend_client_rendcirc_has_opened(origin_circuit_t *circ);
int rend_client_introduction_acked(origin_circuit_t *circ, int rend_client_introduction_acked(origin_circuit_t *circ,
@ -19,6 +21,7 @@ int rend_client_introduction_acked(origin_circuit_t *circ,
size_t request_len); size_t request_len);
void rend_client_refetch_v2_renddesc(const rend_data_t *rend_query); void rend_client_refetch_v2_renddesc(const rend_data_t *rend_query);
void rend_client_cancel_descriptor_fetches(void); void rend_client_cancel_descriptor_fetches(void);
void rend_client_purge_last_hid_serv_requests(void);
int rend_client_remove_intro_point(extend_info_t *failed_intro, int rend_client_remove_intro_point(extend_info_t *failed_intro,
const rend_data_t *rend_query); const rend_data_t *rend_query);
int rend_client_rendezvous_acked(origin_circuit_t *circ, int rend_client_rendezvous_acked(origin_circuit_t *circ,

View File

@ -838,8 +838,10 @@ rend_cache_clean(time_t now)
void void
rend_cache_purge(void) rend_cache_purge(void)
{ {
if (rend_cache) if (rend_cache) {
log_info(LD_REND, "Purging client/v0-HS-authority HS descriptor cache");
strmap_free(rend_cache, _rend_cache_entry_free); strmap_free(rend_cache, _rend_cache_entry_free);
}
rend_cache = strmap_new(); rend_cache = strmap_new();
} }