router.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include "feature/nodelist/describe.h"
  14. #include "feature/nodelist/nickname.h"
  15. #include "feature/nodelist/routerinfo.h"
  16. #include "core/mainloop/netstatus.h"
  17. struct curve25519_keypair_t;
  18. struct ed25519_keypair_t;
  19. #define TOR_ROUTERINFO_ERROR_NO_EXT_ADDR (-1)
  20. #define TOR_ROUTERINFO_ERROR_CANNOT_PARSE (-2)
  21. #define TOR_ROUTERINFO_ERROR_NOT_A_SERVER (-3)
  22. #define TOR_ROUTERINFO_ERROR_DIGEST_FAILED (-4)
  23. #define TOR_ROUTERINFO_ERROR_CANNOT_GENERATE (-5)
  24. #define TOR_ROUTERINFO_ERROR_DESC_REBUILDING (-6)
  25. crypto_pk_t *get_onion_key(void);
  26. time_t get_onion_key_set_at(void);
  27. void set_server_identity_key(crypto_pk_t *k);
  28. crypto_pk_t *get_server_identity_key(void);
  29. int server_identity_key_is_set(void);
  30. void set_client_identity_key(crypto_pk_t *k);
  31. crypto_pk_t *get_tlsclient_identity_key(void);
  32. int client_identity_key_is_set(void);
  33. MOCK_DECL(authority_cert_t *, get_my_v3_authority_cert, (void));
  34. crypto_pk_t *get_my_v3_authority_signing_key(void);
  35. authority_cert_t *get_my_v3_legacy_cert(void);
  36. crypto_pk_t *get_my_v3_legacy_signing_key(void);
  37. void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
  38. void expire_old_onion_keys(void);
  39. void rotate_onion_key(void);
  40. void v3_authority_check_key_expiry(void);
  41. int get_onion_key_lifetime(void);
  42. int get_onion_key_grace_period(void);
  43. crypto_pk_t *router_get_rsa_onion_pkey(const char *pkey, size_t pkey_len);
  44. void router_set_rsa_onion_pkey(const crypto_pk_t *pk, char **onion_pkey_out,
  45. size_t *onion_pkey_len);
  46. di_digest256_map_t *construct_ntor_key_map(void);
  47. void ntor_key_map_free_(di_digest256_map_t *map);
  48. #define ntor_key_map_free(map) \
  49. FREE_AND_NULL(di_digest256_map_t, ntor_key_map_free_, (map))
  50. int router_initialize_tls_context(void);
  51. int init_keys(void);
  52. int init_keys_client(void);
  53. uint16_t router_get_active_listener_port_by_type_af(int listener_type,
  54. sa_family_t family);
  55. uint16_t router_get_advertised_or_port(const or_options_t *options);
  56. uint16_t router_get_advertised_or_port_by_af(const or_options_t *options,
  57. sa_family_t family);
  58. uint16_t router_get_advertised_dir_port(const or_options_t *options,
  59. uint16_t dirport);
  60. int router_should_advertise_dirport(const or_options_t *options,
  61. uint16_t dir_port);
  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. int router_has_bandwidth_to_be_dirserver(const or_options_t *options);
  70. void router_new_address_suggestion(const char *suggestion,
  71. const dir_connection_t *d_conn);
  72. int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
  73. MOCK_DECL(int, router_my_exit_policy_is_reject_star,(void));
  74. MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
  75. MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo_with_err,(int *err));
  76. extrainfo_t *router_get_my_extrainfo(void);
  77. const char *router_get_my_descriptor(void);
  78. const char *router_get_descriptor_gen_reason(void);
  79. int router_digest_is_me(const char *digest);
  80. const uint8_t *router_get_my_id_digest(void);
  81. int router_extrainfo_digest_is_me(const char *digest);
  82. int router_is_me(const routerinfo_t *router);
  83. MOCK_DECL(int,router_pick_published_address,(const or_options_t *options,
  84. uint32_t *addr,
  85. int cache_only));
  86. int router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e);
  87. int router_rebuild_descriptor(int force);
  88. char *router_dump_router_to_string(routerinfo_t *router,
  89. const crypto_pk_t *ident_key,
  90. const crypto_pk_t *tap_key,
  91. const struct curve25519_keypair_t *ntor_keypair,
  92. const struct ed25519_keypair_t *signing_keypair);
  93. char *router_dump_exit_policy_to_string(const routerinfo_t *router,
  94. int include_ipv4,
  95. int include_ipv6);
  96. int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
  97. crypto_pk_t *ident_key,
  98. const struct ed25519_keypair_t *signing_keypair);
  99. const char *routerinfo_err_to_string(int err);
  100. int routerinfo_err_is_transient(int err);
  101. void router_reset_warnings(void);
  102. void router_reset_reachability(void);
  103. void router_free_all(void);
  104. #ifdef ROUTER_PRIVATE
  105. /* Used only by router.c and test.c */
  106. STATIC void get_platform_str(char *platform, size_t len);
  107. STATIC int router_write_fingerprint(int hashed);
  108. #endif
  109. #endif /* !defined(TOR_ROUTER_H) */