routerlist.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2012, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file routerlist.h
  7. * \brief Header file for routerlist.c.
  8. **/
  9. #ifndef TOR_ROUTERLIST_H
  10. #define TOR_ROUTERLIST_H
  11. int get_n_authorities(dirinfo_type_t type);
  12. int trusted_dirs_reload_certs(void);
  13. int trusted_dirs_load_certs_from_string(const char *contents, int from_store,
  14. int flush);
  15. void trusted_dirs_flush_certs_to_disk(void);
  16. authority_cert_t *authority_cert_get_newest_by_id(const char *id_digest);
  17. authority_cert_t *authority_cert_get_by_sk_digest(const char *sk_digest);
  18. authority_cert_t *authority_cert_get_by_digests(const char *id_digest,
  19. const char *sk_digest);
  20. void authority_cert_get_all(smartlist_t *certs_out);
  21. void authority_cert_dl_failed(const char *id_digest, int status);
  22. void authority_certs_fetch_missing(networkstatus_t *status, time_t now);
  23. int router_reload_router_list(void);
  24. int authority_cert_dl_looks_uncertain(const char *id_digest);
  25. smartlist_t *router_get_trusted_dir_servers(void);
  26. const routerstatus_t *router_pick_directory_server(dirinfo_type_t type,
  27. int flags);
  28. trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
  29. trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
  30. const routerstatus_t *router_pick_trusteddirserver(dirinfo_type_t type,
  31. int flags);
  32. int router_get_my_share_of_directory_requests(double *v2_share_out,
  33. double *v3_share_out);
  34. void router_reset_status_download_failures(void);
  35. int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2);
  36. int router_nickname_is_in_list(const routerinfo_t *router, const char *list);
  37. const routerinfo_t *routerlist_find_my_routerinfo(void);
  38. uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
  39. uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router);
  40. const node_t *node_sl_choose_by_bandwidth(smartlist_t *sl,
  41. bandwidth_weight_rule_t rule);
  42. const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
  43. struct routerset_t *excludedset,
  44. router_crn_flags_t flags);
  45. int router_is_named(const routerinfo_t *router);
  46. int router_digest_is_trusted_dir_type(const char *digest,
  47. dirinfo_type_t type);
  48. #define router_digest_is_trusted_dir(d) \
  49. router_digest_is_trusted_dir_type((d), NO_DIRINFO)
  50. int router_addr_is_trusted_dir(uint32_t addr);
  51. int hexdigest_to_digest(const char *hexdigest, char *digest);
  52. const routerinfo_t *router_get_by_id_digest(const char *digest);
  53. routerinfo_t *router_get_mutable_by_digest(const char *digest);
  54. signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
  55. signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
  56. signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
  57. const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
  58. const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
  59. routerlist_t *router_get_routerlist(void);
  60. void routerinfo_free(routerinfo_t *router);
  61. void extrainfo_free(extrainfo_t *extrainfo);
  62. void routerlist_free(routerlist_t *rl);
  63. void dump_routerlist_mem_usage(int severity);
  64. void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
  65. time_t now);
  66. void routerlist_free_all(void);
  67. void routerlist_reset_warnings(void);
  68. static int WRA_WAS_ADDED(was_router_added_t s);
  69. static int WRA_WAS_OUTDATED(was_router_added_t s);
  70. static int WRA_WAS_REJECTED(was_router_added_t s);
  71. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  72. * was added. It might still be necessary to check whether the descriptor
  73. * generator should be notified.
  74. */
  75. static INLINE int
  76. WRA_WAS_ADDED(was_router_added_t s) {
  77. return s == ROUTER_ADDED_SUCCESSFULLY || s == ROUTER_ADDED_NOTIFY_GENERATOR;
  78. }
  79. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  80. * was not added because it was either:
  81. * - not in the consensus
  82. * - neither in the consensus nor in any networkstatus document
  83. * - it was outdated.
  84. */
  85. static INLINE int WRA_WAS_OUTDATED(was_router_added_t s)
  86. {
  87. return (s == ROUTER_WAS_NOT_NEW ||
  88. s == ROUTER_NOT_IN_CONSENSUS ||
  89. s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS);
  90. }
  91. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  92. * was flat-out rejected. */
  93. static INLINE int WRA_WAS_REJECTED(was_router_added_t s)
  94. {
  95. return (s == ROUTER_AUTHDIR_REJECTS);
  96. }
  97. was_router_added_t router_add_to_routerlist(routerinfo_t *router,
  98. const char **msg,
  99. int from_cache,
  100. int from_fetch);
  101. was_router_added_t router_add_extrainfo_to_routerlist(
  102. extrainfo_t *ei, const char **msg,
  103. int from_cache, int from_fetch);
  104. void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
  105. void routerlist_remove_old_routers(void);
  106. int router_load_single_router(const char *s, uint8_t purpose, int cache,
  107. const char **msg);
  108. int router_load_routers_from_string(const char *s, const char *eos,
  109. saved_location_t saved_location,
  110. smartlist_t *requested_fingerprints,
  111. int descriptor_digests,
  112. const char *prepend_annotations);
  113. void router_load_extrainfo_from_string(const char *s, const char *eos,
  114. saved_location_t saved_location,
  115. smartlist_t *requested_fingerprints,
  116. int descriptor_digests);
  117. void routerlist_retry_directory_downloads(time_t now);
  118. int router_exit_policy_rejects_all(const routerinfo_t *router);
  119. trusted_dir_server_t *add_trusted_dir_server(const char *nickname,
  120. const char *address,
  121. uint16_t dir_port, uint16_t or_port,
  122. const char *digest, const char *v3_auth_digest,
  123. dirinfo_type_t type);
  124. void authority_cert_free(authority_cert_t *cert);
  125. void clear_trusted_dir_servers(void);
  126. int any_trusted_dir_is_v1_authority(void);
  127. void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
  128. networkstatus_t *consensus);
  129. void update_router_descriptor_downloads(time_t now);
  130. void update_all_descriptor_downloads(time_t now);
  131. void update_extrainfo_downloads(time_t now);
  132. void router_reset_descriptor_download_failures(void);
  133. int router_differences_are_cosmetic(const routerinfo_t *r1,
  134. const routerinfo_t *r2);
  135. int routerinfo_incompatible_with_extrainfo(const routerinfo_t *ri,
  136. extrainfo_t *ei,
  137. signed_descriptor_t *sd,
  138. const char **msg);
  139. void routerlist_assert_ok(const routerlist_t *rl);
  140. const char *esc_router_info(const routerinfo_t *router);
  141. void routers_sort_by_identity(smartlist_t *routers);
  142. void refresh_all_country_info(void);
  143. int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
  144. const char *id);
  145. int hid_serv_acting_as_directory(void);
  146. int hid_serv_responsible_for_desc_id(const char *id);
  147. void list_pending_microdesc_downloads(digestmap_t *result);
  148. void launch_descriptor_downloads(int purpose,
  149. smartlist_t *downloadable,
  150. const routerstatus_t *source,
  151. time_t now);
  152. int hex_digest_nickname_decode(const char *hexdigest,
  153. char *digest_out,
  154. char *nickname_qualifier_out,
  155. char *nickname_out);
  156. int hex_digest_nickname_matches(const char *hexdigest,
  157. const char *identity_digest,
  158. const char *nickname, int is_named);
  159. #ifdef ROUTERLIST_PRIVATE
  160. /** Helper type for choosing routers by bandwidth: contains a union of
  161. * double and uint64_t. Before we call scale_array_elements_to_u64, it holds
  162. * a double; after, it holds a uint64_t. */
  163. typedef union u64_dbl_t {
  164. uint64_t u64;
  165. double dbl;
  166. } u64_dbl_t;
  167. int choose_array_element_by_weight(const u64_dbl_t *entries, int n_entries);
  168. void scale_array_elements_to_u64(u64_dbl_t *entries, int n_entries,
  169. uint64_t *total_out);
  170. #endif
  171. #endif