router.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-2018, 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 "lib/testsupport/testsupport.h"
  13. struct curve25519_keypair_t;
  14. struct ed25519_keypair_t;
  15. #define TOR_ROUTERINFO_ERROR_NO_EXT_ADDR (-1)
  16. #define TOR_ROUTERINFO_ERROR_CANNOT_PARSE (-2)
  17. #define TOR_ROUTERINFO_ERROR_NOT_A_SERVER (-3)
  18. #define TOR_ROUTERINFO_ERROR_DIGEST_FAILED (-4)
  19. #define TOR_ROUTERINFO_ERROR_CANNOT_GENERATE (-5)
  20. #define TOR_ROUTERINFO_ERROR_DESC_REBUILDING (-6)
  21. crypto_pk_t *get_onion_key(void);
  22. time_t get_onion_key_set_at(void);
  23. void set_server_identity_key(crypto_pk_t *k);
  24. crypto_pk_t *get_server_identity_key(void);
  25. int server_identity_key_is_set(void);
  26. void set_client_identity_key(crypto_pk_t *k);
  27. crypto_pk_t *get_tlsclient_identity_key(void);
  28. int client_identity_key_is_set(void);
  29. MOCK_DECL(authority_cert_t *, get_my_v3_authority_cert, (void));
  30. crypto_pk_t *get_my_v3_authority_signing_key(void);
  31. authority_cert_t *get_my_v3_legacy_cert(void);
  32. crypto_pk_t *get_my_v3_legacy_signing_key(void);
  33. void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
  34. void expire_old_onion_keys(void);
  35. void rotate_onion_key(void);
  36. crypto_pk_t *init_key_from_file(const char *fname, int generate,
  37. int severity, int log_greeting);
  38. void v3_authority_check_key_expiry(void);
  39. int get_onion_key_lifetime(void);
  40. int get_onion_key_grace_period(void);
  41. crypto_pk_t *router_get_rsa_onion_pkey(const char *pkey, size_t pkey_len);
  42. void router_set_rsa_onion_pkey(const crypto_pk_t *pk, char **onion_pkey_out,
  43. size_t *onion_pkey_len);
  44. di_digest256_map_t *construct_ntor_key_map(void);
  45. void ntor_key_map_free_(di_digest256_map_t *map);
  46. #define ntor_key_map_free(map) \
  47. FREE_AND_NULL(di_digest256_map_t, ntor_key_map_free_, (map))
  48. int router_initialize_tls_context(void);
  49. int init_keys(void);
  50. int init_keys_client(void);
  51. int check_whether_orport_reachable(const or_options_t *options);
  52. int check_whether_dirport_reachable(const or_options_t *options);
  53. int dir_server_mode(const or_options_t *options);
  54. void router_do_reachability_checks(int test_or, int test_dir);
  55. void router_orport_found_reachable(void);
  56. void router_dirport_found_reachable(void);
  57. void router_perform_bandwidth_test(int num_circs, time_t now);
  58. int net_is_disabled(void);
  59. int net_is_completely_disabled(void);
  60. int authdir_mode(const or_options_t *options);
  61. int authdir_mode_handles_descs(const or_options_t *options, int purpose);
  62. int authdir_mode_publishes_statuses(const or_options_t *options);
  63. int authdir_mode_tests_reachability(const or_options_t *options);
  64. int authdir_mode_bridge(const or_options_t *options);
  65. uint16_t router_get_active_listener_port_by_type_af(int listener_type,
  66. sa_family_t family);
  67. uint16_t router_get_advertised_or_port(const or_options_t *options);
  68. uint16_t router_get_advertised_or_port_by_af(const or_options_t *options,
  69. sa_family_t family);
  70. uint16_t router_get_advertised_dir_port(const or_options_t *options,
  71. uint16_t dirport);
  72. MOCK_DECL(int, server_mode, (const or_options_t *options));
  73. MOCK_DECL(int, public_server_mode, (const or_options_t *options));
  74. MOCK_DECL(int, advertised_server_mode, (void));
  75. int proxy_mode(const or_options_t *options);
  76. void consider_publishable_server(int force);
  77. int should_refuse_unknown_exits(const or_options_t *options);
  78. void router_upload_dir_desc_to_dirservers(int force);
  79. void mark_my_descriptor_dirty_if_too_old(time_t now);
  80. void mark_my_descriptor_dirty(const char *reason);
  81. void check_descriptor_bandwidth_changed(time_t now);
  82. void check_descriptor_ipaddress_changed(time_t now);
  83. void router_new_address_suggestion(const char *suggestion,
  84. const dir_connection_t *d_conn);
  85. int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
  86. MOCK_DECL(int, router_my_exit_policy_is_reject_star,(void));
  87. MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
  88. MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo_with_err,(int *err));
  89. extrainfo_t *router_get_my_extrainfo(void);
  90. const char *router_get_my_descriptor(void);
  91. const char *router_get_descriptor_gen_reason(void);
  92. int router_digest_is_me(const char *digest);
  93. const uint8_t *router_get_my_id_digest(void);
  94. int router_extrainfo_digest_is_me(const char *digest);
  95. int router_is_me(const routerinfo_t *router);
  96. MOCK_DECL(int,router_pick_published_address,(const or_options_t *options,
  97. uint32_t *addr,
  98. int cache_only));
  99. int router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e);
  100. int router_rebuild_descriptor(int force);
  101. char *router_dump_router_to_string(routerinfo_t *router,
  102. const crypto_pk_t *ident_key,
  103. const crypto_pk_t *tap_key,
  104. const struct curve25519_keypair_t *ntor_keypair,
  105. const struct ed25519_keypair_t *signing_keypair);
  106. char *router_dump_exit_policy_to_string(const routerinfo_t *router,
  107. int include_ipv4,
  108. int include_ipv6);
  109. void router_get_prim_orport(const routerinfo_t *router,
  110. tor_addr_port_t *addr_port_out);
  111. void router_get_pref_orport(const routerinfo_t *router,
  112. tor_addr_port_t *addr_port_out);
  113. void router_get_pref_ipv6_orport(const routerinfo_t *router,
  114. tor_addr_port_t *addr_port_out);
  115. int router_ipv6_preferred(const routerinfo_t *router);
  116. int router_has_addr(const routerinfo_t *router, const tor_addr_t *addr);
  117. int router_has_orport(const routerinfo_t *router,
  118. const tor_addr_port_t *orport);
  119. int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
  120. crypto_pk_t *ident_key,
  121. const struct ed25519_keypair_t *signing_keypair);
  122. int is_legal_nickname(const char *s);
  123. int is_legal_nickname_or_hexdigest(const char *s);
  124. int is_legal_hexdigest(const char *s);
  125. const char *router_describe(const routerinfo_t *ri);
  126. const char *node_describe(const node_t *node);
  127. const char *routerstatus_describe(const routerstatus_t *ri);
  128. const char *extend_info_describe(const extend_info_t *ei);
  129. const char *routerinfo_err_to_string(int err);
  130. int routerinfo_err_is_transient(int err);
  131. void router_get_verbose_nickname(char *buf, const routerinfo_t *router);
  132. void router_reset_warnings(void);
  133. void router_reset_reachability(void);
  134. void router_free_all(void);
  135. const char *router_purpose_to_string(uint8_t p);
  136. uint8_t router_purpose_from_string(const char *s);
  137. smartlist_t *router_get_all_orports(const routerinfo_t *ri);
  138. #ifdef ROUTER_PRIVATE
  139. /* Used only by router.c and test.c */
  140. STATIC void get_platform_str(char *platform, size_t len);
  141. STATIC int router_write_fingerprint(int hashed);
  142. #endif
  143. #endif /* !defined(TOR_ROUTER_H) */