diff options
-rw-r--r-- | src/or/rendservice.c | 96 | ||||
-rw-r--r-- | src/or/routerlist.c | 54 | ||||
-rw-r--r-- | src/or/routerlist.h | 4 |
3 files changed, 67 insertions, 87 deletions
diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 037405463..f96850350 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -584,6 +584,71 @@ rend_config_services(const or_options_t *options, int validate_only) return 0; } +int +hid_serv_get_introduction_points(smartlist_t *introduction_points, + int number, + rend_service_t *service) +{ + int start, found, i; + const node_t *node = NULL; + + networkstatus_t *c = networkstatus_get_latest_consensus(); + + if (!c || !smartlist_len(c->routerstatus_list)) { + log_warn(LD_REND, "We don't have a consensus, so determine introduction " + "points"); + return -1; + } + + start = networkstatus_vote_find_entry_idx(c, service->pk_digest, &found); + + if (start == smartlist_len(c->routerstatus_list)) + start = 0; + + i = start; + + smartlist_t *current_intro_nodes = smartlist_new(); + + SMARTLIST_FOREACH_BEGIN(service->intro_nodes, rend_intro_point_t *, + intro) { + node = node_get_by_id(intro->extend_info->identity_digest); + smartlist_add(current_intro_nodes, (void*) node); + } SMARTLIST_FOREACH_END(intro); + + do { + routerstatus_t *r = smartlist_get(c->routerstatus_list, i); + + node = node_get_by_id(r->identity_digest); + + log_info(LD_REND, "considering node %s", + safe_str_client(node_describe(node))); + + if (!smartlist_contains(service->failed_intro_nodes, node) && + !smartlist_contains(current_intro_nodes, node) && + node->is_stable && + (node->ri || (node->rs && node->md))) { + + smartlist_add(introduction_points, (void*) node); + if (--number <= 0) { + smartlist_free(current_intro_nodes); + return 0; + } + } else { + log_info(LD_REND, "ignoring node %s ", + safe_str_client(node_describe(node))); + } + + if (++i == smartlist_len(c->routerstatus_list)) + i = 0; + } while (i != start); + + smartlist_free(current_intro_nodes); + + /* Even though we don't have the desired number of hidden service + * directories, be happy if we got any. */ + return smartlist_len(introduction_points) ? 0 : -1; +} + /** Replace the old value of <b>service</b>-\>desc with one that reflects * the other fields in service. */ @@ -3353,27 +3418,14 @@ rend_services_introduce(void) smartlist_t *potential_introduction_points = smartlist_new(); - smartlist_t *intros_to_ignore = smartlist_new(); - smartlist_add_all(intros_to_ignore, service->failed_intro_nodes); - - SMARTLIST_FOREACH_BEGIN(service->intro_nodes, rend_intro_point_t *, - intro) { - node = node_get_by_id(intro->extend_info->identity_digest); - smartlist_add(intros_to_ignore, (void*) node); - } SMARTLIST_FOREACH_END(intro); - if (hid_serv_get_introduction_points(potential_introduction_points, n_intro_points_to_open, - intros_to_ignore, // ignore the current introduction points - service->service_id) < 0) { + service) < 0) { log_warn(LD_REND, "Could not find any new introduction points"); smartlist_free(potential_introduction_points); - smartlist_free(intros_to_ignore); return; } - smartlist_free(intros_to_ignore); - for (j = 0; j < smartlist_len(potential_introduction_points); j++) { log_info(LD_REND, "looking at introduction point %i ", @@ -3398,22 +3450,11 @@ rend_services_introduce(void) { // debug purposes only smartlist_clear(potential_introduction_points); - intros_to_ignore = smartlist_new(); - smartlist_add_all(intros_to_ignore, service->failed_intro_nodes); - - SMARTLIST_FOREACH_BEGIN(service->intro_nodes, rend_intro_point_t *, - intro) { - node = node_get_by_id(intro->extend_info->identity_digest); - smartlist_add(intros_to_ignore, (void*) node); - } SMARTLIST_FOREACH_END(intro); - if (hid_serv_get_introduction_points(potential_introduction_points, 3, - intros_to_ignore, - service->service_id) < 0) { + service) < 0) { log_warn(LD_REND, "Could not find any new introduction points"); smartlist_free(potential_introduction_points); - smartlist_free(intros_to_ignore); return; } @@ -3424,11 +3465,8 @@ rend_services_introduce(void) safe_str_client(node_describe(node)), safe_str_client(service->service_id)); } - - smartlist_free(intros_to_ignore); } } - } /* If there's no need to launch new circuits, stop here. */ diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7f8151b59..2db72722d 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -5046,60 +5046,6 @@ hid_serv_get_responsible_directories(smartlist_t *responsible_dirs, return smartlist_len(responsible_dirs) ? 0 : -1; } -int -hid_serv_get_introduction_points(smartlist_t *introduction_points, - int number, - smartlist_t *excludedsmartlist, - const char *id) -{ - int start, found, i; - - networkstatus_t *c = networkstatus_get_latest_consensus(); - - if (!c || !smartlist_len(c->routerstatus_list)) { - log_warn(LD_REND, "We don't have a consensus, so determine introduction " - "points"); - return -1; - } - - tor_assert(id); - - start = networkstatus_vote_find_entry_idx(c, id, &found); - - if (start == smartlist_len(c->routerstatus_list)) - start = 0; - - i = start; - - do { - routerstatus_t *r = smartlist_get(c->routerstatus_list, i); - - node_t *node = node_get_by_id(r->identity_digest); - - log_info(LD_REND, "considering node %s", - safe_str_client(node_describe(node))); - - if ((!excludedsmartlist || !smartlist_contains(excludedsmartlist, node)) && - node->is_stable && - (node->ri || (node->rs && node->md))) { - - smartlist_add(introduction_points, node); - if (--number <= 0) - return 0; - } else { - log_info(LD_REND, "ignoring node %s ", - safe_str_client(node_describe(node))); - } - - if (++i == smartlist_len(c->routerstatus_list)) - i = 0; - } while (i != start); - - /* Even though we don't have the desired number of hidden service - * directories, be happy if we got any. */ - return smartlist_len(introduction_points) ? 0 : -1; -} - /** Return true if this node is currently acting as hidden service * directory, false otherwise. */ int diff --git a/src/or/routerlist.h b/src/or/routerlist.h index 2b1215353..e0260b788 100644 --- a/src/or/routerlist.h +++ b/src/or/routerlist.h @@ -181,10 +181,6 @@ void refresh_all_country_info(void); int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs, const char *id); -int hid_serv_get_introduction_points(smartlist_t *introduction_points, - int number, - smartlist_t *excludedsmartlist, - const char *id); int hid_serv_acting_as_directory(void); int hid_serv_responsible_for_desc_id(const char *id); |