Instead of checking whether we have unremoved intro points, check for usable ones

This commit is contained in:
Nick Mathewson 2011-04-20 16:49:41 -04:00
parent b8b557dcb2
commit 748350ace1
3 changed files with 31 additions and 16 deletions

View File

@ -23,7 +23,8 @@
#include "routerlist.h" #include "routerlist.h"
static extend_info_t *rend_client_get_random_intro_impl( static extend_info_t *rend_client_get_random_intro_impl(
const rend_data_t *rend_query, const int strict); const rend_cache_entry_t *rend_query,
const int strict, const int warnings);
/** 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. */
@ -562,7 +563,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro,
} }
} }
if (smartlist_len(ent->parsed->intro_nodes) == 0) { if (! rend_client_any_intro_points_usable(ent)) {
log_info(LD_REND, log_info(LD_REND,
"No more intro points remain for %s. Re-fetching descriptor.", "No more intro points remain for %s. Re-fetching descriptor.",
escaped_safe_str_client(rend_query->onion_address)); escaped_safe_str_client(rend_query->onion_address));
@ -708,7 +709,7 @@ rend_client_desc_trynow(const char *query)
assert_connection_ok(TO_CONN(conn), now); assert_connection_ok(TO_CONN(conn), now);
if (rend_cache_lookup_entry(conn->rend_data->onion_address, -1, if (rend_cache_lookup_entry(conn->rend_data->onion_address, -1,
&entry) == 1 && &entry) == 1 &&
smartlist_len(entry->parsed->intro_nodes) > 0) { rend_client_any_intro_points_usable(entry)) {
/* either this fetch worked, or it failed but there was a /* either this fetch worked, or it failed but there was a
* valid entry from before which we should reuse */ * valid entry from before which we should reuse */
log_info(LD_REND,"Rend desc is usable. Launching circuits."); log_info(LD_REND,"Rend desc is usable. Launching circuits.");
@ -743,13 +744,22 @@ extend_info_t *
rend_client_get_random_intro(const rend_data_t *rend_query) rend_client_get_random_intro(const rend_data_t *rend_query)
{ {
extend_info_t *result; extend_info_t *result;
rend_cache_entry_t *entry;
if (rend_cache_lookup_entry(rend_query->onion_address, -1, &entry) < 1) {
log_warn(LD_REND,
"Query '%s' didn't have valid rend desc in cache. Failing.",
safe_str_client(rend_query->onion_address));
return NULL;
}
/* See if we can get a node that complies with ExcludeNodes */ /* See if we can get a node that complies with ExcludeNodes */
if ((result = rend_client_get_random_intro_impl(rend_query, 1))) if ((result = rend_client_get_random_intro_impl(entry, 1, 1)))
return result; return result;
/* If not, and StrictNodes is not set, see if we can return any old node /* If not, and StrictNodes is not set, see if we can return any old node
*/ */
if (!get_options()->StrictNodes) if (!get_options()->StrictNodes)
return rend_client_get_random_intro_impl(rend_query, 0); return rend_client_get_random_intro_impl(entry, 0, 1);
return NULL; return NULL;
} }
@ -757,23 +767,18 @@ rend_client_get_random_intro(const rend_data_t *rend_query)
* iff <b>strict</b> is true. * iff <b>strict</b> is true.
*/ */
static extend_info_t * static extend_info_t *
rend_client_get_random_intro_impl(const rend_data_t *rend_query, rend_client_get_random_intro_impl(const rend_cache_entry_t *entry,
const int strict) const int strict,
const int warnings)
{ {
int i; int i;
rend_cache_entry_t *entry;
rend_intro_point_t *intro; rend_intro_point_t *intro;
routerinfo_t *router; routerinfo_t *router;
or_options_t *options = get_options(); or_options_t *options = get_options();
smartlist_t *usable_nodes; smartlist_t *usable_nodes;
int n_excluded = 0; int n_excluded = 0;
if (rend_cache_lookup_entry(rend_query->onion_address, -1, &entry) < 1) {
log_warn(LD_REND,
"Query '%s' didn't have valid rend desc in cache. Failing.",
safe_str_client(rend_query->onion_address));
return NULL;
}
/* We'll keep a separate list of the usable nodes. If this becomes empty, /* We'll keep a separate list of the usable nodes. If this becomes empty,
* no nodes are usable. */ * no nodes are usable. */
usable_nodes = smartlist_create(); usable_nodes = smartlist_create();
@ -781,7 +786,7 @@ rend_client_get_random_intro_impl(const rend_data_t *rend_query,
again: again:
if (smartlist_len(usable_nodes) == 0) { if (smartlist_len(usable_nodes) == 0) {
if (n_excluded && get_options()->StrictNodes) { if (n_excluded && get_options()->StrictNodes && warnings) {
/* We only want to warn if StrictNodes is really set. Otherwise /* We only want to warn if StrictNodes is really set. Otherwise
* we're just about to retry anyways. * we're just about to retry anyways.
*/ */
@ -822,6 +827,15 @@ rend_client_get_random_intro_impl(const rend_data_t *rend_query,
return extend_info_dup(intro->extend_info); return extend_info_dup(intro->extend_info);
} }
/** Return true iff any introduction points still listed in <b>entry</b> are
* usable. */
int
rend_client_any_intro_points_usable(const rend_cache_entry_t *entry)
{
return rend_client_get_random_intro_impl(
entry, get_options()->StrictNodes, 0) != NULL;
}
/** Client-side authorizations for hidden services; map of onion address to /** Client-side authorizations for hidden services; map of onion address to
* rend_service_authorization_t*. */ * rend_service_authorization_t*. */
static strmap_t *auth_hid_servs = NULL; static strmap_t *auth_hid_servs = NULL;

View File

@ -29,6 +29,7 @@ int rend_client_receive_rendezvous(origin_circuit_t *circ,
void rend_client_desc_trynow(const char *query); void rend_client_desc_trynow(const char *query);
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_send_introduction(origin_circuit_t *introcirc, int rend_client_send_introduction(origin_circuit_t *introcirc,
origin_circuit_t *rendcirc); origin_circuit_t *rendcirc);

View File

@ -934,7 +934,7 @@ rend_cache_lookup_entry(const char *query, int version, rend_cache_entry_t **e)
tor_assert((*e)->parsed && (*e)->parsed->intro_nodes); tor_assert((*e)->parsed && (*e)->parsed->intro_nodes);
/* XXX023 hack for now, to return "not found" if there are no intro /* XXX023 hack for now, to return "not found" if there are no intro
* points remaining. See bug 997. */ * points remaining. See bug 997. */
if (smartlist_len((*e)->parsed->intro_nodes) == 0) if (! rend_client_any_intro_points_usable(*e))
return 0; return 0;
return 1; return 1;
} }