tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

node_select.h (5051B)


      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, indicate that we need a HS related circuit (IP, HSDir, or RP).
     33   * This is used in order to avoid certain nodes for these purposes. */
     34  CRN_FOR_HS = 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,
     39 } router_crn_flags_t;
     40 
     41 /** Possible ways to weight routers when choosing one randomly.  See
     42 * routerlist_sl_choose_by_bandwidth() for more information.*/
     43 typedef enum bandwidth_weight_rule_t {
     44  NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
     45  WEIGHT_FOR_DIR
     46 } bandwidth_weight_rule_t;
     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 
     77 const routerstatus_t *router_pick_directory_server(dirinfo_type_t type,
     78                                                   int flags);
     79 
     80 int router_get_my_share_of_directory_requests(double *v3_share_out);
     81 
     82 const node_t *node_sl_choose_by_bandwidth(const smartlist_t *sl,
     83                                          bandwidth_weight_rule_t rule);
     84 double frac_nodes_with_descriptors(const smartlist_t *sl,
     85                                   bandwidth_weight_rule_t rule,
     86                                   int for_direct_conn);
     87 const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
     88                                        struct routerset_t *excludedset,
     89                                        router_crn_flags_t flags);
     90 
     91 const routerstatus_t *router_pick_trusteddirserver(dirinfo_type_t type,
     92                                                   int flags);
     93 const routerstatus_t *router_pick_fallback_dirserver(dirinfo_type_t type,
     94                                                     int flags);
     95 
     96 #ifdef NODE_SELECT_PRIVATE
     97 STATIC int choose_array_element_by_weight(const uint64_t *entries,
     98                                          int n_entries);
     99 STATIC void scale_array_elements_to_u64(uint64_t *entries_out,
    100                                        const double *entries_in,
    101                                        int n_entries,
    102                                        uint64_t *total_out);
    103 STATIC const routerstatus_t *router_pick_directory_server_impl(
    104                                           dirinfo_type_t auth, int flags,
    105                                           int *n_busy_out);
    106 STATIC 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) */