dirserv.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  39. int connection_dirserv_flushed_some(dir_connection_t *conn);
  40. int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
  41. int dirserv_load_fingerprint_file(void);
  42. void dirserv_free_fingerprint_list(void);
  43. const char *dirserv_get_nickname_by_digest(const char *digest);
  44. enum was_router_added_t dirserv_add_multiple_descriptors(
  45. const char *desc, uint8_t purpose,
  46. const char *source,
  47. const char **msg);
  48. enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
  49. const char **msg,
  50. const char *source);
  51. void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
  52. int list_server_status_v1(smartlist_t *routers, char **router_status_out,
  53. int for_controller);
  54. int dirserv_dump_directory_to_string(char **dir_out,
  55. crypto_pk_env_t *private_key);
  56. int directory_fetches_from_authorities(or_options_t *options);
  57. int directory_fetches_dir_info_early(or_options_t *options);
  58. int directory_fetches_dir_info_later(or_options_t *options);
  59. int directory_caches_v2_dir_info(or_options_t *options);
  60. #define directory_caches_v1_dir_info(o) directory_caches_v2_dir_info(o)
  61. int directory_caches_dir_info(or_options_t *options);
  62. int directory_permits_begindir_requests(or_options_t *options);
  63. int directory_permits_controller_requests(or_options_t *options);
  64. int directory_too_idle_to_fetch_descriptors(or_options_t *options, time_t now);
  65. void directory_set_dirty(void);
  66. cached_dir_t *dirserv_get_directory(void);
  67. cached_dir_t *dirserv_get_runningrouters(void);
  68. cached_dir_t *dirserv_get_consensus(const char *flavor_name);
  69. void dirserv_set_cached_directory(const char *directory, time_t when,
  70. int is_running_routers);
  71. void dirserv_set_cached_networkstatus_v2(const char *directory,
  72. const char *identity,
  73. time_t published);
  74. void dirserv_set_cached_consensus_networkstatus(const char *consensus,
  75. const char *flavor_name,
  76. const digests_t *digests,
  77. time_t published);
  78. void dirserv_clear_old_networkstatuses(time_t cutoff);
  79. void dirserv_clear_old_v1_info(time_t now);
  80. void dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
  81. void dirserv_get_networkstatus_v2_fingerprints(smartlist_t *result,
  82. const char *key);
  83. int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
  84. const char **msg,
  85. int for_unencrypted_conn,
  86. int is_extrainfo);
  87. int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
  88. const char **msg);
  89. void dirserv_orconn_tls_done(const char *address,
  90. uint16_t or_port,
  91. const char *digest_rcvd,
  92. int as_advertised);
  93. int dirserv_should_launch_reachability_test(routerinfo_t *ri,
  94. routerinfo_t *ri_old);
  95. void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
  96. void dirserv_test_reachability(time_t now);
  97. int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
  98. int complain);
  99. int dirserv_would_reject_router(routerstatus_t *rs);
  100. int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
  101. int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
  102. int dirserv_have_any_microdesc(const smartlist_t *fps);
  103. size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
  104. int compressed);
  105. size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
  106. int routerstatus_format_entry(char *buf, size_t buf_len,
  107. routerstatus_t *rs, const char *platform,
  108. routerstatus_format_type_t format);
  109. void dirserv_free_all(void);
  110. void cached_dir_decref(cached_dir_t *d);
  111. cached_dir_t *new_cached_dir(char *s, time_t published);
  112. #ifdef DIRSERV_PRIVATE
  113. int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
  114. int measured_bw_line_apply(measured_bw_line_t *parsed_line,
  115. smartlist_t *routerstatuses);
  116. #endif
  117. int dirserv_read_measured_bandwidths(const char *from_file,
  118. smartlist_t *routerstatuses);
  119. #endif