dirserv.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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-2016, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file dirserv.h
  8. * \brief Header file for dirserv.c.
  9. **/
  10. #ifndef TOR_DIRSERV_H
  11. #define TOR_DIRSERV_H
  12. #include "testsupport.h"
  13. /** What fraction (1 over this number) of the relay ID space do we
  14. * (as a directory authority) launch connections to at each reachability
  15. * test? */
  16. #define REACHABILITY_MODULO_PER_TEST 128
  17. /** How often (in seconds) do we launch reachability tests? */
  18. #define REACHABILITY_TEST_INTERVAL 10
  19. /** How many seconds apart are the reachability tests for a given relay? */
  20. #define REACHABILITY_TEST_CYCLE_PERIOD \
  21. (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST)
  22. /** Maximum length of an exit policy summary. */
  23. #define MAX_EXITPOLICY_SUMMARY_LEN 1000
  24. /** Maximum allowable length of a version line in a networkstatus. */
  25. #define MAX_V_LINE_LEN 128
  26. int connection_dirserv_flushed_some(dir_connection_t *conn);
  27. int dirserv_add_own_fingerprint(crypto_pk_t *pk);
  28. int dirserv_load_fingerprint_file(void);
  29. void dirserv_free_fingerprint_list(void);
  30. enum was_router_added_t dirserv_add_multiple_descriptors(
  31. const char *desc, uint8_t purpose,
  32. const char *source,
  33. const char **msg);
  34. enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
  35. const char **msg,
  36. const char *source);
  37. void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
  38. int list_server_status_v1(smartlist_t *routers, char **router_status_out,
  39. int for_controller);
  40. char *dirserv_get_flag_thresholds_line(void);
  41. void dirserv_compute_bridge_flag_thresholds(void);
  42. int directory_fetches_from_authorities(const or_options_t *options);
  43. int directory_fetches_dir_info_early(const or_options_t *options);
  44. int directory_fetches_dir_info_later(const or_options_t *options);
  45. int directory_caches_unknown_auth_certs(const or_options_t *options);
  46. int directory_caches_dir_info(const or_options_t *options);
  47. int directory_permits_begindir_requests(const or_options_t *options);
  48. int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
  49. time_t now);
  50. cached_dir_t *dirserv_get_consensus(const char *flavor_name);
  51. void dirserv_set_cached_consensus_networkstatus(const char *consensus,
  52. const char *flavor_name,
  53. const common_digests_t *digests,
  54. time_t published);
  55. void dirserv_clear_old_networkstatuses(time_t cutoff);
  56. int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
  57. const char **msg,
  58. int for_unencrypted_conn,
  59. int is_extrainfo);
  60. int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
  61. const char **msg);
  62. void dirserv_orconn_tls_done(const tor_addr_t *addr,
  63. uint16_t or_port,
  64. const char *digest_rcvd);
  65. int dirserv_should_launch_reachability_test(const routerinfo_t *ri,
  66. const routerinfo_t *ri_old);
  67. void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
  68. void dirserv_test_reachability(time_t now);
  69. int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
  70. int complain,
  71. int *valid_out);
  72. uint32_t dirserv_router_get_status(const routerinfo_t *router,
  73. const char **msg,
  74. int severity);
  75. void dirserv_set_node_flags_from_authoritative_status(node_t *node,
  76. uint32_t authstatus);
  77. int dirserv_would_reject_router(const routerstatus_t *rs);
  78. int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
  79. int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
  80. int dirserv_have_any_microdesc(const smartlist_t *fps);
  81. size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
  82. int compressed);
  83. size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
  84. char *routerstatus_format_entry(
  85. const routerstatus_t *rs,
  86. const char *version,
  87. const char *protocols,
  88. routerstatus_format_type_t format,
  89. const vote_routerstatus_t *vrs);
  90. void dirserv_free_all(void);
  91. void cached_dir_decref(cached_dir_t *d);
  92. cached_dir_t *new_cached_dir(char *s, time_t published);
  93. int validate_recommended_package_line(const char *line);
  94. #ifdef DIRSERV_PRIVATE
  95. STATIC void dirserv_set_routerstatus_testing(routerstatus_t *rs);
  96. /* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */
  97. #define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */
  98. STATIC int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
  99. STATIC int measured_bw_line_apply(measured_bw_line_t *parsed_line,
  100. smartlist_t *routerstatuses);
  101. STATIC void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line,
  102. time_t as_of);
  103. STATIC void dirserv_clear_measured_bw_cache(void);
  104. STATIC void dirserv_expire_measured_bw_cache(time_t now);
  105. STATIC int dirserv_get_measured_bw_cache_size(void);
  106. STATIC int dirserv_query_measured_bw_cache_kb(const char *node_id,
  107. long *bw_out,
  108. time_t *as_of_out);
  109. STATIC int dirserv_has_measured_bw(const char *node_id);
  110. STATIC int
  111. dirserv_read_guardfraction_file_from_str(const char *guardfraction_file_str,
  112. smartlist_t *vote_routerstatuses);
  113. #endif
  114. int dirserv_read_measured_bandwidths(const char *from_file,
  115. smartlist_t *routerstatuses);
  116. int dirserv_read_guardfraction_file(const char *fname,
  117. smartlist_t *vote_routerstatuses);
  118. #endif