summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-11-05 19:23:57 +0000
committerNick Mathewson <nickm@torproject.org>2007-11-05 19:23:57 +0000
commit42f7ae3eaeb3d0f1067234f3acf9c0f0f4e6cf1a (patch)
tree037ca463c31abe2bd69823238ae1c6e278fe283a
parentdec5fcd611e9865a4751379035c2bad4e57eb5e8 (diff)
downloadtor-42f7ae3eaeb3d0f1067234f3acf9c0f0f4e6cf1a.tar.gz
tor-42f7ae3eaeb3d0f1067234f3acf9c0f0f4e6cf1a.zip
r16435@catbus: nickm | 2007-11-05 14:23:07 -0500
Patch from karsten: tidy up v2 hidden service directory logic, and fix a few bugs. svn:r12388
-rw-r--r--src/or/directory.c17
-rw-r--r--src/or/or.h9
-rw-r--r--src/or/rendservice.c6
-rw-r--r--src/or/routerlist.c39
4 files changed, 25 insertions, 46 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 703cb55bca..b2b15cc4bb 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -3131,9 +3131,10 @@ directory_post_to_hs_dir(smartlist_t *desc_ids, smartlist_t *desc_strs,
hs_dir = smartlist_get(responsible_dirs, j);
/* Send publish request. */
directory_initiate_command_routerstatus(hs_dir,
- DIR_PURPOSE_UPLOAD_RENDDESC_V2,
- ROUTER_PURPOSE_GENERAL,
- 1, NULL, desc_str, strlen(desc_str), 0);
+ DIR_PURPOSE_UPLOAD_RENDDESC_V2,
+ ROUTER_PURPOSE_GENERAL,
+ 1, NULL, desc_str,
+ strlen(desc_str), 0);
base32_encode(desc_id_base32, sizeof(desc_id_base32),
desc_id, DIGEST_LEN);
log_info(LD_REND, "Sending publish request for v2 descriptor for "
@@ -3181,15 +3182,13 @@ directory_get_from_hs_dir(const char *desc_id, const char *query)
base32_encode(desc_id_base32, sizeof(desc_id_base32),
desc_id, DIGEST_LEN);
/* Send fetch request. */
- directory_initiate_command_routerstatus(
- hs_dir,
- DIR_PURPOSE_FETCH_RENDDESC_V2,
- ROUTER_PURPOSE_GENERAL,
- 1, desc_id_base32, NULL, 0, 0);
+ directory_initiate_command_routerstatus(hs_dir,
+ DIR_PURPOSE_FETCH_RENDDESC_V2,
+ ROUTER_PURPOSE_GENERAL,
+ 1, desc_id_base32, NULL, 0, 0);
log_info(LD_REND, "Sending fetch request for v2 descriptor for "
"service '%s' with descriptor ID '%s' to hidden "
"service directory '%s' on port %d.",
query, desc_id_base32, hs_dir->nickname, hs_dir->dir_port);
- smartlist_free(responsible_dirs);
}
diff --git a/src/or/or.h b/src/or/or.h
index 8dd6dc806c..a054e24df6 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3815,15 +3815,12 @@ void routerlist_assert_ok(routerlist_t *rl);
const char *esc_router_info(routerinfo_t *router);
void routers_sort_by_identity(smartlist_t *routers);
-smartlist_t *hid_serv_create_routing_table_st(void);
-int hid_serv_have_enough_directories(const smartlist_t *hs_dirs);
+int hid_serv_have_enough_directories(void);
int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
const char *id);
#if 0
-routerinfo_t *hid_serv_next_directory(const char *id,
- const smartlist_t *hs_dirs);
-routerinfo_t *hid_serv_previous_directory(const char *id,
- const smartlist_t *hs_dirs);
+routerstatus_t *hid_serv_next_directory(const char *id);
+routerstatus_t *hid_serv_previous_directory(const char *id);
#endif
int hid_serv_acting_as_directory(void);
int hid_serv_responsible_for_desc_id(const char *id);
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 0b9ec22357..f757ca5dd5 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -1100,8 +1100,7 @@ upload_service_descriptor(rend_service_t *service)
/* Upload v2 descriptor? */
if (service->descriptor_versions & (1 << 2) &&
get_options()->PublishHidServDescriptors) {
- smartlist_t *hs_dirs = hid_serv_create_routing_table_st();
- if (hid_serv_have_enough_directories(hs_dirs)) {
+ if (hid_serv_have_enough_directories()) {
int seconds_valid;
smartlist_t *desc_strs = smartlist_create();
smartlist_t *desc_ids = smartlist_create();
@@ -1112,7 +1111,6 @@ upload_service_descriptor(rend_service_t *service)
if (seconds_valid < 0) {
log_warn(LD_BUG, "Internal error: couldn't encode service descriptor; "
"not uploading.");
- smartlist_free(hs_dirs);
return;
}
/* Post the current descriptors to the hidden service directories. */
@@ -1143,7 +1141,6 @@ upload_service_descriptor(rend_service_t *service)
if (seconds_valid < 0) {
log_warn(LD_BUG, "Internal error: couldn't encode service "
"descriptor; not uploading.");
- smartlist_free(hs_dirs);
return;
}
directory_post_to_hs_dir(desc_ids, desc_strs, serviceid,
@@ -1159,7 +1156,6 @@ upload_service_descriptor(rend_service_t *service)
uploaded = 1;
log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
}
- smartlist_free(hs_dirs);
}
/* If not uploaded, try again in one minute. */
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 4aedb64cca..3fa6353d56 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -4309,7 +4309,6 @@ hid_serv_next_directory(const char *id)
int idx, i, f;
if (!c || !smartlist_len(c->routerstatus_list)) return NULL;
idx = networkstatus_vote_find_entry_idx(c, id, &f);
- if (f) ++idx;
if (idx >= smartlist_len(c->routerstatus_list))
idx = 0;
i = idx;
@@ -4350,13 +4349,23 @@ hid_serv_previous_directory(const char *id)
}
#endif
-/** Returns true, if we are aware of enough hidden service directory to
+/** Return true, if we are aware of enough hidden service directory to
* usefully perform v2 rend operations on them (publish, fetch, replicate),
* or false otherwise. */
int
-hid_serv_have_enough_directories(const smartlist_t *hs_dirs)
+hid_serv_have_enough_directories(void)
{
- return (smartlist_len(hs_dirs) > REND_NUMBER_OF_CONSECUTIVE_REPLICAS);
+ int n_hsdirs = 0;
+ networkstatus_vote_t *c = networkstatus_get_latest_consensus();
+ if (!c || !smartlist_len(c->routerstatus_list))
+ return 0;
+ SMARTLIST_FOREACH(c->routerstatus_list, routerstatus_t *, r,
+ {
+ if (r->is_hs_dir)
+ if (++n_hsdirs > REND_NUMBER_OF_CONSECUTIVE_REPLICAS)
+ return 1;
+ });
+ return 0;
}
/** Determine the REND_NUMBER_OF_CONSECUTIVE_REPLICAS routers that are
@@ -4375,7 +4384,6 @@ hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
}
tor_assert(id);
start = networkstatus_vote_find_entry_idx(c, id, &found);
- if (found) ++start;
if (start == smartlist_len(c->routerstatus_list)) start = 0;
i = start;
do {
@@ -4394,27 +4402,6 @@ hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
return -1;
}
-/** Create a list of routerstatus_t in ascending order of identity digests
- * containing all routers that have been assigned as hidden service
- * directories by the directory authorities; this list can be used as
- * hidden service routing table. */
-smartlist_t *
-hid_serv_create_routing_table_st(void)
-{
- smartlist_t *hs_dirs = smartlist_create();
- networkstatus_vote_t *c = networkstatus_get_latest_consensus();
- if (!c) return hs_dirs;
- /* Copy the routerstatus_t's of all hidden service directories to a new
- * smartlist. */
- SMARTLIST_FOREACH(c->routerstatus_list, routerstatus_t *, r,
- {
- if (r->is_hs_dir)
- smartlist_add(hs_dirs, r);
- });
- /* It's already sorted by ID. */
- return hs_dirs;
-}
-
/** Return true if this node is currently acting as hidden service
* directory, false otherwise. */
int