dirserv.h 6.9 KB

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