[tor-commits] [tor/master] Merge remote-tracking branch 'dgoulet/ticket24902_029_05'

nickm at torproject.org nickm at torproject.org
Fri Feb 9 17:08:20 UTC 2018


commit abdf2a6f7f400bf7769b701c79b51e51f1cc9e55
Merge: d9826b0a3 1a4fc9cdd
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Feb 9 12:08:12 2018 -0500

    Merge remote-tracking branch 'dgoulet/ticket24902_029_05'

 src/common/address.c        |  22 ++++++
 src/common/address.h        |   2 +
 src/common/address_set.c    | 129 ++++++++++++++++++++++++++++++++
 src/common/address_set.h    |  35 +++++++++
 src/common/include.am       |   2 +
 src/or/dos.c                |   9 +++
 src/or/nodelist.c           |  78 ++++++++++++++++++++
 src/or/nodelist.h           |   3 +
 src/test/include.am         |   1 +
 src/test/test.c             |   1 +
 src/test/test.h             |   1 +
 src/test/test_address_set.c | 174 ++++++++++++++++++++++++++++++++++++++++++++
 src/test/test_dos.c         | 103 ++++++++++++++++++++++++++
 13 files changed, 560 insertions(+)

diff --cc src/common/include.am
index 1777f33ad,cb307e9d5..694528510
--- a/src/common/include.am
+++ b/src/common/include.am
@@@ -80,8 -80,8 +80,9 @@@ src_common_libor_ctime_testing_a_CFLAG
  
  LIBOR_A_SRC = \
    src/common/address.c					\
+   src/common/address_set.c				\
    src/common/backtrace.c				\
 +  src/common/buffers.c					\
    src/common/compat.c					\
    src/common/compat_threads.c				\
    src/common/compat_time.c				\
@@@ -145,9 -136,8 +146,10 @@@ src_common_libor_event_testing_a_CFLAG
  
  COMMONHEADERS = \
    src/common/address.h				\
+   src/common/address_set.h			\
    src/common/backtrace.h			\
 +  src/common/buffers.h				\
 +  src/common/buffers_tls.h			\
    src/common/aes.h				\
    src/common/ciphers.inc			\
    src/common/compat.h				\
diff --cc src/or/nodelist.c
index 17a50ca86,5a02648c5..391b31d68
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@@ -10,38 -10,11 +10,39 @@@
   * \brief Structures and functions for tracking what we know about the routers
   *   on the Tor network, and correlating information from networkstatus,
   *   routerinfo, and microdescs.
 + *
 + * The key structure here is node_t: that's the canonical way to refer
 + * to a Tor relay that we might want to build a circuit through.  Every
 + * node_t has either a routerinfo_t, or a routerstatus_t from the current
 + * networkstatus consensus.  If it has a routerstatus_t, it will also
 + * need to have a microdesc_t before you can use it for circuits.
 + *
 + * The nodelist_t is a global singleton that maps identities to node_t
 + * objects.  Access them with the node_get_*() functions.  The nodelist_t
 + * is maintained by calls throughout the codebase
 + *
 + * Generally, other code should not have to reach inside a node_t to
 + * see what information it has.  Instead, you should call one of the
 + * many accessor functions that works on a generic node_t.  If there
 + * isn't one that does what you need, it's better to make such a function,
 + * and then use it.
 + *
 + * For historical reasons, some of the functions that select a node_t
 + * from the list of all usable node_t objects are in the routerlist.c
 + * module, since they originally selected a routerinfo_t. (TODO: They
 + * should move!)
 + *
 + * (TODO: Perhaps someday we should abstract the remaining ways of
 + * talking about a relay to also be node_t instances. Those would be
 + * routerstatus_t as used for directory requests, and dir_server_t as
 + * used for authorities and fallback directories.)
   */
  
 +#define NODELIST_PRIVATE
 +
  #include "or.h"
  #include "address.h"
+ #include "address_set.h"
  #include "config.h"
  #include "control.h"
  #include "dirserv.h"
@@@ -97,14 -64,9 +99,17 @@@ typedef struct nodelist_t 
    smartlist_t *nodes;
    /* Hash table to map from node ID digest to node. */
    HT_HEAD(nodelist_map, node_t) nodes_by_id;
 +  /* Hash table to map from node Ed25519 ID to node.
 +   *
 +   * Whenever a node's routerinfo or microdescriptor is about to change,
 +   * you should remove it from this map with node_remove_from_ed25519_map().
 +   * Whenever a node's routerinfo or microdescriptor has just chaned,
 +   * you should add it to this map with node_add_to_ed25519_map().
 +   */
 +  HT_HEAD(nodelist_ed_map, node_t) nodes_by_ed_id;
+ 
+   /* Set of addresses that belong to nodes we believe in. */
+   address_set_t *node_addrs;
  } nodelist_t;
  
  static inline unsigned int
@@@ -423,14 -236,8 +472,16 @@@ nodelist_set_routerinfo(routerinfo_t *r
      dirserv_set_node_flags_from_authoritative_status(node, status);
    }
  
 +  /* Setting the HSDir index requires the ed25519 identity key which can
 +   * only be found either in the ri or md. This is why this is called here.
 +   * Only nodes supporting HSDir=2 protocol version needs this index. */
 +  if (node->rs && node->rs->pv.supports_v3_hsdir) {
 +    node_set_hsdir_index(node,
 +                         networkstatus_get_latest_consensus());
 +  }
 +
+   node_add_to_address_set(node);
+ 
    return node;
  }
  
@@@ -457,21 -264,14 +508,23 @@@ nodelist_add_microdesc(microdesc_t *md
      return NULL;
    node = node_get_mutable_by_id(rs->identity_digest);
    if (node) {
 +    node_remove_from_ed25519_map(node);
      if (node->md)
        node->md->held_by_nodes--;
 +
      node->md = md;
      md->held_by_nodes++;
 +    /* Setting the HSDir index requires the ed25519 identity key which can
 +     * only be found either in the ri or md. This is why this is called here.
 +     * Only nodes supporting HSDir=2 protocol version needs this index. */
 +    if (rs->pv.supports_v3_hsdir) {
 +      node_set_hsdir_index(node, ns);
 +    }
 +    node_add_to_ed25519_map(node);
    }
  
+   node_add_to_address_set(node);
+ 
    return node;
  }
  
diff --cc src/or/nodelist.h
index 0abdcd604,098f1d155..dc20eaf0a
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@@ -143,16 -125,7 +144,18 @@@ void router_dir_info_changed(void)
  const char *get_dir_info_status_string(void);
  int count_loading_descriptors_progress(void);
  
 +#ifdef NODELIST_PRIVATE
 +
 +#ifdef TOR_UNIT_TESTS
 +
 +STATIC void
 +node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
 +
 +#endif /* defined(TOR_UNIT_TESTS) */
 +
 +#endif /* defined(NODELIST_PRIVATE) */
 +
+ MOCK_DECL(int, get_estimated_address_per_node, (void));
+ 
 -#endif
 +#endif /* !defined(TOR_NODELIST_H) */
  



More information about the tor-commits mailing list