Tor 0.4.9.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. */
16typedef 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,
37 /* On clients, only provide nodes that support Conflux (Relay=5). */
38 CRN_CONFLUX = 1<<8,
40
41/** Possible ways to weight routers when choosing one randomly. See
42 * routerlist_sl_choose_by_bandwidth() for more information.*/
44 NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
45 WEIGHT_FOR_DIR
47
48/* Flags for pick_directory_server() and pick_trusteddirserver(). */
49/** Flag to indicate that we should not automatically be willing to use
50 * ourself to answer a directory request.
51 * Passed to router_pick_directory_server (et al).*/
52#define PDS_ALLOW_SELF (1<<0)
53/** Flag to indicate that if no servers seem to be up, we should mark all
54 * directory servers as up and try again.
55 * Passed to router_pick_directory_server (et al).*/
56#define PDS_RETRY_IF_NO_SERVERS (1<<1)
57/** Flag to indicate that we should not exclude directory servers that
58 * our ReachableAddress settings would exclude. This usually means that
59 * we're going to connect to the server over Tor, and so we don't need to
60 * worry about our firewall telling us we can't.
61 * Passed to router_pick_directory_server (et al).*/
62#define PDS_IGNORE_FASCISTFIREWALL (1<<2)
63/** Flag to indicate that we should not use any directory authority to which
64 * we have an existing directory connection for downloading server descriptors
65 * or extrainfo documents.
66 *
67 * Passed to router_pick_directory_server (et al)
68 */
69#define PDS_NO_EXISTING_SERVERDESC_FETCH (1<<3)
70/** Flag to indicate that we should not use any directory authority to which
71 * we have an existing directory connection for downloading microdescs.
72 *
73 * Passed to router_pick_directory_server (et al)
74 */
75#define PDS_NO_EXISTING_MICRODESC_FETCH (1<<4)
76
78 int flags);
79
80int router_get_my_share_of_directory_requests(double *v3_share_out);
81
86 int for_direct_conn);
87const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
88 struct routerset_t *excludedset,
89 router_crn_flags_t flags);
90
92 int flags);
94 int flags);
95
96#ifdef NODE_SELECT_PRIVATE
97STATIC int choose_array_element_by_weight(const uint64_t *entries,
98 int n_entries);
99STATIC void scale_array_elements_to_u64(uint64_t *entries_out,
100 const double *entries_in,
101 int n_entries,
102 uint64_t *total_out);
104 dirinfo_type_t auth, int flags,
105 int *n_busy_out);
106STATIC int router_is_already_dir_fetching(const tor_addr_port_t *ap,
107 int serverdesc, int microdesc);
108#endif /* defined(NODE_SELECT_PRIVATE) */
109
110#endif /* !defined(TOR_NODE_SELECT_H) */
STATIC const routerstatus_t * router_pick_directory_server_impl(dirinfo_type_t type, int flags, int *n_busy_out)
Definition: node_select.c:297
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
router_crn_flags_t
Definition: node_select.h:16
const routerstatus_t * router_pick_directory_server(dirinfo_type_t type, int flags)
Definition: node_select.c:72
const routerstatus_t * router_pick_fallback_dirserver(dirinfo_type_t type, int flags)
Definition: node_select.c:1051
const routerstatus_t * router_pick_trusteddirserver(dirinfo_type_t type, int flags)
Definition: node_select.c:1040
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 node_t * router_choose_random_node(smartlist_t *excludedsmartlist, struct routerset_t *excludedset, router_crn_flags_t flags)
Definition: node_select.c:979
bandwidth_weight_rule_t
Definition: node_select.h:43
dirinfo_type_t
Definition: or.h:787
Definition: node_st.h:34
#define STATIC
Definition: testsupport.h:32