node_select.h 4.4 KB

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