[tor-commits] [tor/master] Remove named_map and unnamed_map from networkstatus.c

nickm at torproject.org nickm at torproject.org
Tue Sep 12 13:58:10 UTC 2017


commit 035fe2d208633c600ee7164f2eba2e1c4b24c5db
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Sep 12 09:56:42 2017 -0400

    Remove named_map and unnamed_map from networkstatus.c
---
 src/or/networkstatus.c | 53 --------------------------------------------------
 src/or/networkstatus.h |  1 -
 src/or/nodelist.c      |  9 ---------
 src/or/router.c        | 11 +++--------
 src/or/routerlist.c    | 12 ------------
 src/or/routerlist.h    |  1 -
 6 files changed, 3 insertions(+), 84 deletions(-)

diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 014f0f114..8b07a8885 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -66,12 +66,6 @@
 #include "torcert.h"
 #include "channelpadding.h"
 
-/** Map from lowercase nickname to identity digest of named server, if any. */
-static strmap_t *named_server_map = NULL;
-/** Map from lowercase nickname to (void*)1 for all names that are listed
- * as unnamed for some server in the consensus. */
-static strmap_t *unnamed_server_map = NULL;
-
 /** Most recently received and validated v3 "ns"-flavored consensus network
  * status. */
 STATIC networkstatus_t *current_ns_consensus = NULL;
@@ -142,7 +136,6 @@ static int have_warned_about_old_version = 0;
  * listed by the authorities. */
 static int have_warned_about_new_version = 0;
 
-static void routerstatus_list_update_named_server_map(void);
 static void update_consensus_bootstrap_multiple_downloads(
                                                   time_t now,
                                                   const or_options_t *options);
@@ -250,13 +243,6 @@ router_reload_consensus_networkstatus(void)
     }
   }
 
-  if (!networkstatus_get_latest_consensus()) {
-    if (!named_server_map)
-      named_server_map = strmap_new();
-    if (!unnamed_server_map)
-      unnamed_server_map = strmap_new();
-  }
-
   update_certificate_downloads(time(NULL));
 
   routers_update_all_from_networkstatus(time(NULL), 3);
@@ -794,16 +780,6 @@ router_get_consensus_status_by_id(const char *digest)
   return router_get_mutable_consensus_status_by_id(digest);
 }
 
-/** Return the identity digest that's mapped to officially by
- * <b>nickname</b>. */
-const char *
-networkstatus_get_router_digest_by_nickname(const char *nickname)
-{
-  if (!named_server_map)
-    return NULL;
-  return strmap_get_lc(named_server_map, nickname);
-}
-
 /** How frequently do directory authorities re-download fresh networkstatus
  * documents? */
 #define AUTHORITY_NS_CACHE_INTERVAL (10*60)
@@ -1960,7 +1936,6 @@ networkstatus_set_current_consensus(const char *consensus,
     update_consensus_networkstatus_fetch_time(now);
 
     dirvote_recalculate_timing(options, now);
-    routerstatus_list_update_named_server_map();
 
     /* Update ewma and adjust policy if needed; first cache the old value */
     old_ewma_enabled = cell_ewma_enabled();
@@ -2129,31 +2104,6 @@ routers_update_all_from_networkstatus(time_t now, int dir_version)
   }
 }
 
-/** Update our view of the list of named servers from the most recently
- * retrieved networkstatus consensus. */
-static void
-routerstatus_list_update_named_server_map(void)
-{
-  networkstatus_t *ns = networkstatus_get_latest_consensus();
-  if (!ns)
-    return;
-
-  strmap_free(named_server_map, tor_free_);
-  named_server_map = strmap_new();
-  strmap_free(unnamed_server_map, NULL);
-  unnamed_server_map = strmap_new();
-  smartlist_t *rslist = ns->routerstatus_list;
-  SMARTLIST_FOREACH_BEGIN(rslist, const routerstatus_t *, rs) {
-      if (rs->is_named) {
-        strmap_set_lc(named_server_map, rs->nickname,
-                      tor_memdup(rs->identity_digest, DIGEST_LEN));
-      }
-      if (rs->is_unnamed) {
-        strmap_set_lc(unnamed_server_map, rs->nickname, (void*)1);
-      }
-  } SMARTLIST_FOREACH_END(rs);
-}
-
 /** Given a list <b>routers</b> of routerinfo_t *, update each status field
  * according to our current consensus networkstatus.  May re-order
  * <b>routers</b>. */
@@ -2639,8 +2589,5 @@ networkstatus_free_all(void)
     }
     tor_free(waiting->body);
   }
-
-  strmap_free(named_server_map, tor_free_);
-  strmap_free(unnamed_server_map, NULL);
 }
 
diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
index 34643667a..adaa10890 100644
--- a/src/or/networkstatus.h
+++ b/src/or/networkstatus.h
@@ -62,7 +62,6 @@ const routerstatus_t *router_get_consensus_status_by_descriptor_digest(
 MOCK_DECL(routerstatus_t *,
           router_get_mutable_consensus_status_by_descriptor_digest,
           (networkstatus_t *consensus, const char *digest));
-const char *networkstatus_get_router_digest_by_nickname(const char *nickname);
 int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
 int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
 void networkstatus_consensus_download_failed(int status_code,
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 394c3ae73..01a0e9e85 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -850,15 +850,6 @@ node_get_by_nickname,(const char *nickname, unsigned flags))
   if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
     return NULL;
 
-  /* Okay, so if we get here, the nickname is just a nickname.  Is there
-   * a binding for it in the consensus? */
-  {
-    const char *named_id =
-      networkstatus_get_router_digest_by_nickname(nickname);
-    if (named_id)
-      return node_get_by_id(named_id);
-  }
-
   /* Okay, so the name is not canonical for anybody. */
   {
     smartlist_t *matches = smartlist_new();
diff --git a/src/or/router.c b/src/or/router.c
index 665e95d3a..2bc7a875f 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -3497,7 +3497,7 @@ router_get_description(char *buf, const routerinfo_t *ri)
     return "<null>";
   return format_node_description(buf,
                                  ri->cache_info.identity_digest,
-                                 router_is_named(ri),
+                                 0,
                                  ri->nickname,
                                  NULL,
                                  ri->addr);
@@ -3623,21 +3623,16 @@ extend_info_describe(const extend_info_t *ei)
  * verbose representation of the identity of <b>router</b>.  The format is:
  *  A dollar sign.
  *  The upper-case hexadecimal encoding of the SHA1 hash of router's identity.
- *  A "=" if the router is named; a "~" if it is not.
+ *  A "=" if the router is named (no longer implemented); a "~" if it is not.
  *  The router's nickname.
  **/
 void
 router_get_verbose_nickname(char *buf, const routerinfo_t *router)
 {
-  const char *good_digest = networkstatus_get_router_digest_by_nickname(
-                                                         router->nickname);
-  int is_named = good_digest && tor_memeq(good_digest,
-                                        router->cache_info.identity_digest,
-                                        DIGEST_LEN);
   buf[0] = '$';
   base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
                 DIGEST_LEN);
-  buf[1+HEX_DIGEST_LEN] = is_named ? '=' : '~';
+  buf[1+HEX_DIGEST_LEN] = '~';
   strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
 }
 
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index cc4c19624..9111d93c3 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -2957,18 +2957,6 @@ hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest,
   return tor_memeq(digest, identity_digest, DIGEST_LEN);
 }
 
-/** Return true iff <b>router</b> is listed as named in the current
- * consensus. */
-int
-router_is_named(const routerinfo_t *router)
-{
-  const char *digest =
-    networkstatus_get_router_digest_by_nickname(router->nickname);
-
-  return (digest &&
-          tor_memeq(digest, router->cache_info.identity_digest, DIGEST_LEN));
-}
-
 /** Return true iff <b>digest</b> is the digest of the identity key of a
  * trusted directory matching at least one bit of <b>type</b>.  If <b>type</b>
  * is zero (NO_DIRINFO), or ALL_DIRINFO, any authority is okay. */
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index 931373f5c..27c8d88f0 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -80,7 +80,6 @@ const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
                                         struct routerset_t *excludedset,
                                         router_crn_flags_t flags);
 
-int router_is_named(const routerinfo_t *router);
 int router_digest_is_trusted_dir_type(const char *digest,
                                       dirinfo_type_t type);
 #define router_digest_is_trusted_dir(d) \





More information about the tor-commits mailing list