routerlist.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. /*
  14. * Pass one of these as source to trusted_dirs_load_certs_from_string()
  15. * to indicate whence string originates; this controls error handling
  16. * behavior such as marking downloads as failed.
  17. */
  18. #define TRUSTED_DIRS_CERTS_SRC_SELF 0
  19. #define TRUSTED_DIRS_CERTS_SRC_FROM_STORE 1
  20. #define TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST 2
  21. #define TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_SK_DIGEST 3
  22. #define TRUSTED_DIRS_CERTS_SRC_FROM_VOTE 4
  23. int trusted_dirs_load_certs_from_string(const char *contents, int source,
  24. int flush);
  25. void trusted_dirs_flush_certs_to_disk(void);
  26. authority_cert_t *authority_cert_get_newest_by_id(const char *id_digest);
  27. authority_cert_t *authority_cert_get_by_sk_digest(const char *sk_digest);
  28. authority_cert_t *authority_cert_get_by_digests(const char *id_digest,
  29. const char *sk_digest);
  30. void authority_cert_get_all(smartlist_t *certs_out);
  31. void authority_cert_dl_failed(const char *id_digest,
  32. const char *signing_key_digest, int status);
  33. void authority_certs_fetch_missing(networkstatus_t *status, time_t now);
  34. int router_reload_router_list(void);
  35. int authority_cert_dl_looks_uncertain(const char *id_digest);
  36. smartlist_t *router_get_trusted_dir_servers(void);
  37. const routerstatus_t *router_pick_directory_server(dirinfo_type_t type,
  38. int flags);
  39. trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
  40. trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
  41. const routerstatus_t *router_pick_trusteddirserver(dirinfo_type_t type,
  42. int flags);
  43. int router_get_my_share_of_directory_requests(double *v2_share_out,
  44. double *v3_share_out);
  45. void router_reset_status_download_failures(void);
  46. int routers_have_same_or_addr(const routerinfo_t *r1, const routerinfo_t *r2);
  47. int router_nickname_is_in_list(const routerinfo_t *router, const char *list);
  48. const routerinfo_t *routerlist_find_my_routerinfo(void);
  49. const node_t *router_find_exact_exit_enclave(const char *address,
  50. uint16_t port);
  51. int node_is_unreliable(const node_t *router, int need_uptime,
  52. int need_capacity, int need_guard);
  53. uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
  54. uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router);
  55. const node_t *node_sl_choose_by_bandwidth(smartlist_t *sl,
  56. bandwidth_weight_rule_t rule);
  57. const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
  58. struct routerset_t *excludedset,
  59. router_crn_flags_t flags);
  60. const routerinfo_t *router_get_by_nickname(const char *nickname,
  61. int warn_if_unnamed);
  62. int router_is_named(const routerinfo_t *router);
  63. int router_digest_is_trusted_dir_type(const char *digest,
  64. dirinfo_type_t type);
  65. #define router_digest_is_trusted_dir(d) \
  66. router_digest_is_trusted_dir_type((d), NO_DIRINFO)
  67. int router_addr_is_trusted_dir(uint32_t addr);
  68. int hexdigest_to_digest(const char *hexdigest, char *digest);
  69. const routerinfo_t *router_get_by_hexdigest(const char *hexdigest);
  70. const routerinfo_t *router_get_by_id_digest(const char *digest);
  71. routerinfo_t *router_get_mutable_by_digest(const char *digest);
  72. signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
  73. signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
  74. signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
  75. const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
  76. const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
  77. routerlist_t *router_get_routerlist(void);
  78. void routerinfo_free(routerinfo_t *router);
  79. void extrainfo_free(extrainfo_t *extrainfo);
  80. void routerlist_free(routerlist_t *rl);
  81. void dump_routerlist_mem_usage(int severity);
  82. void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
  83. time_t now);
  84. void routerlist_free_all(void);
  85. void routerlist_reset_warnings(void);
  86. void router_set_status(const char *digest, int up);
  87. static int WRA_WAS_ADDED(was_router_added_t s);
  88. static int WRA_WAS_OUTDATED(was_router_added_t s);
  89. static int WRA_WAS_REJECTED(was_router_added_t s);
  90. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  91. * was added. It might still be necessary to check whether the descriptor
  92. * generator should be notified.
  93. */
  94. static INLINE int
  95. WRA_WAS_ADDED(was_router_added_t s) {
  96. return s == ROUTER_ADDED_SUCCESSFULLY || s == ROUTER_ADDED_NOTIFY_GENERATOR;
  97. }
  98. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  99. * was not added because it was either:
  100. * - not in the consensus
  101. * - neither in the consensus nor in any networkstatus document
  102. * - it was outdated.
  103. */
  104. static INLINE int WRA_WAS_OUTDATED(was_router_added_t s)
  105. {
  106. return (s == ROUTER_WAS_NOT_NEW ||
  107. s == ROUTER_NOT_IN_CONSENSUS ||
  108. s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS);
  109. }
  110. /** Return true iff the outcome code in <b>s</b> indicates that the descriptor
  111. * was flat-out rejected. */
  112. static INLINE int WRA_WAS_REJECTED(was_router_added_t s)
  113. {
  114. return (s == ROUTER_AUTHDIR_REJECTS);
  115. }
  116. was_router_added_t router_add_to_routerlist(routerinfo_t *router,
  117. const char **msg,
  118. int from_cache,
  119. int from_fetch);
  120. was_router_added_t router_add_extrainfo_to_routerlist(
  121. extrainfo_t *ei, const char **msg,
  122. int from_cache, int from_fetch);
  123. void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
  124. void routerlist_remove_old_routers(void);
  125. int router_load_single_router(const char *s, uint8_t purpose, int cache,
  126. const char **msg);
  127. int router_load_routers_from_string(const char *s, const char *eos,
  128. saved_location_t saved_location,
  129. smartlist_t *requested_fingerprints,
  130. int descriptor_digests,
  131. const char *prepend_annotations);
  132. void router_load_extrainfo_from_string(const char *s, const char *eos,
  133. saved_location_t saved_location,
  134. smartlist_t *requested_fingerprints,
  135. int descriptor_digests);
  136. void routerlist_retry_directory_downloads(time_t now);
  137. int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
  138. int need_uptime);
  139. int router_exit_policy_rejects_all(const routerinfo_t *router);
  140. trusted_dir_server_t *add_trusted_dir_server(const char *nickname,
  141. const char *address,
  142. uint16_t dir_port, uint16_t or_port,
  143. const char *digest, const char *v3_auth_digest,
  144. dirinfo_type_t type);
  145. void authority_cert_free(authority_cert_t *cert);
  146. void clear_trusted_dir_servers(void);
  147. int any_trusted_dir_is_v1_authority(void);
  148. void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
  149. networkstatus_t *consensus);
  150. void update_router_descriptor_downloads(time_t now);
  151. void update_all_descriptor_downloads(time_t now);
  152. void update_extrainfo_downloads(time_t now);
  153. int router_have_minimum_dir_info(void);
  154. void router_dir_info_changed(void);
  155. const char *get_dir_info_status_string(void);
  156. int count_loading_descriptors_progress(void);
  157. void router_reset_descriptor_download_failures(void);
  158. int router_differences_are_cosmetic(const routerinfo_t *r1,
  159. const routerinfo_t *r2);
  160. int routerinfo_incompatible_with_extrainfo(const routerinfo_t *ri,
  161. extrainfo_t *ei,
  162. signed_descriptor_t *sd,
  163. const char **msg);
  164. void routerlist_assert_ok(const routerlist_t *rl);
  165. const char *esc_router_info(const routerinfo_t *router);
  166. void routers_sort_by_identity(smartlist_t *routers);
  167. routerset_t *routerset_new(void);
  168. void routerset_refresh_countries(routerset_t *rs);
  169. int routerset_parse(routerset_t *target, const char *s,
  170. const char *description);
  171. void routerset_union(routerset_t *target, const routerset_t *source);
  172. int routerset_is_list(const routerset_t *set);
  173. int routerset_needs_geoip(const routerset_t *set);
  174. int routerset_is_empty(const routerset_t *set);
  175. int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri,
  176. country_t country);
  177. int routerset_contains_routerstatus(const routerset_t *set,
  178. const routerstatus_t *rs,
  179. country_t country);
  180. int routerset_contains_extendinfo(const routerset_t *set,
  181. const extend_info_t *ei);
  182. int routerset_contains_node(const routerset_t *set, const node_t *node);
  183. void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset,
  184. const routerset_t *excludeset,
  185. int running_only);
  186. #if 0
  187. void routersets_get_node_disjunction(smartlist_t *target,
  188. const smartlist_t *source,
  189. const routerset_t *include,
  190. const routerset_t *exclude, int running_only);
  191. #endif
  192. void routerset_subtract_nodes(smartlist_t *out,
  193. const routerset_t *routerset);
  194. char *routerset_to_string(const routerset_t *routerset);
  195. int routerset_equal(const routerset_t *old, const routerset_t *new);
  196. void routerset_free(routerset_t *routerset);
  197. void refresh_all_country_info(void);
  198. int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
  199. const char *id);
  200. int hid_serv_acting_as_directory(void);
  201. int hid_serv_responsible_for_desc_id(const char *id);
  202. void list_pending_microdesc_downloads(digestmap_t *result);
  203. void launch_descriptor_downloads(int purpose,
  204. smartlist_t *downloadable,
  205. const routerstatus_t *source,
  206. time_t now);
  207. int hex_digest_nickname_decode(const char *hexdigest,
  208. char *digest_out,
  209. char *nickname_qualifier_out,
  210. char *nickname_out);
  211. #endif