commit e167910fce2b83d9de3a252cdf02cabdafced14b
Author: Roger Dingledine <a...@torproject.org>
Date:   Fri Mar 11 10:40:31 2016 -0500

    rip out hid_serv_responsible_for_desc_id()
    
    This simplifies relay behavior, because the relay offers the hsdir
    functionality independent of whether the directory authorities have
    decided this relay is suitable for clients to use yet.
    
    Implements ticket 18332.
---
 changes/ticket18332            |  7 +++++
 src/or/rendcache.c             | 11 +------
 src/or/rendcommon.c            | 26 -----------------
 src/or/rendcommon.h            |  1 -
 src/test/test_dir_handle_get.c | 12 --------
 src/test/test_rendcache.c      | 66 ------------------------------------------
 6 files changed, 8 insertions(+), 115 deletions(-)

diff --git a/changes/ticket18332 b/changes/ticket18332
new file mode 100644
index 0000000..6fb8118
--- /dev/null
+++ b/changes/ticket18332
@@ -0,0 +1,7 @@
+  o Removed features:
+    - Streamline relay-side hsdir handling: when relays consider whether
+      to accept an uploaded hidden service descriptor, they no longer
+      check whether directory authorities think they deserve the HSDir
+      flag, or whether they are one of the relays in the network that is
+      "supposed" to handle that descriptor. Implements ticket 18332.
+
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index cb8c14b..6c22503 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -483,8 +483,7 @@ rend_cache_clean_v2_descs_as_dir(time_t now, size_t 
force_remove)
       digestmap_iter_get(iter, &key, &val);
       ent = val;
       if (ent->parsed->timestamp < cutoff ||
-          ent->last_served < last_served_cutoff ||
-          !hid_serv_responsible_for_desc_id(key)) {
+          ent->last_served < last_served_cutoff) {
         char key_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
         base32_encode(key_base32, sizeof(key_base32), key, DIGEST_LEN);
         log_info(LD_REND, "Removing descriptor with ID '%s' from cache",
@@ -657,14 +656,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
     /* For pretty log statements. */
     base32_encode(desc_id_base32, sizeof(desc_id_base32),
                   desc_id, DIGEST_LEN);
-    /* Is desc ID in the range that we are (directly or indirectly) responsible
-     * for? */
-    if (!hid_serv_responsible_for_desc_id(desc_id)) {
-      log_info(LD_REND, "Service descriptor with desc ID %s is not in "
-               "interval that we are responsible for.",
-               safe_str_client(desc_id_base32));
-      goto skip;
-    }
     /* Is descriptor too old? */
     if (parsed->timestamp < now - REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
       log_info(LD_REND, "Service descriptor with desc ID %s is too old.",
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 79509cb..f1fb0d9 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -983,29 +983,3 @@ hid_serv_acting_as_directory(void)
   return 1;
 }
 
-/** Return true if this node is responsible for storing the descriptor ID
- * in <b>query</b> and false otherwise. */
-MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
-          (const char *query))
-{
-  const routerinfo_t *me;
-  routerstatus_t *last_rs;
-  const char *my_id, *last_id;
-  int result;
-  smartlist_t *responsible;
-  if (!hid_serv_acting_as_directory())
-    return 0;
-  if (!(me = router_get_my_routerinfo()))
-    return 0; /* This is redundant, but let's be paranoid. */
-  my_id = me->cache_info.identity_digest;
-  responsible = smartlist_new();
-  if (hid_serv_get_responsible_directories(responsible, query) < 0) {
-    smartlist_free(responsible);
-    return 0;
-  }
-  last_rs = smartlist_get(responsible, smartlist_len(responsible)-1);
-  last_id = last_rs->identity_digest;
-  result = rend_id_is_in_interval(my_id, query, last_id);
-  smartlist_free(responsible);
-  return result;
-}
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index fe45299..b3ae790 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -60,7 +60,6 @@ void rend_get_descriptor_id_bytes(char *descriptor_id_out,
 int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
                                                                         const 
char *id);
 int hid_serv_acting_as_directory(void);
-MOCK_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
 
 rend_data_t *rend_data_dup(const rend_data_t *data);
 rend_data_t *rend_data_client_create(const char *onion_address,
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index 954830d..67bd840 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -389,10 +389,8 @@ test_dir_handle_get_rendezvous2_not_found(void *data)
 }
 
 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
-NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
 
 static routerinfo_t *mock_routerinfo;
-static int hid_serv_responsible_for_desc_id_response;
 
 static const routerinfo_t *
 NS(router_get_my_routerinfo)(void)
@@ -404,13 +402,6 @@ NS(router_get_my_routerinfo)(void)
   return mock_routerinfo;
 }
 
-static int
-NS(hid_serv_responsible_for_desc_id)(const char *id)
-{
-  (void)id;
-  return hid_serv_responsible_for_desc_id_response;
-}
-
 static void
 test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
 {
@@ -428,10 +419,8 @@ 
test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
 
   MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
   NS_MOCK(router_get_my_routerinfo);
-  NS_MOCK(hid_serv_responsible_for_desc_id);
 
   rend_cache_init();
-  hid_serv_responsible_for_desc_id_response = 1;
 
   /* create a valid rend service descriptor */
   #define RECENT_TIME -10
@@ -473,7 +462,6 @@ 
test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
   done:
     UNMOCK(connection_write_to_buf_impl_);
     NS_UNMOCK(router_get_my_routerinfo);
-    NS_UNMOCK(hid_serv_responsible_for_desc_id);
     tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
     tor_free(mock_routerinfo);
 
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index eaa8671..9898e87 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -377,10 +377,8 @@ 
test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
 
 #define NS_SUBMODULE lookup_v2_desc_as_dir
 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
-NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
 
 static routerinfo_t *mock_routerinfo;
-static int hid_serv_responsible_for_desc_id_response;
 
 static const routerinfo_t *
 NS(router_get_my_routerinfo)(void)
@@ -392,13 +390,6 @@ NS(router_get_my_routerinfo)(void)
   return mock_routerinfo;
 }
 
-static int
-NS(hid_serv_responsible_for_desc_id)(const char *id)
-{
-  (void)id;
-  return hid_serv_responsible_for_desc_id_response;
-}
-
 static void
 test_rend_cache_lookup_v2_desc_as_dir(void *data)
 {
@@ -411,7 +402,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
   (void)data;
 
   NS_MOCK(router_get_my_routerinfo);
-  NS_MOCK(hid_serv_responsible_for_desc_id);
 
   rend_cache_init();
 
@@ -425,7 +415,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
   tt_int_op(ret, OP_EQ, 0);
 
   // Test existing descriptor
-  hid_serv_responsible_for_desc_id_response = 1;
   generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
   rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
   base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
@@ -436,7 +425,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
 
  done:
   NS_UNMOCK(router_get_my_routerinfo);
-  NS_UNMOCK(hid_serv_responsible_for_desc_id);
   tor_free(mock_routerinfo);
   rend_cache_free_all();
   rend_encoded_v2_service_descriptor_free(desc_holder);
@@ -447,7 +435,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
 
 #define NS_SUBMODULE store_v2_desc_as_dir
 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
-NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
 
 static const routerinfo_t *
 NS(router_get_my_routerinfo)(void)
@@ -455,13 +442,6 @@ NS(router_get_my_routerinfo)(void)
   return mock_routerinfo;
 }
 
-static int
-NS(hid_serv_responsible_for_desc_id)(const char *id)
-{
-  (void)id;
-  return hid_serv_responsible_for_desc_id_response;
-}
-
 static void
 test_rend_cache_store_v2_desc_as_dir(void *data)
 {
@@ -471,7 +451,6 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
   char *service_id = NULL;
 
   NS_MOCK(router_get_my_routerinfo);
-  NS_MOCK(hid_serv_responsible_for_desc_id);
 
   rend_cache_init();
 
@@ -482,21 +461,10 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
 
   // Test when we can't parse the descriptor
   mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
-  hid_serv_responsible_for_desc_id_response = 1;
   ret = rend_cache_store_v2_desc_as_dir("unparseable");
   tt_int_op(ret, OP_EQ, RCS_BADDESC);
 
-  // Test when we are not responsible for an HS
-  hid_serv_responsible_for_desc_id_response = 0;
-  generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
-  ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
-  tt_int_op(ret, OP_EQ, RCS_OKAY);
-
-  rend_encoded_v2_service_descriptor_free(desc_holder);
-  tor_free(service_id);
-
   // Test when we have an old descriptor
-  hid_serv_responsible_for_desc_id_response = 1;
   generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
   ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
   tt_int_op(ret, OP_EQ, RCS_OKAY);
@@ -529,7 +497,6 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
 
  done:
   NS_UNMOCK(router_get_my_routerinfo);
-  NS_UNMOCK(hid_serv_responsible_for_desc_id);
   rend_encoded_v2_service_descriptor_free(desc_holder);
   tor_free(service_id);
   rend_cache_free_all();
@@ -550,7 +517,6 @@ 
test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
   rend_encoded_v2_service_descriptor_t *desc_holder_older;
 
   NS_MOCK(router_get_my_routerinfo);
-  NS_MOCK(hid_serv_responsible_for_desc_id);
 
   rend_cache_init();
 
@@ -577,7 +543,6 @@ 
test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
 
   // Test when we have a newer descriptor stored
   mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
-  hid_serv_responsible_for_desc_id_response = 1;
   rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
   ret = rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
   tt_int_op(ret, OP_EQ, RCS_OKAY);
@@ -590,7 +555,6 @@ 
test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
 
  done:
   NS_UNMOCK(router_get_my_routerinfo);
-  NS_UNMOCK(hid_serv_responsible_for_desc_id);
   rend_cache_free_all();
   rend_service_descriptor_free(generated);
   tor_free(service_id);
@@ -616,7 +580,6 @@ 
test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
   rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
 
   NS_MOCK(router_get_my_routerinfo);
-  NS_MOCK(hid_serv_responsible_for_desc_id);
 
   rend_cache_init();
 
@@ -645,14 +608,12 @@ 
test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
 
   // Test when we have another descriptor stored, with a different descriptor
   mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
-  hid_serv_responsible_for_desc_id_response = 1;
   rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
   ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
   tt_int_op(ret, OP_EQ, RCS_OKAY);
 
  done:
   NS_UNMOCK(router_get_my_routerinfo);
-  NS_UNMOCK(hid_serv_responsible_for_desc_id);
   rend_cache_free_all();
   rend_service_descriptor_free(generated);
   tor_free(service_id);
@@ -1113,14 +1074,6 @@ test_rend_cache_intro_failure_note(void *data)
 }
 
 #define NS_SUBMODULE clean_v2_descs_as_dir
-NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
-
-static int
-NS(hid_serv_responsible_for_desc_id)(const char *id)
-{
-  (void)id;
-  return hid_serv_responsible_for_desc_id_response;
-}
 
 static void
 test_rend_cache_clean_v2_descs_as_dir(void *data)
@@ -1133,7 +1086,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
 
   (void)data;
 
-  NS_MOCK(hid_serv_responsible_for_desc_id);
   rend_cache_init();
 
   // Test running with an empty cache
@@ -1149,7 +1101,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
   e->parsed = desc;
   digestmap_set(rend_cache_v2_dir, key, e);
 
-  hid_serv_responsible_for_desc_id_response = 1;
   rend_cache_clean_v2_descs_as_dir(now, 0);
   tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
 
@@ -1158,20 +1109,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
   rend_cache_clean_v2_descs_as_dir(now, 0);
   tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
 
-  // Test with one entry that is not under the responsibility of this
-  // hidden service
-  e = tor_malloc_zero(sizeof(rend_cache_entry_t));
-  e->last_served = now;
-  desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
-  desc->timestamp = now;
-  desc->pk = pk_generate(0);
-  e->parsed = desc;
-  digestmap_set(rend_cache_v2_dir, key, e);
-
-  hid_serv_responsible_for_desc_id_response = 0;
-  rend_cache_clean_v2_descs_as_dir(now, 0);
-  tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
-
   // Test with one entry that has an old last served
   e = tor_malloc_zero(sizeof(rend_cache_entry_t));
   e->last_served = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
@@ -1181,7 +1118,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
   e->parsed = desc;
   digestmap_set(rend_cache_v2_dir, key, e);
 
-  hid_serv_responsible_for_desc_id_response = 1;
   rend_cache_clean_v2_descs_as_dir(now, 0);
   tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
 
@@ -1194,12 +1130,10 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
   e->parsed = desc;
   digestmap_set(rend_cache_v2_dir, key, e);
 
-  hid_serv_responsible_for_desc_id_response = 1;
   rend_cache_clean_v2_descs_as_dir(now, 20000);
   tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
 
  done:
-  NS_UNMOCK(hid_serv_responsible_for_desc_id);
   rend_cache_free_all();
 }
 



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to