Tor  0.4.5.0-alpha-dev
router.h
Go to the documentation of this file.
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-2020, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file router.h
9  * \brief Header file for router.c.
10  **/
11 
12 #ifndef TOR_ROUTER_H
13 #define TOR_ROUTER_H
14 
16 
18 struct ed25519_keypair_t;
19 
20 #define TOR_ROUTERINFO_ERROR_NO_EXT_ADDR (-1)
21 #define TOR_ROUTERINFO_ERROR_CANNOT_PARSE (-2)
22 #define TOR_ROUTERINFO_ERROR_NOT_A_SERVER (-3)
23 #define TOR_ROUTERINFO_ERROR_DIGEST_FAILED (-4)
24 #define TOR_ROUTERINFO_ERROR_CANNOT_GENERATE (-5)
25 #define TOR_ROUTERINFO_ERROR_DESC_REBUILDING (-6)
26 #define TOR_ROUTERINFO_ERROR_INTERNAL_BUG (-7)
27 
29 time_t get_onion_key_set_at(void);
31 /* Some compilers are clever enough to know that when relay mode is disabled,
32  * this function never returns. */
33 #ifdef HAVE_MODULE_RELAY
34 MOCK_DECL(crypto_pk_t *,get_server_identity_key,(void));
35 #else
36 #define get_server_identity_key() (tor_abort_(),NULL)
37 #endif
46 void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
47 void expire_old_onion_keys(void);
48 void rotate_onion_key(void);
50 int get_onion_key_lifetime(void);
52 
53 crypto_pk_t *router_get_rsa_onion_pkey(const char *pkey, size_t pkey_len);
54 void router_set_rsa_onion_pkey(const crypto_pk_t *pk, char **onion_pkey_out,
55  size_t *onion_pkey_len);
56 
59 #define ntor_key_map_free(map) \
60  FREE_AND_NULL(di_digest256_map_t, ntor_key_map_free_, (map))
61 
63 int init_keys(void);
64 int init_keys_client(void);
65 
66 uint16_t router_get_active_listener_port_by_type_af(int listener_type,
67  sa_family_t family);
68 void routerconf_find_ipv6_or_ap(const or_options_t *options,
69  tor_addr_port_t *ipv6_ap_out);
70 bool routerconf_has_ipv6_orport(const or_options_t *options);
71 MOCK_DECL(bool, router_can_extend_over_ipv6,(const or_options_t *options));
72 uint16_t routerconf_find_or_port(const or_options_t *options,
73  sa_family_t family);
74 uint16_t routerconf_find_dir_port(const or_options_t *options,
75  uint16_t dirport);
76 
78  uint16_t dir_port);
79 
80 void consider_publishable_server(int force);
81 int should_refuse_unknown_exits(const or_options_t *options);
82 
86 void mark_my_descriptor_dirty(const char *reason);
87 void mark_my_descriptor_if_omit_ipv6_changes(const char *reason,
88  bool omit_ipv6);
89 void check_descriptor_bandwidth_changed(time_t now);
90 void check_descriptor_ipaddress_changed(time_t now);
92 int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
97 const char *router_get_my_descriptor(void);
98 const char *router_get_descriptor_gen_reason(void);
99 int router_digest_is_me(const char *digest);
100 const uint8_t *router_get_my_id_digest(void);
101 int router_extrainfo_digest_is_me(const char *digest);
102 int router_is_me(const routerinfo_t *router);
105 int router_rebuild_descriptor(int force);
107  const crypto_pk_t *ident_key,
108  const crypto_pk_t *tap_key,
109  const struct curve25519_keypair_t *ntor_keypair,
110  const struct ed25519_keypair_t *signing_keypair);
112  int include_ipv4,
113  int include_ipv6);
114 int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
115  crypto_pk_t *ident_key,
116  const struct ed25519_keypair_t *signing_keypair);
117 
118 const char *routerinfo_err_to_string(int err);
119 int routerinfo_err_is_transient(int err);
120 
121 void log_addr_has_changed(int severity, const tor_addr_t *prev,
122  const tor_addr_t *cur, const char *source);
123 
124 void router_reset_warnings(void);
125 void router_free_all(void);
126 
127 #ifdef ROUTER_PRIVATE
128 /* Used only by router.c and the unit tests */
129 STATIC void get_platform_str(char *platform, size_t len);
130 STATIC int router_write_fingerprint(int hashed, int ed25519_identity);
132 
133 #ifdef TOR_UNIT_TESTS
134 extern time_t desc_clean_since;
135 extern const char *desc_dirty_reason;
136 void set_server_identity_key_digest_testing(const uint8_t *digest);
137 MOCK_DECL(STATIC const struct curve25519_keypair_t *,
139 
140 MOCK_DECL(STATIC int,
143  const routerinfo_t *ri);
145  const extrainfo_t *ei);
147 #endif /* defined(TOR_UNIT_TESTS) */
148 
149 #endif /* defined(ROUTER_PRIVATE) */
150 
151 #endif /* !defined(TOR_ROUTER_H) */
extrainfo_dump_to_string
int extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo, crypto_pk_t *ident_key, const ed25519_keypair_t *signing_keypair)
Definition: router.c:3403
router_can_extend_over_ipv6
bool router_can_extend_over_ipv6(const or_options_t *options)
Definition: router.c:1553
router_update_routerinfo_from_extrainfo
STATIC void router_update_routerinfo_from_extrainfo(routerinfo_t *ri, const extrainfo_t *ei)
Definition: router.c:2291
routerinfo_t
Definition: routerinfo_st.h:20
construct_ntor_key_map
di_digest256_map_t * construct_ntor_key_map(void)
Definition: router.c:288
router_addr_is_my_published_addr
bool router_addr_is_my_published_addr(const tor_addr_t *addr)
Definition: router.c:1738
init_keys
int init_keys(void)
Definition: router.c:928
mark_my_descriptor_if_omit_ipv6_changes
void mark_my_descriptor_if_omit_ipv6_changes(const char *reason, bool omit_ipv6)
Definition: router.c:2482
tor_addr_t
Definition: address.h:69
extrainfo_t
Definition: extrainfo_st.h:18
get_onion_key
crypto_pk_t * get_onion_key(void)
Definition: router.c:205
routerconf_find_dir_port
uint16_t routerconf_find_dir_port(const or_options_t *options, uint16_t dirport)
Definition: router.c:1566
get_onion_key_lifetime
int get_onion_key_lifetime(void)
Definition: router.c:774
desc_dirty_reason
STATIC const char * desc_dirty_reason
Definition: router.c:1596
router_should_advertise_dirport
int router_should_advertise_dirport(const or_options_t *options, uint16_t dir_port)
Definition: router.c:1320
routerinfo_err_to_string
const char * routerinfo_err_to_string(int err)
Definition: router.c:145
mark_my_descriptor_dirty
void mark_my_descriptor_dirty(const char *reason)
Definition: router.c:2545
router_dump_and_sign_routerinfo_descriptor_body
STATIC int router_dump_and_sign_routerinfo_descriptor_body(routerinfo_t *ri)
Definition: router.c:2319
router_new_consensus_params
void router_new_consensus_params(const networkstatus_t *)
Definition: router.c:2449
log_addr_has_changed
void log_addr_has_changed(int severity, const tor_addr_t *prev, const tor_addr_t *cur, const char *source)
Definition: router.c:2613
router_get_my_descriptor
const char * router_get_my_descriptor(void)
Definition: router.c:1796
client_identity_key_is_set
int client_identity_key_is_set(void)
Definition: router.c:426
mark_my_descriptor_dirty_if_too_old
void mark_my_descriptor_dirty_if_too_old(time_t now)
Definition: router.c:2504
set_client_identity_key
void set_client_identity_key(crypto_pk_t *k)
Definition: router.c:407
router_get_my_routerinfo
const routerinfo_t * router_get_my_routerinfo(void)
Definition: router.c:1760
get_onion_key_grace_period
int get_onion_key_grace_period(void)
Definition: router.c:784
get_my_v3_authority_cert
authority_cert_t * get_my_v3_authority_cert(void)
Definition: router.c:434
router_get_descriptor_gen_reason
const char * router_get_descriptor_gen_reason(void)
Definition: router.c:1825
get_my_declared_family
STATIC smartlist_t * get_my_declared_family(const or_options_t *options)
Definition: router.c:1920
check_descriptor_bandwidth_changed
void check_descriptor_bandwidth_changed(time_t now)
Definition: router.c:2576
routerconf_has_ipv6_orport
bool routerconf_has_ipv6_orport(const or_options_t *options)
Definition: router.c:1522
routerconf_find_ipv6_or_ap
void routerconf_find_ipv6_or_ap(const or_options_t *options, tor_addr_port_t *ipv6_ap_out)
Definition: router.c:1481
router_build_fresh_signed_extrainfo
STATIC extrainfo_t * router_build_fresh_signed_extrainfo(const routerinfo_t *ri)
Definition: router.c:2259
routerinfo_err_is_transient
int routerinfo_err_is_transient(int err)
Definition: router.c:174
tor_addr_port_t
Definition: address.h:81
router_get_my_routerinfo_with_err
const routerinfo_t * router_get_my_routerinfo_with_err(int *err)
Definition: router.c:1770
router_dump_router_to_string
char * router_dump_router_to_string(routerinfo_t *router, const crypto_pk_t *ident_key, const crypto_pk_t *tap_key, const curve25519_keypair_t *ntor_keypair, const ed25519_keypair_t *signing_keypair)
Definition: router.c:2721
v3_authority_check_key_expiry
void v3_authority_check_key_expiry(void)
Definition: router.c:711
router_dump_exit_policy_to_string
char * router_dump_exit_policy_to_string(const routerinfo_t *router, int include_ipv4, int include_ipv6)
Definition: router.c:3106
di_digest256_map_t
Definition: di_ops.c:147
MOCK_DECL
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
expire_old_onion_keys
void expire_old_onion_keys(void)
Definition: router.c:240
router_compare_to_my_exit_policy
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port)
Definition: router.c:1651
server_identity_key_is_set
int server_identity_key_is_set(void)
Definition: router.c:399
authority_cert_t
Definition: authority_cert_st.h:19
get_onion_key_set_at
time_t get_onion_key_set_at(void)
Definition: router.c:332
router_my_exit_policy_is_reject_star
int router_my_exit_policy_is_reject_star(void)
Definition: router.c:1686
router_build_fresh_unsigned_routerinfo
STATIC int router_build_fresh_unsigned_routerinfo(routerinfo_t **ri_out)
Definition: router.c:2045
ntor_key_map_free_
void ntor_key_map_free_(di_digest256_map_t *map)
Definition: router.c:320
router_rebuild_descriptor
int router_rebuild_descriptor(int force)
Definition: router.c:2415
get_current_curve25519_keypair
STATIC const struct curve25519_keypair_t * get_current_curve25519_keypair(void)
Definition: router.c:280
router_has_bandwidth_to_be_dirserver
int router_has_bandwidth_to_be_dirserver(const or_options_t *options)
Definition: router.c:1200
should_refuse_unknown_exits
int should_refuse_unknown_exits(const or_options_t *options)
Definition: router.c:1342
router_initialize_tls_context
int router_initialize_tls_context(void)
Definition: router.c:798
get_my_v3_legacy_cert
authority_cert_t * get_my_v3_legacy_cert(void)
Definition: router.c:451
get_platform_str
STATIC void get_platform_str(char *platform, size_t len)
Definition: router.c:2700
get_my_v3_authority_signing_key
crypto_pk_t * get_my_v3_authority_signing_key(void)
Definition: router.c:442
router_get_active_listener_port_by_type_af
uint16_t router_get_active_listener_port_by_type_af(int listener_type, sa_family_t family)
Definition: router.c:1441
router_extrainfo_digest_is_me
int router_extrainfo_digest_is_me(const char *digest)
Definition: router.c:1714
check_descriptor_ipaddress_changed
void check_descriptor_ipaddress_changed(time_t now)
Definition: router.c:2646
router_get_my_id_digest
const uint8_t * router_get_my_id_digest(void)
Definition: router.c:1706
testsupport.h
Macros to implement mocking and selective exposure for the test code.
dup_onion_keys
void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last)
Definition: router.c:216
crypto_pk_t
Definition: crypto_rsa_nss.c:37
get_tlsclient_identity_key
crypto_pk_t * get_tlsclient_identity_key(void)
Definition: router.c:417
desc_clean_since
STATIC time_t desc_clean_since
Definition: router.c:1594
router_write_fingerprint
STATIC int router_write_fingerprint(int hashed, int ed25519_identity)
Definition: router.c:836
set_server_identity_key
void set_server_identity_key(crypto_pk_t *k)
Definition: router.c:340
router_free_all
void router_free_all(void)
Definition: router.c:3518
rotate_onion_key
void rotate_onion_key(void)
Definition: router.c:472
sa_family_t
uint16_t sa_family_t
Definition: inaddr_st.h:77
or_options_t
Definition: or_options_st.h:45
STATIC
#define STATIC
Definition: testsupport.h:32
router_get_my_extrainfo
extrainfo_t * router_get_my_extrainfo(void)
Definition: router.c:1813
router_digest_is_me
int router_digest_is_me(const char *digest)
Definition: router.c:1698
router_reset_warnings
void router_reset_warnings(void)
Definition: router.c:3508
router_build_fresh_descriptor
int router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
Definition: router.c:2353
networkstatus_t
Definition: networkstatus_st.h:26
router_upload_dir_desc_to_dirservers
void router_upload_dir_desc_to_dirservers(int force)
Definition: router.c:1605
smartlist_t
Definition: smartlist_core.h:26
routerconf_find_or_port
uint16_t routerconf_find_or_port(const or_options_t *options, sa_family_t family)
Definition: router.c:1461
consider_publishable_server
void consider_publishable_server(int force)
Definition: router.c:1419
router_is_me
int router_is_me(const routerinfo_t *router)
Definition: router.c:1727
get_my_v3_legacy_signing_key
crypto_pk_t * get_my_v3_legacy_signing_key(void)
Definition: router.c:459
curve25519_keypair_t
Definition: crypto_curve25519.h:38
ed25519_keypair_t
Definition: crypto_ed25519.h:39