[or-cvs] r12388: Patch from karsten: tidy up v2 hidden service directory logi (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Mon Nov 5 19:23:57 UTC 2007


Author: nickm
Date: 2007-11-05 14:23:57 -0500 (Mon, 05 Nov 2007)
New Revision: 12388

Modified:
   tor/trunk/
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/rendservice.c
   tor/trunk/src/or/routerlist.c
Log:
 r16435 at catbus:  nickm | 2007-11-05 14:23:07 -0500
 Patch from karsten: tidy up v2 hidden service directory logic, and fix a few bugs.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16435] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-11-05 19:23:55 UTC (rev 12387)
+++ tor/trunk/src/or/directory.c	2007-11-05 19:23:57 UTC (rev 12388)
@@ -3131,9 +3131,10 @@
       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 @@
   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);
 }
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-11-05 19:23:55 UTC (rev 12387)
+++ tor/trunk/src/or/or.h	2007-11-05 19:23:57 UTC (rev 12388)
@@ -3815,15 +3815,12 @@
 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);

Modified: tor/trunk/src/or/rendservice.c
===================================================================
--- tor/trunk/src/or/rendservice.c	2007-11-05 19:23:55 UTC (rev 12387)
+++ tor/trunk/src/or/rendservice.c	2007-11-05 19:23:57 UTC (rev 12388)
@@ -1100,8 +1100,7 @@
   /* 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 @@
       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 @@
         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 @@
       uploaded = 1;
       log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
     }
-    smartlist_free(hs_dirs);
   }
 
   /* If not uploaded, try again in one minute. */

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-11-05 19:23:55 UTC (rev 12387)
+++ tor/trunk/src/or/routerlist.c	2007-11-05 19:23:57 UTC (rev 12388)
@@ -4309,7 +4309,6 @@
   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 @@
 }
 #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 @@
   }
   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 @@
   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



More information about the tor-commits mailing list