aboutsummaryrefslogtreecommitdiff
path: root/src/or/rendservice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/rendservice.c')
-rw-r--r--src/or/rendservice.c96
1 files changed, 67 insertions, 29 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. */