Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Enumerations | Functions | Variables
nodelist.c File Reference

Structures and functions for tracking what we know about the routers on the Tor network, and correlating information from networkstatus, routerinfo, and microdescs. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/or/address_set.h"
#include "core/or/policies.h"
#include "core/or/protover.h"
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control_events.h"
#include "feature/dirauth/process_descs.h"
#include "feature/dirclient/dirclient_modes.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_common.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodefamily.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
#include "lib/encoding/binascii.h"
#include "lib/err/backtrace.h"
#include "lib/geoip/geoip.h"
#include "lib/net/address.h"
#include <string.h>
#include "feature/dirauth/authmode.h"
#include "feature/dirclient/dir_server_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "feature/nodelist/routerstatus_st.h"

Go to the source code of this file.

Data Structures

struct  nodelist_t
 

Macros

#define NODELIST_PRIVATE
 
#define node_free(val)    FREE_AND_NULL(node_t, node_free_, (val))
 
#define ESTIMATED_ADDRESS_PER_NODE   2
 
#define SL_ADD_NEW_AP(r, addr_field, port_field, sl, valid)
 
#define RETURN_IPV4_AP(r, port_field, ap_out)
 
#define DFLT_PCT_USABLE_NEEDED   60
 

Enumerations

enum  usable_descriptor_t { USABLE_DESCRIPTOR_ALL = 0U , USABLE_DESCRIPTOR_EXIT_POLICY = 1U << 0 , USABLE_DESCRIPTOR_EXIT_FLAG = 1U << 1 , USABLE_DESCRIPTOR_EXIT_POLICY_AND_FLAG }
 

Functions

static void nodelist_drop_node (node_t *node, int remove_from_ht)
 
static void node_free_ (node_t *node)
 
static void count_usable_descriptors (int *num_present, int *num_usable, smartlist_t *descs_out, const networkstatus_t *consensus, time_t now, routerset_t *in_set, usable_descriptor_t exit_only)
 
static void update_router_have_minimum_dir_info (void)
 
static double get_frac_paths_needed_for_circs (const or_options_t *options, const networkstatus_t *ns)
 
static void node_add_to_address_set (const node_t *node)
 
static unsigned int node_id_hash (const node_t *node)
 
static unsigned int node_id_eq (const node_t *node1, const node_t *node2)
 
 HT_PROTOTYPE (nodelist_map, node_t, ht_ent, node_id_hash, node_id_eq)
 
 HT_GENERATE2 (nodelist_map, node_t, ht_ent, node_id_hash, node_id_eq, 0.6, tor_reallocarray_, tor_free_)
 
static unsigned int node_ed_id_hash (const node_t *node)
 
static unsigned int node_ed_id_eq (const node_t *node1, const node_t *node2)
 
 HT_PROTOTYPE (nodelist_ed_map, node_t, ed_ht_ent, node_ed_id_hash, node_ed_id_eq)
 
 HT_GENERATE2 (nodelist_ed_map, node_t, ed_ht_ent, node_ed_id_hash, node_ed_id_eq, 0.6, tor_reallocarray_, tor_free_)
 
static void init_nodelist (void)
 
node_tnode_get_mutable_by_id (const char *identity_digest)
 
node_tnode_get_mutable_by_ed25519_id (const ed25519_public_key_t *ed_id)
 
const node_tnode_get_by_id (const char *identity_digest)
 
const node_tnode_get_by_ed25519_id (const ed25519_public_key_t *ed_id)
 
static node_tnode_get_or_create (const char *identity_digest)
 
static int node_remove_from_ed25519_map (node_t *node)
 
static void node_log_dup_ed_id (const node_t *old, const node_t *node, const char *ed_id)
 
static int node_add_to_ed25519_map (node_t *node)
 
STATIC void node_set_hsdir_index (node_t *node, const networkstatus_t *ns)
 
static void node_addrs_changed (node_t *node)
 
static char * build_addr_port_item (const tor_addr_t *addr, const uint16_t port)
 
void nodelist_add_addr_to_address_set (const tor_addr_t *addr, uint16_t or_port, uint16_t dir_port)
 
int nodelist_probably_contains_address (const tor_addr_t *addr)
 
bool nodelist_reentry_contains (const tor_addr_t *addr, uint16_t port)
 
node_tnodelist_set_routerinfo (routerinfo_t *ri, routerinfo_t **ri_old_out)
 
node_tnodelist_add_microdesc (microdesc_t *md)
 
int get_estimated_address_per_node (void)
 
void nodelist_set_consensus (const networkstatus_t *ns)
 
int node_is_good_exit (const node_t *node)
 
static int node_is_usable (const node_t *node)
 
void nodelist_remove_microdesc (const char *identity_digest, microdesc_t *md)
 
void nodelist_remove_routerinfo (routerinfo_t *ri)
 
smartlist_tnodelist_find_nodes_with_microdesc (const microdesc_t *md)
 
void nodelist_purge (void)
 
void nodelist_free_all (void)
 
void nodelist_assert_ok (void)
 
void nodelist_ensure_freshness (const networkstatus_t *ns)
 
const smartlist_tnodelist_get_list (void)
 
const node_tnode_get_by_hex_id (const char *hex_id, unsigned flags)
 
const node_tnode_get_by_nickname (const char *nickname, unsigned flags)
 
const ed25519_public_key_tnode_get_ed25519_id (const node_t *node)
 
int node_ed25519_id_matches (const node_t *node, const ed25519_public_key_t *id)
 
static const protover_summary_flags_tnode_get_protover_summary_flags (const node_t *node)
 
bool node_supports_ed25519_link_authentication (const node_t *node, bool compatible_with_us)
 
bool node_supports_v3_hsdir (const node_t *node)
 
bool node_supports_ed25519_hs_intro (const node_t *node)
 
bool node_supports_v3_rendezvous_point (const node_t *node)
 
bool node_supports_establish_intro_dos_extension (const node_t *node)
 
bool node_supports_initiating_ipv6_extends (const node_t *node)
 
bool node_supports_accepting_ipv6_extends (const node_t *node, bool need_canonical_ipv6_conn)
 
const uint8_t * node_get_rsa_id_digest (const node_t *node)
 
smartlist_tnode_get_link_specifier_smartlist (const node_t *node, bool direct_conn)
 
void link_specifier_smartlist_free_ (smartlist_t *ls_list)
 
const char * node_get_nickname (const node_t *node)
 
int node_is_dir (const node_t *node)
 
int node_has_any_descriptor (const node_t *node)
 
int node_has_preferred_descriptor (const node_t *node, int for_direct_connect)
 
int node_get_purpose (const node_t *node)
 
void node_get_verbose_nickname (const node_t *node, char *verbose_name_out)
 
void node_get_verbose_nickname_by_id (const char *id_digest, char *verbose_name_out)
 
int node_allows_single_hop_exits (const node_t *node)
 
int node_exit_policy_rejects_all (const node_t *node)
 
int node_exit_policy_is_exact (const node_t *node, sa_family_t family)
 
smartlist_tnode_get_all_orports (const node_t *node)
 
void node_get_addr (const node_t *node, tor_addr_t *addr_out)
 
static const tor_addr_tnode_get_prim_addr_ipv4 (const node_t *node)
 
void node_get_address_string (const node_t *node, char *buf, size_t len)
 
long node_get_declared_uptime (const node_t *node)
 
const char * node_get_platform (const node_t *node)
 
int node_is_me (const node_t *node)
 
int node_has_ipv6_addr (const node_t *node)
 
int node_has_ipv6_orport (const node_t *node)
 
int node_has_ipv6_dirport (const node_t *node)
 
int node_ipv6_or_preferred (const node_t *node)
 
void node_get_prim_orport (const node_t *node, tor_addr_port_t *ap_out)
 
void node_get_pref_orport (const node_t *node, tor_addr_port_t *ap_out)
 
void node_get_pref_ipv6_orport (const node_t *node, tor_addr_port_t *ap_out)
 
int node_ipv6_dir_preferred (const node_t *node)
 
void node_get_prim_dirport (const node_t *node, tor_addr_port_t *ap_out)
 
void node_get_pref_dirport (const node_t *node, tor_addr_port_t *ap_out)
 
void node_get_pref_ipv6_dirport (const node_t *node, tor_addr_port_t *ap_out)
 
static int microdesc_has_curve25519_onion_key (const microdesc_t *md)
 
int node_has_curve25519_onion_key (const node_t *node)
 
const curve25519_public_key_tnode_get_curve25519_onion_key (const node_t *node)
 
crypto_pk_tnode_get_rsa_onion_key (const node_t *node)
 
void node_set_country (node_t *node)
 
void nodelist_refresh_countries (void)
 
int router_addrs_in_same_network (const tor_addr_t *a1, const tor_addr_t *a2)
 
STATIC int node_nickname_matches (const node_t *node, const char *nickname)
 
STATIC int node_in_nickname_smartlist (const smartlist_t *lst, const node_t *node)
 
STATIC int node_family_contains (const node_t *n1, const node_t *n2)
 
STATIC bool node_has_declared_family (const node_t *node)
 
STATIC void node_lookup_declared_family (smartlist_t *out, const node_t *node)
 
int nodes_in_same_family (const node_t *node1, const node_t *node2)
 
void nodelist_add_node_and_family (smartlist_t *sl, const node_t *node)
 
const node_trouter_find_exact_exit_enclave (const char *address, uint16_t port)
 
int node_is_unreliable (const node_t *node, int need_uptime, int need_capacity, int need_guard)
 
int router_exit_policy_all_nodes_reject (const tor_addr_t *addr, uint16_t port, int need_uptime)
 
void router_set_status (const char *digest, int up)
 
int router_have_minimum_dir_info (void)
 
consensus_path_type_t router_have_consensus_path (void)
 
void router_dir_info_changed (void)
 
const char * get_dir_info_status_string (void)
 
static double compute_frac_paths_available (const networkstatus_t *consensus, const or_options_t *options, time_t now, int *num_present_out, int *num_usable_out, char **status_out)
 
int count_loading_descriptors_progress (void)
 

Variables

static nodelist_tthe_nodelist =NULL
 
static const protover_summary_flags_t zero_protover_flags
 
static int have_min_dir_info = 0
 
static consensus_path_type_t have_consensus_path = CONSENSUS_PATH_UNKNOWN
 
static int need_to_update_have_min_dir_info = 1
 
static char dir_info_status [512] = ""
 

Detailed Description

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.)

Definition in file nodelist.c.

Macro Definition Documentation

◆ RETURN_IPV4_AP

#define RETURN_IPV4_AP (   r,
  port_field,
  ap_out 
)
Value:
STMT_BEGIN \
if (r && tor_addr_port_is_valid(&(r)->ipv4_addr, (r)->port_field, 0)) { \
tor_addr_copy(&(ap_out)->addr, &(r)->ipv4_addr); \
(ap_out)->port = (r)->port_field; \
} \
STMT_END

Definition at line 1810 of file nodelist.c.

◆ SL_ADD_NEW_AP

#define SL_ADD_NEW_AP (   r,
  addr_field,
  port_field,
  sl,
  valid 
)
Value:
STMT_BEGIN \
if (tor_addr_port_is_valid(&(r)->addr_field, (r)->port_field, 0)) { \
valid = 1; \
tor_addr_port_t *ap = tor_addr_port_new(&(r)->addr_field, \
(r)->port_field); \
smartlist_add((sl), ap); \
} \
STMT_END
tor_addr_port_t * tor_addr_port_new(const tor_addr_t *addr, uint16_t port)
Definition: address.c:2100

Definition at line 1616 of file nodelist.c.

Enumeration Type Documentation

◆ usable_descriptor_t

count_usable_descriptors counts descriptors with these flag(s)

Definition at line 91 of file nodelist.c.

Function Documentation

◆ build_addr_port_item()

static char* build_addr_port_item ( const tor_addr_t addr,
const uint16_t  port 
)
static

Build a construction for the reentry set consisting of an address and port pair.

If the given address is not AF_INET or AF_INET6, then the item is an array of 0s.

Return a pointer to a static buffer containing the item. Next call to this function invalidates its previous content.

Definition at line 496 of file nodelist.c.

◆ compute_frac_paths_available()

static double compute_frac_paths_available ( const networkstatus_t consensus,
const or_options_t options,
time_t  now,
int *  num_present_out,
int *  num_usable_out,
char **  status_out 
)
static

Return an estimate of which fraction of usable paths through the Tor network we have available for use. Count how many routers seem like ones we'd use (store this in *num_usable_out), and how many of those we have descriptors for (store this in *num_present_out.)

If **status_out is present, allocate a new string and print the available percentages of guard, middle, and exit nodes to it, noting whether there are exits in the consensus. If there are no exits in the consensus, we treat the exit fraction as 100%, but set router_have_consensus_path() so that we can only build internal paths.

Definition at line 2571 of file nodelist.c.

Referenced by count_loading_descriptors_progress().

◆ count_loading_descriptors_progress()

int count_loading_descriptors_progress ( void  )

We just fetched a new set of descriptors. Compute how far through the "loading descriptors" bootstrapping phase we are, so we can inform the controller of our progress.

Definition at line 2770 of file nodelist.c.

◆ count_usable_descriptors()

static void count_usable_descriptors ( int *  num_present,
int *  num_usable,
smartlist_t descs_out,
const networkstatus_t consensus,
time_t  now,
routerset_t *  in_set,
usable_descriptor_t  exit_only 
)
static

Iterate over the servers listed in consensus, and count how many of them seem like ones we'd use (store this in *num_usable), and how many of those we have descriptors for (store this in *num_present).

If in_set is non-NULL, only consider those routers in in_set. If exit_only & USABLE_DESCRIPTOR_EXIT_POLICY, only consider nodes present if they have an exit policy that accepts at least one port. If exit_only & USABLE_DESCRIPTOR_EXIT_FLAG, only consider nodes usable if they have the exit flag in the consensus.

If *descs_out is present, add a node_t for each usable descriptor to it.

Definition at line 2500 of file nodelist.c.

◆ get_dir_info_status_string()

const char* get_dir_info_status_string ( void  )

Return a string describing what we're missing before we have enough directory info.

Definition at line 2480 of file nodelist.c.

Referenced by directory_info_has_arrived().

◆ get_frac_paths_needed_for_circs()

static double get_frac_paths_needed_for_circs ( const or_options_t options,
const networkstatus_t ns 
)
static

Return the fraction of paths needed before we're willing to build circuits, as configured in options, or in the consensus ns.

Definition at line 2797 of file nodelist.c.

Referenced by count_loading_descriptors_progress().

◆ init_nodelist()

static void init_nodelist ( void  )
static

Create an empty nodelist if we haven't done so already.

Definition at line 185 of file nodelist.c.

Referenced by nodelist_get_list(), and nodelist_set_routerinfo().

◆ microdesc_has_curve25519_onion_key()

static int microdesc_has_curve25519_onion_key ( const microdesc_t md)
static

Return true iff md has a curve25519 onion key. Use node_has_curve25519_onion_key() instead of calling this directly.

Definition at line 1989 of file nodelist.c.

◆ node_add_to_address_set()

static void node_add_to_address_set ( const node_t node)
static

Add all address information about node to the current address set (if there is one).

Definition at line 451 of file nodelist.c.

◆ node_add_to_ed25519_map()

static int node_add_to_ed25519_map ( node_t node)
static

If node has an ed25519 id, and it is not already in the ed25519 id map, set its ed25519_id field, and add it to the ed25519 map.

Definition at line 311 of file nodelist.c.

Referenced by nodelist_set_routerinfo().

◆ node_addrs_changed()

static void node_addrs_changed ( node_t node)
static

Called when a node's address changes.

Definition at line 441 of file nodelist.c.

Referenced by nodelist_set_routerinfo().

◆ node_allows_single_hop_exits()

int node_allows_single_hop_exits ( const node_t node)

Return true iff it seems that node allows circuits to exit through it directlry from the client.

Definition at line 1568 of file nodelist.c.

◆ node_ed25519_id_matches()

int node_ed25519_id_matches ( const node_t node,
const ed25519_public_key_t id 
)

Return true iff this node's Ed25519 identity matches id. (An absent Ed25519 identity matches NULL or zero.)

Definition at line 1195 of file nodelist.c.

◆ node_exit_policy_is_exact()

int node_exit_policy_is_exact ( const node_t node,
sa_family_t  family 
)

Return true iff the exit policy for node is such that we can treat rejecting an address of type family unexpectedly as a sign of that node's failure.

Definition at line 1596 of file nodelist.c.

Referenced by adjust_exit_policy_from_exitpolicy_failure().

◆ node_exit_policy_rejects_all()

int node_exit_policy_rejects_all ( const node_t node)

Return true iff it seems that node has an exit policy that doesn't actually permit anything to exit, or we don't know its exit policy

Definition at line 1579 of file nodelist.c.

◆ node_family_contains()

STATIC int node_family_contains ( const node_t n1,
const node_t n2 
)

Return true iff n1's declared family contains n2.

Definition at line 2139 of file nodelist.c.

Referenced by nodes_in_same_family().

◆ node_free_()

static void node_free_ ( node_t node)
static

Release storage held by node

Definition at line 881 of file nodelist.c.

◆ node_get_addr()

void node_get_addr ( const node_t node,
tor_addr_t addr_out 
)

Wrapper around node_get_prim_orport for backward compatibility.

Definition at line 1672 of file nodelist.c.

Referenced by guard_in_node_family(), nodelist_add_node_and_family(), and nodes_in_same_family().

◆ node_get_address_string()

void node_get_address_string ( const node_t node,
char *  buf,
size_t  len 
)

Copy a string representation of an IP address for node into the len-byte buffer at buf.

Definition at line 1698 of file nodelist.c.

◆ node_get_all_orports()

smartlist_t* node_get_all_orports ( const node_t node)

Return list of tor_addr_port_t with all OR ports (in the sense IP addr + TCP port) for node. Caller must free all elements using tor_free() and free the list using smartlist_free().

XXX this is potentially a memory fragmentation hog – if on critical path consider the option of having the caller allocate the memory

Definition at line 1635 of file nodelist.c.

Referenced by router_get_all_orports().

◆ node_get_by_ed25519_id()

const node_t* node_get_by_ed25519_id ( const ed25519_public_key_t ed_id)

Return the node_t whose ed25519 identity is ed_id, or NULL if no such node exists.

Definition at line 234 of file nodelist.c.

◆ node_get_by_hex_id()

const node_t* node_get_by_hex_id ( const char *  hex_id,
unsigned  flags 
)

Given a hex-encoded nickname of the format DIGEST, $DIGEST, $DIGEST=name, or $DIGEST~name, return the node with the matching identity digest and nickname (if any). Return NULL if no such node exists, or if hex_id is not well-formed. DOCDOC flags

Definition at line 1058 of file nodelist.c.

Referenced by getinfo_helper_dir(), and handle_control_hspost().

◆ node_get_by_id()

const node_t* node_get_by_id ( const char *  identity_digest)

◆ node_get_by_nickname()

const node_t* node_get_by_nickname ( const char *  nickname,
unsigned  flags 
)

Given a nickname (possibly verbose, possibly a hexadecimal digest), return the corresponding node_t, or NULL if none exists. Warn the user if they have specified a router by nickname, unless the NNF_NO_WARN_UNNAMED bit is set in flags.

Definition at line 1085 of file nodelist.c.

Referenced by circuit_discard_optional_exit_enclaves(), connection_ap_can_use_exit(), get_my_declared_family(), and nodefamily_add_nodes_to_smartlist().

◆ node_get_curve25519_onion_key()

const curve25519_public_key_t* node_get_curve25519_onion_key ( const node_t node)

Return the curve25519 key of node, or NULL if none.

Definition at line 2016 of file nodelist.c.

Referenced by node_has_curve25519_onion_key(), and node_supports_v3_rendezvous_point().

◆ node_get_declared_uptime()

long node_get_declared_uptime ( const node_t node)

Return node's declared uptime, or -1 if it doesn't seem to have one.

Definition at line 1712 of file nodelist.c.

◆ node_get_ed25519_id()

const ed25519_public_key_t* node_get_ed25519_id ( const node_t node)

Return the Ed25519 identity key for the provided node, or NULL if it doesn't have one.

Definition at line 1150 of file nodelist.c.

Referenced by node_add_to_ed25519_map(), node_describe(), node_ed25519_id_matches(), node_supports_ed25519_link_authentication(), and nodelist_remove_microdesc().

◆ node_get_mutable_by_ed25519_id()

node_t* node_get_mutable_by_ed25519_id ( const ed25519_public_key_t ed_id)

As node_get_by_ed25519_id, but returns a non-const pointer

Definition at line 210 of file nodelist.c.

Referenced by node_get_by_ed25519_id().

◆ node_get_mutable_by_id()

node_t* node_get_mutable_by_id ( const char *  identity_digest)

◆ node_get_nickname()

const char* node_get_nickname ( const node_t node)

Return the nickname of node, or NULL if we can't find one.

Definition at line 1450 of file nodelist.c.

Referenced by node_get_verbose_nickname(), node_nickname_matches(), nodefamily_contains_node(), and rep_hist_dump_stats().

◆ node_get_or_create()

static node_t* node_get_or_create ( const char *  identity_digest)
static

Internal: return the node_t whose identity_digest is identity_digest. If none exists, create a new one, add it to the nodelist, and return it.

Requires that the nodelist be initialized.

Definition at line 246 of file nodelist.c.

Referenced by nodelist_set_routerinfo().

◆ node_get_platform()

const char* node_get_platform ( const node_t node)

Return node's platform string, or NULL if we don't know it.

Definition at line 1722 of file nodelist.c.

◆ node_get_pref_dirport()

void node_get_pref_dirport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the preferred Dir port (IP address and TCP port) for node into *ap_out.

Definition at line 1945 of file nodelist.c.

◆ node_get_pref_ipv6_dirport()

void node_get_pref_ipv6_dirport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the preferred IPv6 Dir port (IP address and TCP port) for node into *ap_out.

Definition at line 1960 of file nodelist.c.

Referenced by node_get_pref_dirport().

◆ node_get_pref_ipv6_orport()

void node_get_pref_ipv6_orport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the preferred IPv6 OR port (IP address and TCP port) for node into *ap_out.

Definition at line 1857 of file nodelist.c.

Referenced by node_get_pref_orport(), nodelist_add_node_and_family(), and nodes_in_same_family().

◆ node_get_pref_orport()

void node_get_pref_orport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the preferred OR port (IP address and TCP port) for node into *ap_out.

Definition at line 1842 of file nodelist.c.

◆ node_get_prim_addr_ipv4()

static const tor_addr_t* node_get_prim_addr_ipv4 ( const node_t node)
static

Return the IPv4 address for node, or NULL if none found.

Definition at line 1681 of file nodelist.c.

Referenced by node_get_address_string(), and router_find_exact_exit_enclave().

◆ node_get_prim_dirport()

void node_get_prim_dirport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the primary (IPv4) Dir port (IP address and TCP port) for node into *ap_out.

Definition at line 1922 of file nodelist.c.

Referenced by node_get_pref_dirport().

◆ node_get_prim_orport()

void node_get_prim_orport ( const node_t node,
tor_addr_port_t ap_out 
)

Copy the primary (IPv4) OR port (IP address and TCP port) for node into *ap_out.

Definition at line 1821 of file nodelist.c.

Referenced by node_get_addr(), and node_get_pref_orport().

◆ node_get_protover_summary_flags()

static const protover_summary_flags_t* node_get_protover_summary_flags ( const node_t node)
static

◆ node_get_purpose()

int node_get_purpose ( const node_t node)

Return the router_purpose of node.

Definition at line 1521 of file nodelist.c.

◆ node_get_rsa_id_digest()

const uint8_t* node_get_rsa_id_digest ( const node_t node)

Return the RSA ID key's SHA1 digest for the provided node.

Definition at line 1346 of file nodelist.c.

Referenced by nodefamily_contains_node().

◆ node_get_verbose_nickname()

void node_get_verbose_nickname ( const node_t node,
char *  verbose_name_out 
)

Compute the verbose ("extended") nickname of node and store it into the MAX_VERBOSE_NICKNAME_LEN+1 character buffer at verbose_name_out

Definition at line 1533 of file nodelist.c.

Referenced by node_get_verbose_nickname_by_id(), and orconn_target_get_name().

◆ node_get_verbose_nickname_by_id()

void node_get_verbose_nickname_by_id ( const char *  id_digest,
char *  verbose_name_out 
)

Compute the verbose ("extended") nickname of node with given id_digest and store it into the MAX_VERBOSE_NICKNAME_LEN+1 character buffer at verbose_name_out

If node_get_by_id() returns NULL, base 16 encoding of id_digest is returned instead.

Definition at line 1553 of file nodelist.c.

Referenced by node_describe_longname_by_id().

◆ node_has_any_descriptor()

int node_has_any_descriptor ( const node_t node)

Return true iff node has either kind of descriptor – that is, a routerdescriptor or a microdescriptor.

You should probably use node_has_preferred_descriptor() instead.

Definition at line 1487 of file nodelist.c.

◆ node_has_curve25519_onion_key()

int node_has_curve25519_onion_key ( const node_t node)

Return true iff node has a curve25519 onion key.

Definition at line 2009 of file nodelist.c.

◆ node_has_declared_family()

STATIC bool node_has_declared_family ( const node_t node)

Return true iff node has declared a nonempty family.

Definition at line 2154 of file nodelist.c.

◆ node_has_preferred_descriptor()

int node_has_preferred_descriptor ( const node_t node,
int  for_direct_connect 
)

Return true iff node has the kind of descriptor we would prefer to use for it, given our configuration and how we intend to use the node.

If for_direct_connect is true, we intend to connect to the node directly, as the first hop of a circuit; otherwise, we intend to connect to it indirectly, or use it as if we were connecting to it indirectly.

Definition at line 1500 of file nodelist.c.

Referenced by extend_info_from_node(), guard_has_descriptor(), and node_has_hsdir_index().

◆ node_in_nickname_smartlist()

STATIC int node_in_nickname_smartlist ( const smartlist_t lst,
const node_t node 
)

Return true iff node is named by some nickname in lst.

Definition at line 2127 of file nodelist.c.

Referenced by node_family_contains().

◆ node_ipv6_dir_preferred()

int node_ipv6_dir_preferred ( const node_t node)

Return 1 if we prefer the IPv6 address and Dir TCP port of node, else 0.

We prefer the IPv6 address if the router has an IPv6 address, and we can use IPv6 addresses, and: i) the router has no IPv4 Dir address. or ii) our preference is for IPv6 Dir addresses.

If there is no node, use reachable_addr_prefer_ipv6_dirport().

Definition at line 1899 of file nodelist.c.

Referenced by node_get_pref_dirport().

◆ node_ipv6_or_preferred()

int node_ipv6_or_preferred ( const node_t node)

Return 1 if we prefer the IPv6 address and OR TCP port of node, else 0.

We prefer the IPv6 address if the router has an IPv6 address, and we can use IPv6 addresses, and: i) the node_t says that it prefers IPv6 or ii) the router has no IPv4 OR address.

If you don't have a node, consider looking it up. If there is no node, use reachable_addr_prefer_ipv6_orport().

Definition at line 1791 of file nodelist.c.

Referenced by node_get_pref_orport().

◆ node_is_dir()

int node_is_dir ( const node_t node)

Return true iff node appears to be a directory authority or directory cache

Definition at line 1464 of file nodelist.c.

Referenced by node_is_possible_guard().

◆ node_is_good_exit()

int node_is_good_exit ( const node_t node)

Return 1 iff node has Exit flag and no BadExit flag. Otherwise, return 0.

Definition at line 794 of file nodelist.c.

◆ node_is_me()

int node_is_me ( const node_t node)

Return true iff node is one representing this router.

Definition at line 1735 of file nodelist.c.

◆ node_is_unreliable()

int node_is_unreliable ( const node_t node,
int  need_uptime,
int  need_capacity,
int  need_guard 
)

Return 1 if router is not suitable for these parameters, else 0. If need_uptime is non-zero, we require a minimum uptime. If need_capacity is non-zero, we require a minimum advertised bandwidth. If need_guard, we require that the router is a possible entry guard.

Definition at line 2335 of file nodelist.c.

Referenced by router_exit_policy_all_nodes_reject().

◆ node_is_usable()

static int node_is_usable ( const node_t node)
inlinestatic

Helper: return true iff a node has a usable amount of information

Definition at line 801 of file nodelist.c.

Referenced by nodelist_remove_routerinfo().

◆ node_log_dup_ed_id()

static void node_log_dup_ed_id ( const node_t old,
const node_t node,
const char *  ed_id 
)
static

Helper function to log details of duplicated ed2559_ids

Definition at line 295 of file nodelist.c.

◆ node_lookup_declared_family()

STATIC void node_lookup_declared_family ( smartlist_t out,
const node_t node 
)

Add to out every node_t that is listed by node as being in its family. (Note that these nodes are not in node's family unless they also agree that node is in their family.)

Definition at line 2174 of file nodelist.c.

◆ node_nickname_matches()

STATIC int node_nickname_matches ( const node_t node,
const char *  nickname 
)

Return true if node's nickname matches nickname (case-insensitive), or if node's identity key digest matches a hexadecimal value stored in nickname. Return false otherwise.

Definition at line 2115 of file nodelist.c.

Referenced by node_in_nickname_smartlist().

◆ node_remove_from_ed25519_map()

static int node_remove_from_ed25519_map ( node_t node)
static

Remove node from the ed25519 map (if it present), and set its ed25519_id field to zero.

Definition at line 268 of file nodelist.c.

Referenced by nodelist_drop_node(), nodelist_remove_microdesc(), and nodelist_set_routerinfo().

◆ node_set_country()

void node_set_country ( node_t node)

Refresh the country code of ri. This function MUST be called on each router when the GeoIP database is reloaded, and on all new routers.

Definition at line 2062 of file nodelist.c.

Referenced by nodelist_refresh_countries(), and nodelist_set_routerinfo().

◆ node_supports_accepting_ipv6_extends()

bool node_supports_accepting_ipv6_extends ( const node_t node,
bool  need_canonical_ipv6_conn 
)

Return true iff node can accept IPv6 extends (Relay=2 or Relay=3) from other relays. If need_canonical_ipv6_conn is true, also check if the relay supports canonical IPv6 connections (Relay=3 only).

This check should only be performed by client path selection code.

Definition at line 1324 of file nodelist.c.

◆ node_supports_ed25519_hs_intro()

bool node_supports_ed25519_hs_intro ( const node_t node)

Return true iff node supports ed25519 authentication as an hidden service introduction point.

Definition at line 1261 of file nodelist.c.

◆ node_supports_ed25519_link_authentication()

bool node_supports_ed25519_link_authentication ( const node_t node,
bool  compatible_with_us 
)

Return true iff node supports authenticating itself by ed25519 ID during the link handshake. If compatible_with_us, it needs to be using a link authentication method that we understand. If not, any plausible link authentication method will do.

Definition at line 1235 of file nodelist.c.

◆ node_supports_establish_intro_dos_extension()

bool node_supports_establish_intro_dos_extension ( const node_t node)

Return true iff node supports the DoS ESTABLISH_INTRO cell extension.

Definition at line 1286 of file nodelist.c.

◆ node_supports_initiating_ipv6_extends()

bool node_supports_initiating_ipv6_extends ( const node_t node)

Return true iff node can initiate IPv6 extends (Relay=3).

This check should only be performed by client path selection code.

Extending relays should check their own IPv6 support using router_can_extend_over_ipv6(). Like other extends, they should not verify the link specifiers in the extend cell against the consensus, because it may be out of date.

Definition at line 1303 of file nodelist.c.

◆ node_supports_v3_hsdir()

bool node_supports_v3_hsdir ( const node_t node)

Return true iff node supports the hidden service directory version 3 protocol (proposal 224).

Definition at line 1251 of file nodelist.c.

Referenced by node_has_hsdir_index().

◆ node_supports_v3_rendezvous_point()

bool node_supports_v3_rendezvous_point ( const node_t node)

Return true iff node can be a rendezvous point for hidden service version 3 (HSRend=2).

Definition at line 1271 of file nodelist.c.

Referenced by client_rendezvous_circ_has_opened().

◆ nodelist_add_addr_to_address_set()

void nodelist_add_addr_to_address_set ( const tor_addr_t addr,
uint16_t  or_port,
uint16_t  dir_port 
)

Add the given address into the nodelist address set.

Definition at line 525 of file nodelist.c.

Referenced by add_trusted_dir_to_nodelist_addr_set(), and node_add_to_address_set().

◆ nodelist_add_microdesc()

node_t* nodelist_add_microdesc ( microdesc_t md)

Set the appropriate node_t to use md as its microdescriptor.

Called when a new microdesc has arrived and the usable consensus flavor is "microdesc".

Definition at line 635 of file nodelist.c.

◆ nodelist_add_node_and_family()

void nodelist_add_node_and_family ( smartlist_t sl,
const node_t node 
)

Add all the family of node, including node itself, to the smartlist sl.

This is used to make sure we don't pick siblings in a single path, or pick more than one relay from a family for our entry guard list. Note that a node may be added to sl more than once if it is part of node's family for more than one reason.

Definition at line 2242 of file nodelist.c.

Referenced by build_middle_exclude_list(), and routerlist_add_node_and_family().

◆ nodelist_assert_ok()

void nodelist_assert_ok ( void  )

Check that the nodelist is internally consistent, and consistent with the directory info it's derived from.

Definition at line 949 of file nodelist.c.

◆ nodelist_drop_node()

static void nodelist_drop_node ( node_t node,
int  remove_from_ht 
)
static

Remove node from the nodelist. (Asserts that it was there to begin with.)

Definition at line 838 of file nodelist.c.

Referenced by nodelist_remove_routerinfo().

◆ nodelist_ensure_freshness()

void nodelist_ensure_freshness ( const networkstatus_t ns)

Ensure that the nodelist has been created with the most recent consensus. If that's not the case, make it so.

Definition at line 1026 of file nodelist.c.

◆ nodelist_find_nodes_with_microdesc()

smartlist_t* nodelist_find_nodes_with_microdesc ( const microdesc_t md)

Return a newly allocated smartlist of the nodes that have md as their microdescriptor.

Definition at line 863 of file nodelist.c.

◆ nodelist_free_all()

void nodelist_free_all ( void  )

Release all storage held by the nodelist.

Definition at line 923 of file nodelist.c.

◆ nodelist_get_list()

const smartlist_t* nodelist_get_list ( void  )

Return a list of a node_t * for every node we know about. The caller MUST NOT modify the list. (You can set and clear flags in the nodes if you must, but you must not add or remove nodes.)

Definition at line 1047 of file nodelist.c.

Referenced by choose_guard_selection(), directory_remove_invalid(), microdesc_check_counts(), networkstatus_reset_warnings(), nodelist_add_node_and_family(), nodelist_refresh_countries(), nodelist_subtract(), router_add_running_nodes_to_smartlist(), router_exit_policy_all_nodes_reject(), and router_find_exact_exit_enclave().

◆ nodelist_probably_contains_address()

int nodelist_probably_contains_address ( const tor_addr_t addr)

Return true if addr is the address of some node in the nodelist. If not, probably return false.

Definition at line 548 of file nodelist.c.

◆ nodelist_purge()

void nodelist_purge ( void  )

Remove all entries from the nodelist that don't have enough info to be usable for anything.

Definition at line 894 of file nodelist.c.

◆ nodelist_reentry_contains()

bool nodelist_reentry_contains ( const tor_addr_t addr,
uint16_t  port 
)

Return true if addr is the address of some node in the nodelist and corresponds also to the given port. If not, probably return false.

Definition at line 562 of file nodelist.c.

◆ nodelist_refresh_countries()

void nodelist_refresh_countries ( void  )

Set the country code of all routers in the routerlist.

Definition at line 2083 of file nodelist.c.

Referenced by refresh_all_country_info().

◆ nodelist_remove_microdesc()

void nodelist_remove_microdesc ( const char *  identity_digest,
microdesc_t md 
)

Tell the nodelist that md is no longer a microdescriptor for the node with identity_digest.

Definition at line 809 of file nodelist.c.

◆ nodelist_remove_routerinfo()

void nodelist_remove_routerinfo ( routerinfo_t ri)

Tell the nodelist that ri is no longer in the routerlist.

Definition at line 823 of file nodelist.c.

◆ nodelist_set_consensus()

void nodelist_set_consensus ( const networkstatus_t ns)

Tell the nodelist that the current usable consensus is ns. This makes the nodelist change all of the routerstatus entries for the nodes, drop nodes that no longer have enough info to get used, and grab microdescriptors into nodes as appropriate.

Definition at line 689 of file nodelist.c.

◆ nodelist_set_routerinfo()

node_t* nodelist_set_routerinfo ( routerinfo_t ri,
routerinfo_t **  ri_old_out 
)

Add ri to an appropriate node in the nodelist. If we replace an old routerinfo, and ri_old_out is not NULL, set *ri_old_out to the previous routerinfo.

Definition at line 579 of file nodelist.c.

◆ nodes_in_same_family()

int nodes_in_same_family ( const node_t node1,
const node_t node2 
)

Return true iff r1 and r2 are in the same family, but not the same router.

Definition at line 2195 of file nodelist.c.

Referenced by guard_in_node_family().

◆ router_addrs_in_same_network()

int router_addrs_in_same_network ( const tor_addr_t a1,
const tor_addr_t a2 
)

Return true iff router1 and router2 have similar enough network addresses that we should treat them as being in the same family

Definition at line 2093 of file nodelist.c.

Referenced by guard_in_node_family(), nodelist_add_node_and_family(), and nodes_in_same_family().

◆ router_dir_info_changed()

void router_dir_info_changed ( void  )

Called when our internal view of the directory has changed. This can be when the authorities change, networkstatuses change, the list of routerdescs changes, or number of running routers changes.

Definition at line 2470 of file nodelist.c.

Referenced by check_expired_networkstatus_callback(), and dir_server_add().

◆ router_exit_policy_all_nodes_reject()

int router_exit_policy_all_nodes_reject ( const tor_addr_t addr,
uint16_t  port,
int  need_uptime 
)

Return 1 if all running sufficiently-stable routers we can use will reject addr:port. Return 0 if any might accept it.

Definition at line 2350 of file nodelist.c.

◆ router_find_exact_exit_enclave()

const node_t* router_find_exact_exit_enclave ( const char *  address,
uint16_t  port 
)

Find a router that's up, that has this IP address, and that allows exit to this address:port, or return NULL if there isn't a good one. Don't exit enclave to excluded relays – it wouldn't actually hurt anything, but this way there are fewer confused users.

Definition at line 2307 of file nodelist.c.

◆ router_have_consensus_path()

consensus_path_type_t router_have_consensus_path ( void  )

Set to CONSENSUS_PATH_EXIT if there is at least one exit node in the consensus. We update this flag in compute_frac_paths_available if there is at least one relay that has an Exit flag in the consensus. Used to avoid building exit circuits when they will almost certainly fail. Set to CONSENSUS_PATH_INTERNAL if there are no exits in the consensus. (This situation typically occurs during bootstrap of a test network.) Set to CONSENSUS_PATH_UNKNOWN if we have never checked, or have reason to believe our last known value was invalid or has expired. If we're in a network with TestingDirAuthVoteExit set, this can cause router_have_consensus_path() to be set to CONSENSUS_PATH_EXIT, even if there are no nodes with accept exit policies.

Definition at line 2460 of file nodelist.c.

Referenced by circuit_build_needed_circs(), and run_build_circuit_event().

◆ router_have_minimum_dir_info()

int router_have_minimum_dir_info ( void  )

Return true iff we have enough consensus information to start building circuits. Right now, this means "a consensus that's less than a day old, and at least 60% of router descriptors (configurable), weighted by bandwidth. Treat the exit fraction as 100% if there are no exits in the consensus." To obtain the final weighted bandwidth, we multiply the weighted bandwidth fraction for each position (guard, middle, exit).

Definition at line 2427 of file nodelist.c.

Referenced by check_expired_networkstatus_callback(), directory_info_has_arrived(), second_elapsed_callback(), and update_extrainfo_downloads().

◆ router_set_status()

void router_set_status ( const char *  digest,
int  up 
)

Mark the router with ID digest as running or non-running in our routerlist.

Definition at line 2371 of file nodelist.c.

Referenced by channel_do_open_actions(), connection_dir_client_request_failed(), and learned_bridge_descriptor().

◆ update_router_have_minimum_dir_info()

static void update_router_have_minimum_dir_info ( void  )
static

Change the value of have_min_dir_info, setting it true iff we have enough network and router information to build circuits. Clear the value of need_to_update_have_min_dir_info.

Definition at line 2814 of file nodelist.c.

Variable Documentation

◆ dir_info_status

char dir_info_status[512] = ""
static

String describing what we're missing before we have enough directory info.

Definition at line 2417 of file nodelist.c.

Referenced by get_dir_info_status_string().

◆ have_consensus_path

consensus_path_type_t have_consensus_path = CONSENSUS_PATH_UNKNOWN
static

Does the consensus contain nodes that can exit?

Definition at line 2409 of file nodelist.c.

Referenced by router_have_consensus_path().

◆ have_min_dir_info

int have_min_dir_info = 0
static

True iff, the last time we checked whether we had enough directory info to build circuits, the answer was "yes". If there are no exits in the consensus, we act as if we have 100% of the exit directory info.

Definition at line 2406 of file nodelist.c.

◆ need_to_update_have_min_dir_info

int need_to_update_have_min_dir_info = 1
static

True iff enough has changed since the last time we checked whether we had enough directory info to build circuits that our old answer can no longer be trusted.

Definition at line 2414 of file nodelist.c.

Referenced by router_dir_info_changed().

◆ the_nodelist

nodelist_t* the_nodelist =NULL
static

◆ zero_protover_flags

const protover_summary_flags_t zero_protover_flags
static
Initial value:
= {
0,0,0,0,0,0,0,0,0,0,0,0
}

Dummy object that should be unreturnable. Used to ensure that node_get_protover_summary_flags() always returns non-NULL.

Definition at line 1207 of file nodelist.c.