aboutsummaryrefslogtreecommitdiff
path: root/src/or/rendclient.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-04-20 16:49:41 -0400
committerNick Mathewson <nickm@torproject.org>2011-04-27 00:01:41 -0400
commit748350ace11fa55758fb8bafe5e5556867dd9c23 (patch)
tree550360f9a4bea20cf638f6481d48cdeade5307b7 /src/or/rendclient.c
parentb8b557dcb2bf719976858589345f08fffbab13e3 (diff)
downloadtor-748350ace11fa55758fb8bafe5e5556867dd9c23.tar
tor-748350ace11fa55758fb8bafe5e5556867dd9c23.tar.gz
Instead of checking whether we have unremoved intro points, check for usable ones
Diffstat (limited to 'src/or/rendclient.c')
-rw-r--r--src/or/rendclient.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 90304c33c..d44461101 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -23,7 +23,8 @@
#include "routerlist.h"
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:
* 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,
"No more intro points remain for %s. Re-fetching descriptor.",
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);
if (rend_cache_lookup_entry(conn->rend_data->onion_address, -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
* valid entry from before which we should reuse */
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)
{
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 */
- if ((result = rend_client_get_random_intro_impl(rend_query, 1)))
+ if ((result = rend_client_get_random_intro_impl(entry, 1, 1)))
return result;
/* If not, and StrictNodes is not set, see if we can return any old node
*/
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;
}
@@ -757,23 +767,18 @@ rend_client_get_random_intro(const rend_data_t *rend_query)
* iff <b>strict</b> is true.
*/
static extend_info_t *
-rend_client_get_random_intro_impl(const rend_data_t *rend_query,
- const int strict)
+rend_client_get_random_intro_impl(const rend_cache_entry_t *entry,
+ const int strict,
+ const int warnings)
{
int i;
- rend_cache_entry_t *entry;
+
rend_intro_point_t *intro;
routerinfo_t *router;
or_options_t *options = get_options();
smartlist_t *usable_nodes;
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,
* no nodes are usable. */
usable_nodes = smartlist_create();
@@ -781,7 +786,7 @@ rend_client_get_random_intro_impl(const rend_data_t *rend_query,
again:
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'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 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
* rend_service_authorization_t*. */
static strmap_t *auth_hid_servs = NULL;