Tor  0.4.7.0-alpha-dev
node_select.h
Go to the documentation of this file.
1 /* Copyright (c) 2001-2004, Roger Dingledine.
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file node_select.h
8  * \brief Header file for node_select.c
9  **/
10 
11 #ifndef TOR_NODE_SELECT_H
12 #define TOR_NODE_SELECT_H
13 
14 /** Flags to be passed to control router_choose_random_node() to indicate what
15  * kind of nodes to pick according to what algorithm. */
16 typedef enum router_crn_flags_t {
17  /* Try to choose stable nodes. */
18  CRN_NEED_UPTIME = 1<<0,
19  /* Try to choose nodes with a reasonable amount of bandwidth. */
20  CRN_NEED_CAPACITY = 1<<1,
21  /* Only choose nodes if we have downloaded their descriptor or
22  * microdescriptor. */
23  CRN_NEED_DESC = 1<<2,
24  /* Choose nodes that can be used as Guard relays. */
25  CRN_NEED_GUARD = 1<<3,
26  /* On clients, only provide nodes that we can connect to directly, based on
27  * our firewall rules. */
28  CRN_DIRECT_CONN = 1<<4,
29  /* On clients, if choosing a node for a direct connection, only provide
30  * nodes that satisfy ClientPreferIPv6OR. */
31  CRN_PREF_ADDR = 1<<5,
32  /* On clients, only provide nodes with HSRend=2 protocol version which
33  * is required for hidden service version 3. */
34  CRN_RENDEZVOUS_V3 = 1<<6,
35  /* On clients, only provide nodes that can initiate IPv6 extends. */
36  CRN_INITIATE_IPV6_EXTEND = 1<<7,
38 
39 /** Possible ways to weight routers when choosing one randomly. See
40  * routerlist_sl_choose_by_bandwidth() for more information.*/
42  NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
43  WEIGHT_FOR_DIR
45 
46 /* Flags for pick_directory_server() and pick_trusteddirserver(). */
47 /** Flag to indicate that we should not automatically be willing to use
48  * ourself to answer a directory request.
49  * Passed to router_pick_directory_server (et al).*/
50 #define PDS_ALLOW_SELF (1<<0)
51 /** Flag to indicate that if no servers seem to be up, we should mark all
52  * directory servers as up and try again.
53  * Passed to router_pick_directory_server (et al).*/
54 #define PDS_RETRY_IF_NO_SERVERS (1<<1)
55 /** Flag to indicate that we should not exclude directory servers that
56  * our ReachableAddress settings would exclude. This usually means that
57  * we're going to connect to the server over Tor, and so we don't need to
58  * worry about our firewall telling us we can't.
59  * Passed to router_pick_directory_server (et al).*/
60 #define PDS_IGNORE_FASCISTFIREWALL (1<<2)
61 /** Flag to indicate that we should not use any directory authority to which
62  * we have an existing directory connection for downloading server descriptors
63  * or extrainfo documents.
64  *
65  * Passed to router_pick_directory_server (et al)
66  */
67 #define PDS_NO_EXISTING_SERVERDESC_FETCH (1<<3)
68 /** Flag to indicate that we should not use any directory authority to which
69  * we have an existing directory connection for downloading microdescs.
70  *
71  * Passed to router_pick_directory_server (et al)
72  */
73 #define PDS_NO_EXISTING_MICRODESC_FETCH (1<<4)
74 
76  int flags);
77 
78 int router_get_my_share_of_directory_requests(double *v3_share_out);
79 
84  int for_direct_conn);
85 const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
86  struct routerset_t *excludedset,
87  router_crn_flags_t flags);
88 
90  int flags);
92  int flags);
93 
94 #ifdef NODE_SELECT_PRIVATE
95 STATIC int choose_array_element_by_weight(const uint64_t *entries,
96  int n_entries);
97 STATIC void scale_array_elements_to_u64(uint64_t *entries_out,
98  const double *entries_in,
99  int n_entries,
100  uint64_t *total_out);
102  dirinfo_type_t auth, int flags,
103  int *n_busy_out);
104 STATIC int router_is_already_dir_fetching(const tor_addr_port_t *ap,
105  int serverdesc, int microdesc);
106 #endif /* defined(NODE_SELECT_PRIVATE) */
107 
108 #endif /* !defined(TOR_NODE_SELECT_H) */
STATIC int choose_array_element_by_weight(const uint64_t *entries, int n_entries)
Definition: node_select.c:460
STATIC void scale_array_elements_to_u64(uint64_t *entries_out, const double *entries_in, int n_entries, uint64_t *total_out)
Definition: node_select.c:431
STATIC const routerstatus_t * router_pick_directory_server_impl(dirinfo_type_t type, int flags, int *n_busy_out)
Definition: node_select.c:297
const node_t * router_choose_random_node(smartlist_t *excludedsmartlist, struct routerset_t *excludedset, router_crn_flags_t flags)
Definition: node_select.c:979
router_crn_flags_t
Definition: node_select.h:16
const routerstatus_t * router_pick_fallback_dirserver(dirinfo_type_t type, int flags)
Definition: node_select.c:1051
double frac_nodes_with_descriptors(const smartlist_t *sl, bandwidth_weight_rule_t rule, int for_direct_conn)
Definition: node_select.c:821
const node_t * node_sl_choose_by_bandwidth(const smartlist_t *sl, bandwidth_weight_rule_t rule)
Definition: node_select.c:856
const routerstatus_t * router_pick_directory_server(dirinfo_type_t type, int flags)
Definition: node_select.c:72
const routerstatus_t * router_pick_trusteddirserver(dirinfo_type_t type, int flags)
Definition: node_select.c:1040
bandwidth_weight_rule_t
Definition: node_select.h:41
dirinfo_type_t
Definition: or.h:785
Definition: node_st.h:34
#define STATIC
Definition: testsupport.h:32