Ticket #22215: 0001-networkstatus_nickname_is_unnamed.patch

File 0001-networkstatus_nickname_is_unnamed.patch, 10.4 KB (added by neel, 3 years ago)

Patch to remove networkstatus_nickname_is_unnamed(), as well as named_flag and unnamed_flag, and checks for Named and Unnamed flags

  • src/or/networkstatus.c

    From 569aed9c40382ed5adad1ea9a33eea5b2a7cc443 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Thu, 24 Aug 2017 14:55:08 -0400
    Subject: [PATCH 1/2] Removed networkstatus_nickname_is_unnamed()
    
    ---
     src/or/networkstatus.c | 10 ----------
     src/or/networkstatus.h |  1 -
     src/or/nodelist.c      |  8 --------
     3 files changed, 19 deletions(-)
    
    diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
    index 69bff55cf..32057a344 100644
    a b networkstatus_get_router_digest_by_nickname(const char *nickname) 
    819819  return strmap_get_lc(named_server_map, nickname);
    820820}
    821821
    822 /** Return true iff <b>nickname</b> is disallowed from being the nickname
    823  * of any server. */
    824 int
    825 networkstatus_nickname_is_unnamed(const char *nickname)
    826 {
    827   if (!unnamed_server_map)
    828     return 0;
    829   return strmap_get_lc(unnamed_server_map, nickname) != NULL;
    830 }
    831 
    832822/** How frequently do directory authorities re-download fresh networkstatus
    833823 * documents? */
    834824#define AUTHORITY_NS_CACHE_INTERVAL (10*60)
  • src/or/networkstatus.h

    diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
    index f9320747d..c39ae15e2 100644
    a b const routerstatus_t *router_get_consensus_status_by_nickname( 
    6666                                   const char *nickname,
    6767                                   int warn_if_unnamed);
    6868const char *networkstatus_get_router_digest_by_nickname(const char *nickname);
    69 int networkstatus_nickname_is_unnamed(const char *nickname);
    7069int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
    7170int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
    7271void networkstatus_consensus_download_failed(int status_code,
  • src/or/nodelist.c

    diff --git a/src/or/nodelist.c b/src/or/nodelist.c
    index 0fcaea626..ba4e21e91 100644
    a b node_get_by_nickname,(const char *nickname, int warn_if_unnamed)) 
    678678      return node_get_by_id(named_id);
    679679  }
    680680
    681   /* Is it marked as owned-by-someone-else? */
    682   if (networkstatus_nickname_is_unnamed(nickname)) {
    683     log_info(LD_GENERAL, "The name %s is listed as Unnamed: there is some "
    684              "router that holds it, but not one listed in the current "
    685              "consensus.", escaped(nickname));
    686     return NULL;
    687   }
    688 
    689681  /* Okay, so the name is not canonical for anybody. */
    690682  {
    691683    smartlist_t *matches = smartlist_new();
  • src/or/dirvote.c

    -- 
    2.14.1
    
    
    From 67c0cb4506ecad6324f372519079e26482bbaca5 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Thu, 24 Aug 2017 15:19:36 -0400
    Subject: [PATCH 2/2] Remove named_flag and unnamed_flag, and checks for Named
     and Unnamed flags
    
    ---
     src/or/dirvote.c     | 86 ++--------------------------------------------------
     src/or/routerparse.c |  8 +----
     2 files changed, 3 insertions(+), 91 deletions(-)
    
    diff --git a/src/or/dirvote.c b/src/or/dirvote.c
    index c65945fea..45ba4b968 100644
    a b networkstatus_compute_consensus(smartlist_t *votes, 
    16471647                         * about flags[f]. */
    16481648    int **flag_map; /* flag_map[j][b] is an index f such that flag_map[f]
    16491649                     * is the same flag as votes[j]->known_flags[b]. */
    1650     int *named_flag; /* Index of the flag "Named" for votes[j] */
    1651     int *unnamed_flag; /* Index of the flag "Unnamed" for votes[j] */
    16521650    int n_authorities_measuring_bandwidth;
    16531651
    16541652    strmap_t *name_to_id_map = strmap_new();
    networkstatus_compute_consensus(smartlist_t *votes, 
    16611659    n_voter_flags = tor_calloc(smartlist_len(votes), sizeof(int));
    16621660    n_flag_voters = tor_calloc(smartlist_len(flags), sizeof(int));
    16631661    flag_map = tor_calloc(smartlist_len(votes), sizeof(int *));
    1664     named_flag = tor_calloc(smartlist_len(votes), sizeof(int));
    1665     unnamed_flag = tor_calloc(smartlist_len(votes), sizeof(int));
    1666     for (i = 0; i < smartlist_len(votes); ++i)
    1667       unnamed_flag[i] = named_flag[i] = -1;
    16681662
    16691663    /* Build the flag indexes. Note that no vote can have more than 64 members
    16701664     * for known_flags, so no value will be greater than 63, so it's safe to
    1671      * do U64_LITERAL(1) << index on these values.  But note also that
    1672      * named_flag and unnamed_flag are initialized to -1, so we need to check
    1673      * that they're actually set before doing U64_LITERAL(1) << index with
    1674      * them.*/
     1665     * do U64_LITERAL(1) << index on these values. */
    16751666    SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
    16761667      flag_map[v_sl_idx] = tor_calloc(smartlist_len(v->known_flags),
    16771668                                      sizeof(int));
    networkstatus_compute_consensus(smartlist_t *votes, 
    16841675        tor_assert(p >= 0);
    16851676        flag_map[v_sl_idx][fl_sl_idx] = p;
    16861677        ++n_flag_voters[p];
    1687         if (!strcmp(fl, "Named"))
    1688           named_flag[v_sl_idx] = fl_sl_idx;
    1689         if (!strcmp(fl, "Unnamed"))
    1690           unnamed_flag[v_sl_idx] = fl_sl_idx;
    16911678      } SMARTLIST_FOREACH_END(fl);
    16921679      n_voter_flags[v_sl_idx] = smartlist_len(v->known_flags);
    16931680      size[v_sl_idx] = smartlist_len(v->routerstatus_list);
    16941681    } SMARTLIST_FOREACH_END(v);
    16951682
    1696     /* Named and Unnamed get treated specially */
    1697     {
    1698       SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
    1699         uint64_t nf;
    1700         if (named_flag[v_sl_idx]<0)
    1701           continue;
    1702         nf = U64_LITERAL(1) << named_flag[v_sl_idx];
    1703         SMARTLIST_FOREACH_BEGIN(v->routerstatus_list,
    1704                                 vote_routerstatus_t *, rs) {
    1705 
    1706           if ((rs->flags & nf) != 0) {
    1707             const char *d = strmap_get_lc(name_to_id_map, rs->status.nickname);
    1708             if (!d) {
    1709               /* We have no name officially mapped to this digest. */
    1710               strmap_set_lc(name_to_id_map, rs->status.nickname,
    1711                             rs->status.identity_digest);
    1712             } else if (d != conflict &&
    1713                 fast_memcmp(d, rs->status.identity_digest, DIGEST_LEN)) {
    1714               /* Authorities disagree about this nickname. */
    1715               strmap_set_lc(name_to_id_map, rs->status.nickname, conflict);
    1716             } else {
    1717               /* It's already a conflict, or it's already this ID. */
    1718             }
    1719           }
    1720         } SMARTLIST_FOREACH_END(rs);
    1721       } SMARTLIST_FOREACH_END(v);
    1722 
    1723       SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
    1724         uint64_t uf;
    1725         if (unnamed_flag[v_sl_idx]<0)
    1726           continue;
    1727         uf = U64_LITERAL(1) << unnamed_flag[v_sl_idx];
    1728         SMARTLIST_FOREACH_BEGIN(v->routerstatus_list,
    1729                                 vote_routerstatus_t *, rs) {
    1730           if ((rs->flags & uf) != 0) {
    1731             const char *d = strmap_get_lc(name_to_id_map, rs->status.nickname);
    1732             if (d == conflict || d == unknown) {
    1733               /* Leave it alone; we know what it is. */
    1734             } else if (!d) {
    1735               /* We have no name officially mapped to this digest. */
    1736               strmap_set_lc(name_to_id_map, rs->status.nickname, unknown);
    1737             } else if (fast_memeq(d, rs->status.identity_digest, DIGEST_LEN)) {
    1738               /* Authorities disagree about this nickname. */
    1739               strmap_set_lc(name_to_id_map, rs->status.nickname, conflict);
    1740             } else {
    1741               /* It's mapped to a different name. */
    1742             }
    1743           }
    1744         } SMARTLIST_FOREACH_END(rs);
    1745       } SMARTLIST_FOREACH_END(v);
    1746     }
    1747 
    17481683    /* We need to know how many votes measure bandwidth. */
    17491684    n_authorities_measuring_bandwidth = 0;
    17501685    SMARTLIST_FOREACH(votes, const networkstatus_t *, v,
    networkstatus_compute_consensus(smartlist_t *votes, 
    18171752          if (rs->flags & (U64_LITERAL(1) << flag))
    18181753            ++flag_counts[flag_map[voter_idx][flag]];
    18191754        }
    1820         if (named_flag[voter_idx] >= 0 &&
    1821             (rs->flags & (U64_LITERAL(1) << named_flag[voter_idx]))) {
    1822           if (chosen_name && strcmp(chosen_name, rs->status.nickname)) {
    1823             log_notice(LD_DIR, "Conflict on naming for router: %s vs %s",
    1824                        chosen_name, rs->status.nickname);
    1825             naming_conflict = 1;
    1826           }
    1827           chosen_name = rs->status.nickname;
    1828         }
    18291755
    18301756        /* Count guardfraction votes and note down the values. */
    18311757        if (rs->status.has_guardfraction) {
    networkstatus_compute_consensus(smartlist_t *votes, 
    19121838      /* Set the flags. */
    19131839      smartlist_add(chosen_flags, (char*)"s"); /* for the start of the line. */
    19141840      SMARTLIST_FOREACH_BEGIN(flags, const char *, fl) {
    1915         if (!strcmp(fl, "Named")) {
    1916           if (is_named)
    1917             smartlist_add(chosen_flags, (char*)fl);
    1918         } else if (!strcmp(fl, "Unnamed")) {
    1919           if (is_unnamed)
    1920             smartlist_add(chosen_flags, (char*)fl);
    1921         } else if (!strcmp(fl, "NoEdConsensus") &&
     1841        if (!strcmp(fl, "NoEdConsensus") &&
    19221842                   consensus_method >= MIN_METHOD_FOR_ED25519_ID_VOTING) {
    19231843          if (ed_consensus <= total_authorities/2)
    19241844            smartlist_add(chosen_flags, (char*)fl);
    networkstatus_compute_consensus(smartlist_t *votes, 
    21572077      tor_free(flag_map[i]);
    21582078    tor_free(flag_map);
    21592079    tor_free(flag_counts);
    2160     tor_free(named_flag);
    2161     tor_free(unnamed_flag);
    21622080    strmap_free(name_to_id_map, NULL);
    21632081    smartlist_free(matching_descs);
    21642082    smartlist_free(chosen_flags);
  • src/or/routerparse.c

    diff --git a/src/or/routerparse.c b/src/or/routerparse.c
    index 3449e6f6b..ef47b4b60 100644
    a b routerstatus_parse_entry_from_string(memarea_t *area, 
    26692669        rs->is_fast = 1;
    26702670      else if (!strcmp(tok->args[i], "Running"))
    26712671        rs->is_flagged_running = 1;
    2672       else if (!strcmp(tok->args[i], "Named"))
    2673         rs->is_named = 1;
    26742672      else if (!strcmp(tok->args[i], "Valid"))
    26752673        rs->is_valid = 1;
    26762674      else if (!strcmp(tok->args[i], "Guard"))
    routerstatus_parse_entry_from_string(memarea_t *area, 
    26792677        rs->is_bad_exit = 1;
    26802678      else if (!strcmp(tok->args[i], "Authority"))
    26812679        rs->is_authority = 1;
    2682       else if (!strcmp(tok->args[i], "Unnamed") &&
    2683                consensus_method >= 2) {
    2684         /* Unnamed is computed right by consensus method 2 and later. */
    2685         rs->is_unnamed = 1;
    2686       } else if (!strcmp(tok->args[i], "HSDir")) {
     2680      else if (!strcmp(tok->args[i], "HSDir")) {
    26872681        rs->is_hs_dir = 1;
    26882682      } else if (!strcmp(tok->args[i], "V2Dir")) {
    26892683        rs->is_v2_dir = 1;