router.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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-2013, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file router.h
  8. * \brief Header file for router.c.
  9. **/
  10. #ifndef TOR_ROUTER_H
  11. #define TOR_ROUTER_H
  12. #include "testsupport.h"
  13. crypto_pk_t *get_onion_key(void);
  14. time_t get_onion_key_set_at(void);
  15. void set_server_identity_key(crypto_pk_t *k);
  16. crypto_pk_t *get_server_identity_key(void);
  17. int server_identity_key_is_set(void);
  18. void set_client_identity_key(crypto_pk_t *k);
  19. crypto_pk_t *get_tlsclient_identity_key(void);
  20. int client_identity_key_is_set(void);
  21. authority_cert_t *get_my_v3_authority_cert(void);
  22. crypto_pk_t *get_my_v3_authority_signing_key(void);
  23. authority_cert_t *get_my_v3_legacy_cert(void);
  24. crypto_pk_t *get_my_v3_legacy_signing_key(void);
  25. void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
  26. void rotate_onion_key(void);
  27. crypto_pk_t *init_key_from_file(const char *fname, int generate,
  28. int severity);
  29. void v3_authority_check_key_expiry(void);
  30. #ifdef CURVE25519_ENABLED
  31. di_digest256_map_t *construct_ntor_key_map(void);
  32. void ntor_key_map_free(di_digest256_map_t *map);
  33. #endif
  34. int router_initialize_tls_context(void);
  35. int init_keys(void);
  36. int check_whether_orport_reachable(void);
  37. int check_whether_dirport_reachable(void);
  38. void consider_testing_reachability(int test_or, int test_dir);
  39. void router_orport_found_reachable(void);
  40. void router_dirport_found_reachable(void);
  41. void router_perform_bandwidth_test(int num_circs, time_t now);
  42. int net_is_disabled(void);
  43. int authdir_mode(const or_options_t *options);
  44. int authdir_mode_v3(const or_options_t *options);
  45. int authdir_mode_any_main(const or_options_t *options);
  46. int authdir_mode_any_nonhidserv(const or_options_t *options);
  47. int authdir_mode_handles_descs(const or_options_t *options, int purpose);
  48. int authdir_mode_publishes_statuses(const or_options_t *options);
  49. int authdir_mode_tests_reachability(const or_options_t *options);
  50. int authdir_mode_bridge(const or_options_t *options);
  51. uint16_t router_get_active_listener_port_by_type_af(int listener_type,
  52. sa_family_t family);
  53. uint16_t router_get_advertised_or_port(const or_options_t *options);
  54. uint16_t router_get_advertised_or_port_by_af(const or_options_t *options,
  55. sa_family_t family);
  56. uint16_t router_get_advertised_dir_port(const or_options_t *options,
  57. uint16_t dirport);
  58. MOCK_DECL(int, server_mode, (const or_options_t *options));
  59. MOCK_DECL(int, public_server_mode, (const or_options_t *options));
  60. int advertised_server_mode(void);
  61. int proxy_mode(const or_options_t *options);
  62. void consider_publishable_server(int force);
  63. int should_refuse_unknown_exits(const or_options_t *options);
  64. void router_upload_dir_desc_to_dirservers(int force);
  65. void mark_my_descriptor_dirty_if_too_old(time_t now);
  66. void mark_my_descriptor_dirty(const char *reason);
  67. void check_descriptor_bandwidth_changed(time_t now);
  68. void check_descriptor_ipaddress_changed(time_t now);
  69. void router_new_address_suggestion(const char *suggestion,
  70. const dir_connection_t *d_conn);
  71. int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
  72. int router_my_exit_policy_is_reject_star(void);
  73. MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
  74. extrainfo_t *router_get_my_extrainfo(void);
  75. const char *router_get_my_descriptor(void);
  76. const char *router_get_descriptor_gen_reason(void);
  77. int router_digest_is_me(const char *digest);
  78. const uint8_t *router_get_my_id_digest(void);
  79. int router_extrainfo_digest_is_me(const char *digest);
  80. int router_is_me(const routerinfo_t *router);
  81. int router_pick_published_address(const or_options_t *options, uint32_t *addr);
  82. int router_rebuild_descriptor(int force);
  83. char *router_dump_router_to_string(routerinfo_t *router,
  84. crypto_pk_t *ident_key);
  85. char *router_dump_exit_policy_to_string(const routerinfo_t *router,
  86. int include_ipv4,
  87. int include_ipv6);
  88. void router_get_prim_orport(const routerinfo_t *router,
  89. tor_addr_port_t *addr_port_out);
  90. void router_get_pref_orport(const routerinfo_t *router,
  91. tor_addr_port_t *addr_port_out);
  92. void router_get_pref_ipv6_orport(const routerinfo_t *router,
  93. tor_addr_port_t *addr_port_out);
  94. int router_ipv6_preferred(const routerinfo_t *router);
  95. int router_has_addr(const routerinfo_t *router, const tor_addr_t *addr);
  96. int router_has_orport(const routerinfo_t *router,
  97. const tor_addr_port_t *orport);
  98. int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
  99. crypto_pk_t *ident_key);
  100. int is_legal_nickname(const char *s);
  101. int is_legal_nickname_or_hexdigest(const char *s);
  102. int is_legal_hexdigest(const char *s);
  103. /**
  104. * Longest allowed output of format_node_description, plus 1 character for
  105. * NUL. This allows space for:
  106. * "$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF~xxxxxxxxxxxxxxxxxxx at"
  107. * " [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]"
  108. * plus a terminating NUL.
  109. */
  110. #define NODE_DESC_BUF_LEN (MAX_VERBOSE_NICKNAME_LEN+4+TOR_ADDR_BUF_LEN)
  111. const char *format_node_description(char *buf,
  112. const char *id_digest,
  113. int is_named,
  114. const char *nickname,
  115. const tor_addr_t *addr,
  116. uint32_t addr32h);
  117. const char *router_get_description(char *buf, const routerinfo_t *ri);
  118. const char *node_get_description(char *buf, const node_t *node);
  119. const char *routerstatus_get_description(char *buf, const routerstatus_t *rs);
  120. const char *extend_info_get_description(char *buf, const extend_info_t *ei);
  121. const char *router_describe(const routerinfo_t *ri);
  122. const char *node_describe(const node_t *node);
  123. const char *routerstatus_describe(const routerstatus_t *ri);
  124. const char *extend_info_describe(const extend_info_t *ei);
  125. void router_get_verbose_nickname(char *buf, const routerinfo_t *router);
  126. void router_reset_warnings(void);
  127. void router_reset_reachability(void);
  128. void router_free_all(void);
  129. const char *router_purpose_to_string(uint8_t p);
  130. uint8_t router_purpose_from_string(const char *s);
  131. smartlist_t *router_get_all_orports(const routerinfo_t *ri);
  132. #ifdef ROUTER_PRIVATE
  133. /* Used only by router.c and test.c */
  134. STATIC void get_platform_str(char *platform, size_t len);
  135. STATIC int router_write_fingerprint(int hashed);
  136. #endif
  137. #endif