dirserv.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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-2012, 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. /** What fraction (1 over this number) of the relay ID space do we
  13. * (as a directory authority) launch connections to at each reachability
  14. * test? */
  15. #define REACHABILITY_MODULO_PER_TEST 128
  16. /** How often (in seconds) do we launch reachability tests? */
  17. #define REACHABILITY_TEST_INTERVAL 10
  18. /** How many seconds apart are the reachability tests for a given relay? */
  19. #define REACHABILITY_TEST_CYCLE_PERIOD \
  20. (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST)
  21. /** Maximum length of an exit policy summary. */
  22. #define MAX_EXITPOLICY_SUMMARY_LEN 1000
  23. /** Maximum allowable length of a version line in a networkstatus. */
  24. #define MAX_V_LINE_LEN 128
  25. /** Length of "r Authority BadDirectory BadExit Exit Fast Guard HSDir Named
  26. * Running Stable Unnamed V2Dir Valid\n". */
  27. #define MAX_FLAG_LINE_LEN 96
  28. /** Length of "w" line for weighting. Currently at most
  29. * "w Bandwidth=<uint32t> Measured=<uint32t>\n" */
  30. #define MAX_WEIGHT_LINE_LEN (12+10+10+10+1)
  31. /** Maximum length of an exit policy summary line. */
  32. #define MAX_POLICY_LINE_LEN (3+MAX_EXITPOLICY_SUMMARY_LEN)
  33. /** Amount of space to allocate for each entry: r, s, and v lines. */
  34. #define RS_ENTRY_LEN \
  35. ( /* first line */ \
  36. MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
  37. 5*2 /* ports */ + 10 /* punctuation */ + \
  38. /* second line */ \
  39. MAX_FLAG_LINE_LEN + \
  40. /* weight line */ \
  41. MAX_WEIGHT_LINE_LEN + \
  42. /* p line. */ \
  43. MAX_POLICY_LINE_LEN + \
  44. /* v line. */ \
  45. MAX_V_LINE_LEN \
  46. )
  47. int connection_dirserv_flushed_some(dir_connection_t *conn);
  48. int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_t *pk);
  49. int dirserv_load_fingerprint_file(void);
  50. void dirserv_free_fingerprint_list(void);
  51. const char *dirserv_get_nickname_by_digest(const char *digest);
  52. enum was_router_added_t dirserv_add_multiple_descriptors(
  53. const char *desc, uint8_t purpose,
  54. const char *source,
  55. const char **msg);
  56. enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
  57. const char **msg,
  58. const char *source);
  59. void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
  60. int list_server_status_v1(smartlist_t *routers, char **router_status_out,
  61. int for_controller);
  62. int dirserv_dump_directory_to_string(char **dir_out,
  63. crypto_pk_t *private_key);
  64. int directory_fetches_from_authorities(const or_options_t *options);
  65. int directory_fetches_dir_info_early(const or_options_t *options);
  66. int directory_fetches_dir_info_later(const or_options_t *options);
  67. int directory_caches_v2_dir_info(const or_options_t *options);
  68. #define directory_caches_v1_dir_info(o) directory_caches_v2_dir_info(o)
  69. int directory_caches_unknown_auth_certs(const or_options_t *options);
  70. int directory_caches_dir_info(const or_options_t *options);
  71. int directory_permits_begindir_requests(const or_options_t *options);
  72. int directory_permits_controller_requests(const or_options_t *options);
  73. int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
  74. time_t now);
  75. void directory_set_dirty(void);
  76. cached_dir_t *dirserv_get_directory(void);
  77. cached_dir_t *dirserv_get_runningrouters(void);
  78. cached_dir_t *dirserv_get_consensus(const char *flavor_name);
  79. void dirserv_set_cached_directory(const char *directory, time_t when,
  80. int is_running_routers);
  81. void dirserv_set_cached_networkstatus_v2(const char *directory,
  82. const char *identity,
  83. time_t published);
  84. void dirserv_set_cached_consensus_networkstatus(const char *consensus,
  85. const char *flavor_name,
  86. const digests_t *digests,
  87. time_t published);
  88. void dirserv_clear_old_networkstatuses(time_t cutoff);
  89. void dirserv_clear_old_v1_info(time_t now);
  90. void dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
  91. void dirserv_get_networkstatus_v2_fingerprints(smartlist_t *result,
  92. const char *key);
  93. int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
  94. const char **msg,
  95. int for_unencrypted_conn,
  96. int is_extrainfo);
  97. int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
  98. const char **msg);
  99. void dirserv_orconn_tls_done(const char *address,
  100. uint16_t or_port,
  101. const char *digest_rcvd);
  102. int dirserv_should_launch_reachability_test(const routerinfo_t *ri,
  103. const routerinfo_t *ri_old);
  104. void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
  105. void dirserv_test_reachability(time_t now);
  106. int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
  107. int complain,
  108. int *valid_out);
  109. uint32_t dirserv_router_get_status(const routerinfo_t *router,
  110. const char **msg);
  111. void dirserv_set_node_flags_from_authoritative_status(node_t *node,
  112. uint32_t authstatus);
  113. int dirserv_would_reject_router(const routerstatus_t *rs);
  114. int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
  115. int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
  116. int dirserv_have_any_microdesc(const smartlist_t *fps);
  117. size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
  118. int compressed);
  119. size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
  120. int routerstatus_format_entry(char *buf, size_t buf_len,
  121. const routerstatus_t *rs, const char *platform,
  122. routerstatus_format_type_t format);
  123. void dirserv_free_all(void);
  124. void cached_dir_decref(cached_dir_t *d);
  125. cached_dir_t *new_cached_dir(char *s, time_t published);
  126. #ifdef DIRSERV_PRIVATE
  127. int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
  128. int measured_bw_line_apply(measured_bw_line_t *parsed_line,
  129. smartlist_t *routerstatuses);
  130. #endif
  131. int dirserv_read_measured_bandwidths(const char *from_file,
  132. smartlist_t *routerstatuses);
  133. #endif