Extract node_t into its own header.

This commit is contained in:
Nick Mathewson 2018-06-15 13:13:33 -04:00
parent 8b7df72359
commit d2942d127d
34 changed files with 152 additions and 104 deletions

View File

@ -27,6 +27,8 @@
#include "routerset.h" #include "routerset.h"
#include "transports.h" #include "transports.h"
#include "node_st.h"
/** Information about a configured bridge. Currently this just matches the /** Information about a configured bridge. Currently this just matches the
* ones in the torrc file, but one day we may be able to learn about new * ones in the torrc file, but one day we may be able to learn about new
* bridges on our own, and remember them in the state file. */ * bridges on our own, and remember them in the state file. */

View File

@ -67,6 +67,7 @@
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "entry_connection_st.h" #include "entry_connection_st.h"
#include "node_st.h"
#include "or_circuit_st.h" #include "or_circuit_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"

View File

@ -100,6 +100,7 @@
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "entry_connection_st.h" #include "entry_connection_st.h"
#include "node_st.h"
#include "or_circuit_st.h" #include "or_circuit_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
#include "socks_request_st.h" #include "socks_request_st.h"

View File

@ -84,6 +84,7 @@
#include "control_connection_st.h" #include "control_connection_st.h"
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "entry_connection_st.h" #include "entry_connection_st.h"
#include "node_st.h"
#include "or_connection_st.h" #include "or_connection_st.h"
#include "or_circuit_st.h" #include "or_circuit_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"

View File

@ -29,6 +29,7 @@
#include "dirauth/shared_random_state.h" #include "dirauth/shared_random_state.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
#include "vote_timing_st.h" #include "vote_timing_st.h"
/** /**

View File

@ -57,6 +57,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "entry_connection_st.h" #include "entry_connection_st.h"
#include "node_st.h"
#include "rend_service_descriptor_st.h" #include "rend_service_descriptor_st.h"
/** /**

View File

@ -37,6 +37,7 @@
#include "dirauth/dirvote.h" #include "dirauth/dirvote.h"
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "node_st.h"
#include "tor_version_st.h" #include "tor_version_st.h"
/** /**

View File

@ -139,6 +139,7 @@
#include "transports.h" #include "transports.h"
#include "statefile.h" #include "statefile.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
/** A list of existing guard selection contexts. */ /** A list of existing guard selection contexts. */

View File

@ -35,6 +35,7 @@
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "crypt_path_st.h" #include "crypt_path_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
/* A circuit is about to become an e2e rendezvous circuit. Check /* A circuit is about to become an e2e rendezvous circuit. Check

View File

@ -34,6 +34,7 @@
#include "dirauth/shared_random_state.h" #include "dirauth/shared_random_state.h"
#include "edge_connection_st.h" #include "edge_connection_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
/* Trunnel */ /* Trunnel */

View File

@ -15,6 +15,8 @@
#include "hs_service.h" #include "hs_service.h"
#include "nodelist.h" #include "nodelist.h"
#include "node_st.h"
/* Send on the control port the "HS_DESC REQUESTED [...]" event. /* Send on the control port the "HS_DESC REQUESTED [...]" event.
* *
* The onion_pk is the onion service public key, base64_blinded_pk is the * The onion_pk is the onion service public key, base64_blinded_pk is the

View File

@ -41,6 +41,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "edge_connection_st.h" #include "edge_connection_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
/* Trunnel */ /* Trunnel */

View File

@ -248,6 +248,7 @@ ORHEADERS = \
src/or/microdesc.h \ src/or/microdesc.h \
src/or/networkstatus.h \ src/or/networkstatus.h \
src/or/nodelist.h \ src/or/nodelist.h \
src/or/node_st.h \
src/or/ntmain.h \ src/or/ntmain.h \
src/or/onion.h \ src/or/onion.h \
src/or/onion_fast.h \ src/or/onion_fast.h \

View File

@ -22,6 +22,8 @@
#include "routerlist.h" #include "routerlist.h"
#include "routerparse.h" #include "routerparse.h"
#include "node_st.h"
/** A data structure to hold a bunch of cached microdescriptors. There are /** A data structure to hold a bunch of cached microdescriptors. There are
* two active files in the cache: a "cache file" that we mmap, and a "journal * two active files in the cache: a "cache file" that we mmap, and a "journal
* file" that we append to. Periodically, we rebuild the cache file to hold * file" that we append to. Periodically, we rebuild the cache file to hold

View File

@ -76,6 +76,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
/** Most recently received and validated v3 "ns"-flavored consensus network /** Most recently received and validated v3 "ns"-flavored consensus network
* status. */ * status. */

100
src/or/node_st.h Normal file
View File

@ -0,0 +1,100 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef NODE_ST_H
#define NODE_ST_H
/** A node_t represents a Tor router.
*
* Specifically, a node_t is a Tor router as we are using it: a router that
* we are considering for circuits, connections, and so on. A node_t is a
* thin wrapper around the routerstatus, routerinfo, and microdesc for a
* single router, and provides a consistent interface for all of them.
*
* Also, a node_t has mutable state. While a routerinfo, a routerstatus,
* and a microdesc have[*] only the information read from a router
* descriptor, a consensus entry, and a microdescriptor (respectively)...
* a node_t has flags based on *our own current opinion* of the node.
*
* [*] Actually, there is some leftover information in each that is mutable.
* We should try to excise that.
*/
struct node_t {
/* Indexing information */
/** Used to look up the node_t by its identity digest. */
HT_ENTRY(node_t) ht_ent;
/** Used to look up the node_t by its ed25519 identity digest. */
HT_ENTRY(node_t) ed_ht_ent;
/** Position of the node within the list of nodes */
int nodelist_idx;
/** The identity digest of this node_t. No more than one node_t per
* identity may exist at a time. */
char identity[DIGEST_LEN];
/** The ed25519 identity of this node_t. This field is nonzero iff we
* currently have an ed25519 identity for this node in either md or ri,
* _and_ this node has been inserted to the ed25519-to-node map in the
* nodelist.
*/
ed25519_public_key_t ed25519_id;
microdesc_t *md;
routerinfo_t *ri;
routerstatus_t *rs;
/* local info: copied from routerstatus, then possibly frobbed based
* on experience. Authorities set this stuff directly. Note that
* these reflect knowledge of the primary (IPv4) OR port only. */
unsigned int is_running:1; /**< As far as we know, is this OR currently
* running? */
unsigned int is_valid:1; /**< Has a trusted dirserver validated this OR?
* (For Authdir: Have we validated this OR?) */
unsigned int is_fast:1; /** Do we think this is a fast OR? */
unsigned int is_stable:1; /** Do we think this is a stable OR? */
unsigned int is_possible_guard:1; /**< Do we think this is an OK guard? */
unsigned int is_exit:1; /**< Do we think this is an OK exit? */
unsigned int is_bad_exit:1; /**< Do we think this exit is censored, borked,
* or otherwise nasty? */
unsigned int is_hs_dir:1; /**< True iff this router is a hidden service
* directory according to the authorities. */
/* Local info: warning state. */
unsigned int name_lookup_warned:1; /**< Have we warned the user for referring
* to this (unnamed) router by nickname?
*/
/** Local info: we treat this node as if it rejects everything */
unsigned int rejects_all:1;
/* Local info: derived. */
/** True if the IPv6 OR port is preferred over the IPv4 OR port.
* XX/teor - can this become out of date if the torrc changes? */
unsigned int ipv6_preferred:1;
/** According to the geoip db what country is this router in? */
/* XXXprop186 what is this suppose to mean with multiple OR ports? */
country_t country;
/* The below items are used only by authdirservers for
* reachability testing. */
/** When was the last time we could reach this OR? */
time_t last_reachable; /* IPv4. */
time_t last_reachable6; /* IPv6. */
/* Hidden service directory index data. This is used by a service or client
* in order to know what's the hs directory index for this node at the time
* the consensus is set. */
struct hsdir_index_t hsdir_index;
};
#endif

View File

@ -69,6 +69,7 @@
#include "dirauth/mode.h" #include "dirauth/mode.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
static void nodelist_drop_node(node_t *node, int remove_from_ht); static void nodelist_drop_node(node_t *node, int remove_from_ht);
#define node_free(val) \ #define node_free(val) \
@ -634,6 +635,14 @@ nodelist_set_consensus(networkstatus_t *ns)
} }
} }
/** Return 1 iff <b>node</b> has Exit flag and no BadExit flag.
* Otherwise, return 0.
*/
int node_is_good_exit(const node_t *node)
{
return node->is_exit && ! node->is_bad_exit;
}
/** Helper: return true iff a node has a usable amount of information*/ /** Helper: return true iff a node has a usable amount of information*/
static inline int static inline int
node_is_usable(const node_t *node) node_is_usable(const node_t *node)

View File

@ -46,6 +46,7 @@ void node_get_verbose_nickname(const node_t *node,
void node_get_verbose_nickname_by_id(const char *id_digest, void node_get_verbose_nickname_by_id(const char *id_digest,
char *verbose_name_out); char *verbose_name_out);
int node_is_dir(const node_t *node); int node_is_dir(const node_t *node);
int node_is_good_exit(const node_t *node);
int node_has_any_descriptor(const node_t *node); int node_has_any_descriptor(const node_t *node);
int node_has_preferred_descriptor(const node_t *node, int node_has_preferred_descriptor(const node_t *node,
int for_direct_connect); int for_direct_connect);

View File

@ -1857,94 +1857,7 @@ typedef struct microdesc_t {
} microdesc_t; } microdesc_t;
/** A node_t represents a Tor router. typedef struct node_t node_t;
*
* Specifically, a node_t is a Tor router as we are using it: a router that
* we are considering for circuits, connections, and so on. A node_t is a
* thin wrapper around the routerstatus, routerinfo, and microdesc for a
* single router, and provides a consistent interface for all of them.
*
* Also, a node_t has mutable state. While a routerinfo, a routerstatus,
* and a microdesc have[*] only the information read from a router
* descriptor, a consensus entry, and a microdescriptor (respectively)...
* a node_t has flags based on *our own current opinion* of the node.
*
* [*] Actually, there is some leftover information in each that is mutable.
* We should try to excise that.
*/
typedef struct node_t {
/* Indexing information */
/** Used to look up the node_t by its identity digest. */
HT_ENTRY(node_t) ht_ent;
/** Used to look up the node_t by its ed25519 identity digest. */
HT_ENTRY(node_t) ed_ht_ent;
/** Position of the node within the list of nodes */
int nodelist_idx;
/** The identity digest of this node_t. No more than one node_t per
* identity may exist at a time. */
char identity[DIGEST_LEN];
/** The ed25519 identity of this node_t. This field is nonzero iff we
* currently have an ed25519 identity for this node in either md or ri,
* _and_ this node has been inserted to the ed25519-to-node map in the
* nodelist.
*/
ed25519_public_key_t ed25519_id;
microdesc_t *md;
routerinfo_t *ri;
routerstatus_t *rs;
/* local info: copied from routerstatus, then possibly frobbed based
* on experience. Authorities set this stuff directly. Note that
* these reflect knowledge of the primary (IPv4) OR port only. */
unsigned int is_running:1; /**< As far as we know, is this OR currently
* running? */
unsigned int is_valid:1; /**< Has a trusted dirserver validated this OR?
* (For Authdir: Have we validated this OR?) */
unsigned int is_fast:1; /** Do we think this is a fast OR? */
unsigned int is_stable:1; /** Do we think this is a stable OR? */
unsigned int is_possible_guard:1; /**< Do we think this is an OK guard? */
unsigned int is_exit:1; /**< Do we think this is an OK exit? */
unsigned int is_bad_exit:1; /**< Do we think this exit is censored, borked,
* or otherwise nasty? */
unsigned int is_hs_dir:1; /**< True iff this router is a hidden service
* directory according to the authorities. */
/* Local info: warning state. */
unsigned int name_lookup_warned:1; /**< Have we warned the user for referring
* to this (unnamed) router by nickname?
*/
/** Local info: we treat this node as if it rejects everything */
unsigned int rejects_all:1;
/* Local info: derived. */
/** True if the IPv6 OR port is preferred over the IPv4 OR port.
* XX/teor - can this become out of date if the torrc changes? */
unsigned int ipv6_preferred:1;
/** According to the geoip db what country is this router in? */
/* XXXprop186 what is this suppose to mean with multiple OR ports? */
country_t country;
/* The below items are used only by authdirservers for
* reachability testing. */
/** When was the last time we could reach this OR? */
time_t last_reachable; /* IPv4. */
time_t last_reachable6; /* IPv6. */
/* Hidden service directory index data. This is used by a service or client
* in order to know what's the hs directory index for this node at the time
* the consensus is set. */
struct hsdir_index_t hsdir_index;
} node_t;
/** Linked list of microdesc hash lines for a single router in a directory /** Linked list of microdesc hash lines for a single router in a directory
* vote. * vote.
@ -2385,14 +2298,6 @@ typedef enum {
/** Convert a circuit subtype to a circuit_t. */ /** Convert a circuit subtype to a circuit_t. */
#define TO_CIRCUIT(x) (&((x)->base_)) #define TO_CIRCUIT(x) (&((x)->base_))
/** Return 1 iff <b>node</b> has Exit flag and no BadExit flag.
* Otherwise, return 0.
*/
static inline int node_is_good_exit(const node_t *node)
{
return node->is_exit && ! node->is_bad_exit;
}
/* limits for TCP send and recv buffer size used for constrained sockets */ /* limits for TCP send and recv buffer size used for constrained sockets */
#define MIN_CONSTRAINED_TCP_BUFFER 2048 #define MIN_CONSTRAINED_TCP_BUFFER 2048
#define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */ #define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */

View File

@ -31,6 +31,7 @@
#include "ht.h" #include "ht.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
#include "port_cfg_st.h" #include "port_cfg_st.h"
/** Policy that addresses for incoming SOCKS connections must match. */ /** Policy that addresses for incoming SOCKS connections must match. */

View File

@ -42,6 +42,7 @@
#include "crypt_path_st.h" #include "crypt_path_st.h"
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
#include "port_cfg_st.h" #include "port_cfg_st.h"

View File

@ -127,6 +127,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "dir_server_st.h" #include "dir_server_st.h"
#include "node_st.h"
// #define DEBUG_ROUTERLIST // #define DEBUG_ROUTERLIST

View File

@ -36,6 +36,8 @@
#include "routerparse.h" #include "routerparse.h"
#include "routerset.h" #include "routerset.h"
#include "node_st.h"
/** Return a new empty routerset. */ /** Return a new empty routerset. */
routerset_t * routerset_t *
routerset_new(void) routerset_new(void)

View File

@ -26,6 +26,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "entry_connection_st.h" #include "entry_connection_st.h"
#include "node_st.h"
#include "or_connection_st.h" #include "or_connection_st.h"
#include "socks_request_st.h" #include "socks_request_st.h"

View File

@ -33,6 +33,7 @@
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "crypt_path_st.h" #include "crypt_path_st.h"
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
#include "test_helpers.h" #include "test_helpers.h"

View File

@ -25,6 +25,7 @@
#include "routerlist.h" #include "routerlist.h"
#include "connection_st.h" #include "connection_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
#include "test.h" #include "test.h"

View File

@ -22,6 +22,7 @@
#include "routerset.h" #include "routerset.h"
#include "circuitbuild.h" #include "circuitbuild.h"
#include "node_st.h"
#include "rend_encoded_v2_service_descriptor_st.h" #include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h" #include "rend_intro_point_st.h"

View File

@ -33,6 +33,8 @@
#include "util.h" #include "util.h"
#include "voting_schedule.h" #include "voting_schedule.h"
#include "node_st.h"
/** Test the validation of HS v3 addresses */ /** Test the validation of HS v3 addresses */
static void static void
test_validate_address(void *arg) test_validate_address(void *arg)

View File

@ -7,10 +7,6 @@
**/ **/
#define CONTROL_PRIVATE #define CONTROL_PRIVATE
#define CIRCUITBUILD_PRIVATE
#define RENDCOMMON_PRIVATE
#define RENDSERVICE_PRIVATE
#define HS_SERVICE_PRIVATE
#include "or.h" #include "or.h"
#include "test.h" #include "test.h"
@ -19,10 +15,9 @@
#include "hs_common.h" #include "hs_common.h"
#include "hs_control.h" #include "hs_control.h"
#include "nodelist.h" #include "nodelist.h"
//#include "rendcommon.h"
//#include "rendservice.h" #include "node_st.h"
//#include "routerset.h"
//#include "circuitbuild.h"
#include "test_helpers.h" #include "test_helpers.h"
/* mock ID digest and longname for node that's in nodelist */ /* mock ID digest and longname for node that's in nodelist */

View File

@ -55,6 +55,7 @@
#include "cpath_build_state_st.h" #include "cpath_build_state_st.h"
#include "crypt_path_st.h" #include "crypt_path_st.h"
#include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
/* Trunnel */ /* Trunnel */

View File

@ -11,6 +11,9 @@
#include "networkstatus.h" #include "networkstatus.h"
#include "nodelist.h" #include "nodelist.h"
#include "torcert.h" #include "torcert.h"
#include "node_st.h"
#include "test.h" #include "test.h"
/** Test the case when node_get_by_id() returns NULL, /** Test the case when node_get_by_id() returns NULL,

View File

@ -10,6 +10,7 @@
#include "policies.h" #include "policies.h"
#include "test.h" #include "test.h"
#include "node_st.h"
#include "port_cfg_st.h" #include "port_cfg_st.h"
/* Helper: assert that short_policy parses and writes back out as itself, /* Helper: assert that short_policy parses and writes back out as itself,

View File

@ -35,6 +35,7 @@
#include "statefile.h" #include "statefile.h"
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "node_st.h"
#include "test.h" #include "test.h"
#include "test_dir_common.h" #include "test_dir_common.h"

View File

@ -9,6 +9,9 @@
#include "routerparse.h" #include "routerparse.h"
#include "policies.h" #include "policies.h"
#include "nodelist.h" #include "nodelist.h"
#include "node_st.h"
#include "test.h" #include "test.h"
#define NS_MODULE routerset #define NS_MODULE routerset