routerlist.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2010, 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(authority_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. smartlist_t *router_get_trusted_dir_servers(void);
  25. routerstatus_t *router_pick_directory_server(authority_type_t type, int flags);
  26. trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
  27. trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
  28. routerstatus_t *router_pick_trusteddirserver(authority_type_t type, int flags);
  29. int router_get_my_share_of_directory_requests(double *v2_share_out,
  30. double *v3_share_out);
  31. void router_reset_status_download_failures(void);
  32. void routerlist_add_family(smartlist_t *sl, routerinfo_t *router);
  33. int routers_in_same_family(routerinfo_t *r1, routerinfo_t *r2);
  34. void add_nickname_list_to_smartlist(smartlist_t *sl, const char *list,
  35. int must_be_running);
  36. int router_nickname_is_in_list(routerinfo_t *router, const char *list);
  37. routerinfo_t *routerlist_find_my_routerinfo(void);
  38. routerinfo_t *router_find_exact_exit_enclave(const char *address,
  39. uint16_t port);
  40. int router_is_unreliable(routerinfo_t *router, int need_uptime,
  41. int need_capacity, int need_guard);
  42. uint32_t router_get_advertised_bandwidth(routerinfo_t *router);
  43. uint32_t router_get_advertised_bandwidth_capped(routerinfo_t *router);
  44. routerinfo_t *routerlist_sl_choose_by_bandwidth(smartlist_t *sl,
  45. bandwidth_weight_rule_t rule);
  46. routerstatus_t *routerstatus_sl_choose_by_bandwidth(smartlist_t *sl,
  47. bandwidth_weight_rule_t rule);
  48. routerinfo_t *router_choose_random_node(smartlist_t *excludedsmartlist,
  49. struct routerset_t *excludedset,
  50. router_crn_flags_t flags);
  51. routerinfo_t *router_get_by_nickname(const char *nickname,
  52. int warn_if_unnamed);
  53. int router_digest_version_as_new_as(const char *digest, const char *cutoff);
  54. int router_digest_is_trusted_dir_type(const char *digest,
  55. authority_type_t type);
  56. #define router_digest_is_trusted_dir(d) \
  57. router_digest_is_trusted_dir_type((d), NO_AUTHORITY)
  58. int router_addr_is_trusted_dir(uint32_t addr);
  59. int hexdigest_to_digest(const char *hexdigest, char *digest);
  60. routerinfo_t *router_get_by_hexdigest(const char *hexdigest);
  61. routerinfo_t *router_get_by_digest(const char *digest);
  62. signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
  63. signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
  64. signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
  65. const char *signed_descriptor_get_body(signed_descriptor_t *desc);
  66. const char *signed_descriptor_get_annotations(signed_descriptor_t *desc);
  67. routerlist_t *router_get_routerlist(void);
  68. void routerinfo_free(routerinfo_t *router);
  69. void extrainfo_free(extrainfo_t *extrainfo);
  70. void routerlist_free(routerlist_t *rl);
  71. void dump_routerlist_mem_usage(int severity);
  72. void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
  73. time_t now);
  74. void routerlist_free_all(void);
  75. void routerlist_reset_warnings(void);
  76. void router_set_status(const char *digest, int up);
  77. static int WRA_WAS_ADDED(was_router_added_t s);
  78. static int WRA_WAS_OUTDATED(was_router_added_t s);
  79. static int WRA_WAS_REJECTED(was_router_added_t s);
  80. /** Return true iff the descriptor was added. It might still be necessary to
  81. * check whether the descriptor generator should be notified.
  82. */
  83. static INLINE int
  84. WRA_WAS_ADDED(was_router_added_t s) {
  85. return s == ROUTER_ADDED_SUCCESSFULLY || s == ROUTER_ADDED_NOTIFY_GENERATOR;
  86. }
  87. /** Return true iff the descriptor was not added because it was either:
  88. * - not in the consensus
  89. * - neither in the consensus nor in any networkstatus document
  90. * - it was outdated.
  91. */
  92. static INLINE int WRA_WAS_OUTDATED(was_router_added_t s)
  93. {
  94. return (s == ROUTER_WAS_NOT_NEW ||
  95. s == ROUTER_NOT_IN_CONSENSUS ||
  96. s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS);
  97. }
  98. static INLINE int WRA_WAS_REJECTED(was_router_added_t s)
  99. {
  100. return (s == ROUTER_AUTHDIR_REJECTS);
  101. }
  102. was_router_added_t router_add_to_routerlist(routerinfo_t *router,
  103. const char **msg,
  104. int from_cache,
  105. int from_fetch);
  106. was_router_added_t router_add_extrainfo_to_routerlist(
  107. extrainfo_t *ei, const char **msg,
  108. int from_cache, int from_fetch);
  109. void routerlist_remove_old_routers(void);
  110. int router_load_single_router(const char *s, uint8_t purpose, int cache,
  111. const char **msg);
  112. int router_load_routers_from_string(const char *s, const char *eos,
  113. saved_location_t saved_location,
  114. smartlist_t *requested_fingerprints,
  115. int descriptor_digests,
  116. const char *prepend_annotations);
  117. void router_load_extrainfo_from_string(const char *s, const char *eos,
  118. saved_location_t saved_location,
  119. smartlist_t *requested_fingerprints,
  120. int descriptor_digests);
  121. void routerlist_retry_directory_downloads(time_t now);
  122. int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port,
  123. int need_uptime);
  124. int router_exit_policy_rejects_all(routerinfo_t *router);
  125. trusted_dir_server_t *add_trusted_dir_server(const char *nickname,
  126. const char *address,
  127. uint16_t dir_port, uint16_t or_port,
  128. const char *digest, const char *v3_auth_digest,
  129. authority_type_t type);
  130. void authority_cert_free(authority_cert_t *cert);
  131. void clear_trusted_dir_servers(void);
  132. int any_trusted_dir_is_v1_authority(void);
  133. void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
  134. networkstatus_t *consensus);
  135. void update_router_descriptor_downloads(time_t now);
  136. void update_extrainfo_downloads(time_t now);
  137. int router_have_minimum_dir_info(void);
  138. void router_dir_info_changed(void);
  139. const char *get_dir_info_status_string(void);
  140. int count_loading_descriptors_progress(void);
  141. void router_reset_descriptor_download_failures(void);
  142. int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2);
  143. int routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei,
  144. signed_descriptor_t *sd,
  145. const char **msg);
  146. void routerlist_assert_ok(routerlist_t *rl);
  147. const char *esc_router_info(routerinfo_t *router);
  148. void routers_sort_by_identity(smartlist_t *routers);
  149. routerset_t *routerset_new(void);
  150. int routerset_parse(routerset_t *target, const char *s,
  151. const char *description);
  152. void routerset_union(routerset_t *target, const routerset_t *source);
  153. int routerset_is_list(const routerset_t *set);
  154. int routerset_needs_geoip(const routerset_t *set);
  155. int routerset_contains_router(const routerset_t *set, routerinfo_t *ri);
  156. int routerset_contains_routerstatus(const routerset_t *set,
  157. routerstatus_t *rs);
  158. int routerset_contains_extendinfo(const routerset_t *set,
  159. const extend_info_t *ei);
  160. void routerset_get_all_routers(smartlist_t *out, const routerset_t *routerset,
  161. int running_only);
  162. void routersets_get_disjunction(smartlist_t *target, const smartlist_t *source,
  163. const routerset_t *include,
  164. const routerset_t *exclude, int running_only);
  165. void routerset_subtract_routers(smartlist_t *out,
  166. const routerset_t *routerset);
  167. char *routerset_to_string(const routerset_t *routerset);
  168. void routerset_refresh_countries(routerset_t *target);
  169. int routerset_equal(const routerset_t *old, const routerset_t *new);
  170. void routerset_free(routerset_t *routerset);
  171. void routerinfo_set_country(routerinfo_t *ri);
  172. void routerlist_refresh_countries(void);
  173. void refresh_all_country_info(void);
  174. int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
  175. const char *id);
  176. int hid_serv_acting_as_directory(void);
  177. int hid_serv_responsible_for_desc_id(const char *id);
  178. #endif