networkstatus.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file networkstatus.h
  8. * \brief Header file for networkstatus.c.
  9. **/
  10. #ifndef TOR_NETWORKSTATUS_H
  11. #define TOR_NETWORKSTATUS_H
  12. #include "lib/testsupport/testsupport.h"
  13. void networkstatus_reset_warnings(void);
  14. void networkstatus_reset_download_failures(void);
  15. char *networkstatus_read_cached_consensus(const char *flavorname);
  16. int router_reload_consensus_networkstatus(void);
  17. void routerstatus_free_(routerstatus_t *rs);
  18. #define routerstatus_free(rs) \
  19. FREE_AND_NULL(routerstatus_t, routerstatus_free_, (rs))
  20. void networkstatus_vote_free_(networkstatus_t *ns);
  21. #define networkstatus_vote_free(ns) \
  22. FREE_AND_NULL(networkstatus_t, networkstatus_vote_free_, (ns))
  23. void ns_detached_signatures_free_(ns_detached_signatures_t *s);
  24. #define ns_detached_signatures_free(s) \
  25. FREE_AND_NULL(ns_detached_signatures_t, ns_detached_signatures_free_, (s))
  26. networkstatus_voter_info_t *networkstatus_get_voter_by_id(
  27. networkstatus_t *vote,
  28. const char *identity);
  29. document_signature_t *networkstatus_get_voter_sig_by_alg(
  30. const networkstatus_voter_info_t *voter,
  31. digest_algorithm_t alg);
  32. int networkstatus_check_consensus_signature(networkstatus_t *consensus,
  33. int warn);
  34. int networkstatus_check_document_signature(const networkstatus_t *consensus,
  35. document_signature_t *sig,
  36. const authority_cert_t *cert);
  37. int compare_digest_to_routerstatus_entry(const void *_key,
  38. const void **_member);
  39. int compare_digest_to_vote_routerstatus_entry(const void *_key,
  40. const void **_member);
  41. const routerstatus_t *networkstatus_vote_find_entry(networkstatus_t *ns,
  42. const char *digest);
  43. routerstatus_t *networkstatus_vote_find_mutable_entry(networkstatus_t *ns,
  44. const char *digest);
  45. int networkstatus_vote_find_entry_idx(networkstatus_t *ns,
  46. const char *digest, int *found_out);
  47. MOCK_DECL(download_status_t *,
  48. networkstatus_get_dl_status_by_flavor,
  49. (consensus_flavor_t flavor));
  50. MOCK_DECL(download_status_t *,
  51. networkstatus_get_dl_status_by_flavor_bootstrap,
  52. (consensus_flavor_t flavor));
  53. MOCK_DECL(download_status_t *,
  54. networkstatus_get_dl_status_by_flavor_running,
  55. (consensus_flavor_t flavor));
  56. MOCK_DECL(smartlist_t *, router_get_descriptor_digests, (void));
  57. MOCK_DECL(download_status_t *,router_get_dl_status_by_descriptor_digest,
  58. (const char *d));
  59. const routerstatus_t *router_get_consensus_status_by_id(const char *digest);
  60. routerstatus_t *router_get_mutable_consensus_status_by_id(
  61. const char *digest);
  62. const routerstatus_t *router_get_consensus_status_by_descriptor_digest(
  63. networkstatus_t *consensus,
  64. const char *digest);
  65. MOCK_DECL(routerstatus_t *,
  66. router_get_mutable_consensus_status_by_descriptor_digest,
  67. (networkstatus_t *consensus, const char *digest));
  68. int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
  69. int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
  70. void networkstatus_consensus_download_failed(int status_code,
  71. const char *flavname);
  72. void update_consensus_networkstatus_fetch_time(time_t now);
  73. int should_delay_dir_fetches(const or_options_t *options,const char **msg_out);
  74. void update_networkstatus_downloads(time_t now);
  75. void update_certificate_downloads(time_t now);
  76. int consensus_is_waiting_for_certs(void);
  77. int client_would_use_router(const routerstatus_t *rs, time_t now);
  78. MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus,(void));
  79. MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus_by_flavor,
  80. (consensus_flavor_t f));
  81. MOCK_DECL(networkstatus_t *, networkstatus_get_live_consensus,(time_t now));
  82. int networkstatus_is_live(const networkstatus_t *ns, time_t now);
  83. int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus,
  84. time_t now);
  85. int networkstatus_valid_until_is_reasonably_live(time_t valid_until,
  86. time_t now);
  87. networkstatus_t *networkstatus_get_reasonably_live_consensus(time_t now,
  88. int flavor);
  89. MOCK_DECL(int, networkstatus_consensus_is_bootstrapping,(time_t now));
  90. int networkstatus_consensus_can_use_multiple_directories(
  91. const or_options_t *options);
  92. MOCK_DECL(int, networkstatus_consensus_can_use_extra_fallbacks,(
  93. const or_options_t *options));
  94. int networkstatus_consensus_is_already_downloading(const char *resource);
  95. int networkstatus_consensus_has_ipv6(const or_options_t* options);
  96. #define NSSET_FROM_CACHE 1
  97. #define NSSET_WAS_WAITING_FOR_CERTS 2
  98. #define NSSET_DONT_DOWNLOAD_CERTS 4
  99. #define NSSET_ACCEPT_OBSOLETE 8
  100. #define NSSET_REQUIRE_FLAVOR 16
  101. int networkstatus_set_current_consensus(const char *consensus,
  102. const char *flavor,
  103. unsigned flags,
  104. const char *source_dir);
  105. void networkstatus_note_certs_arrived(const char *source_dir);
  106. void routers_update_all_from_networkstatus(time_t now, int dir_version);
  107. void routers_update_status_from_consensus_networkstatus(smartlist_t *routers,
  108. int reset_failures);
  109. void signed_descs_update_status_from_consensus_networkstatus(
  110. smartlist_t *descs);
  111. char *networkstatus_getinfo_helper_single(const routerstatus_t *rs);
  112. char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now);
  113. void networkstatus_dump_bridge_status_to_file(time_t now);
  114. MOCK_DECL(int32_t, networkstatus_get_param,
  115. (const networkstatus_t *ns, const char *param_name,
  116. int32_t default_val, int32_t min_val, int32_t max_val));
  117. int32_t networkstatus_get_overridable_param(const networkstatus_t *ns,
  118. int32_t torrc_value,
  119. const char *param_name,
  120. int32_t default_val,
  121. int32_t min_val, int32_t max_val);
  122. int getinfo_helper_networkstatus(control_connection_t *conn,
  123. const char *question, char **answer,
  124. const char **errmsg);
  125. int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight,
  126. int32_t default_val);
  127. const char *networkstatus_get_flavor_name(consensus_flavor_t flav);
  128. int networkstatus_parse_flavor_name(const char *flavname);
  129. void document_signature_free_(document_signature_t *sig);
  130. #define document_signature_free(sig) \
  131. FREE_AND_NULL(document_signature_t, document_signature_free_, (sig))
  132. document_signature_t *document_signature_dup(const document_signature_t *sig);
  133. void networkstatus_free_all(void);
  134. int networkstatus_get_weight_scale_param(networkstatus_t *ns);
  135. void vote_routerstatus_free_(vote_routerstatus_t *rs);
  136. #define vote_routerstatus_free(rs) \
  137. FREE_AND_NULL(vote_routerstatus_t, vote_routerstatus_free_, (rs))
  138. #ifdef NETWORKSTATUS_PRIVATE
  139. #ifdef TOR_UNIT_TESTS
  140. STATIC int networkstatus_set_current_consensus_from_ns(networkstatus_t *c,
  141. const char *flavor);
  142. STATIC void warn_early_consensus(const networkstatus_t *c, const char *flavor,
  143. time_t now);
  144. extern networkstatus_t *current_ns_consensus;
  145. extern networkstatus_t *current_md_consensus;
  146. #endif /* defined(TOR_UNIT_TESTS) */
  147. #endif /* defined(NETWORKSTATUS_PRIVATE) */
  148. #endif /* !defined(TOR_NETWORKSTATUS_H) */