tor  0.4.0.1-alpha
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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
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 
28 time_t get_onion_key_set_at(void);
35 MOCK_DECL(authority_cert_t *, get_my_v3_authority_cert, (void));
39 void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
40 void expire_old_onion_keys(void);
41 void rotate_onion_key(void);
43 int get_onion_key_lifetime(void);
45 
46 crypto_pk_t *router_get_rsa_onion_pkey(const char *pkey, size_t pkey_len);
47 void router_set_rsa_onion_pkey(const crypto_pk_t *pk, char **onion_pkey_out,
48  size_t *onion_pkey_len);
49 
52 #define ntor_key_map_free(map) \
53  FREE_AND_NULL(di_digest256_map_t, ntor_key_map_free_, (map))
54 
56 int init_keys(void);
57 int init_keys_client(void);
58 
59 uint16_t router_get_active_listener_port_by_type_af(int listener_type,
60  sa_family_t family);
61 uint16_t router_get_advertised_or_port(const or_options_t *options);
63  sa_family_t family);
64 uint16_t router_get_advertised_dir_port(const or_options_t *options,
65  uint16_t dirport);
66 
68  uint16_t dir_port);
69 
70 void consider_publishable_server(int force);
71 int should_refuse_unknown_exits(const or_options_t *options);
72 
75 void mark_my_descriptor_dirty(const char *reason);
76 void check_descriptor_bandwidth_changed(time_t now);
77 void check_descriptor_ipaddress_changed(time_t now);
79 void router_new_address_suggestion(const char *suggestion,
80  const dir_connection_t *d_conn);
81 int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
82 MOCK_DECL(int, router_my_exit_policy_is_reject_star,(void));
83 MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
84 MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo_with_err,(int *err));
86 const char *router_get_my_descriptor(void);
87 const char *router_get_descriptor_gen_reason(void);
88 int router_digest_is_me(const char *digest);
89 const uint8_t *router_get_my_id_digest(void);
90 int router_extrainfo_digest_is_me(const char *digest);
91 int router_is_me(const routerinfo_t *router);
92 MOCK_DECL(int,router_pick_published_address,(const or_options_t *options,
93  uint32_t *addr,
94  int cache_only));
96 int router_rebuild_descriptor(int force);
98  const crypto_pk_t *ident_key,
99  const crypto_pk_t *tap_key,
100  const struct curve25519_keypair_t *ntor_keypair,
101  const struct ed25519_keypair_t *signing_keypair);
103  int include_ipv4,
104  int include_ipv6);
105 int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
106  crypto_pk_t *ident_key,
107  const struct ed25519_keypair_t *signing_keypair);
108 
109 const char *routerinfo_err_to_string(int err);
110 int routerinfo_err_is_transient(int err);
111 
112 void router_reset_warnings(void);
113 void router_reset_reachability(void);
114 void router_free_all(void);
115 
116 #ifdef ROUTER_PRIVATE
117 /* Used only by router.c and test.c */
118 STATIC void get_platform_str(char *platform, size_t len);
119 STATIC int router_write_fingerprint(int hashed);
120 STATIC smartlist_t *get_my_declared_family(const or_options_t *options);
121 
122 #ifdef TOR_UNIT_TESTS
123 extern time_t desc_clean_since;
124 extern const char *desc_dirty_reason;
125 void set_server_identity_key_digest_testing(const uint8_t *digest);
126 #endif
127 
128 #endif
129 
130 #endif /* !defined(TOR_ROUTER_H) */
crypto_pk_t * get_my_v3_authority_signing_key(void)
Definition: router.c:432
const char * router_get_my_descriptor(void)
Definition: router.c:1672
authority_cert_t * get_my_v3_legacy_cert(void)
Definition: router.c:441
int client_identity_key_is_set(void)
Definition: router.c:416
int router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
Definition: router.c:1952
void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last)
Definition: router.c:209
int router_initialize_tls_context(void)
Definition: router.c:788
uint16_t sa_family_t
Definition: inaddr_st.h:77
const uint8_t * router_get_my_id_digest(void)
Definition: router.c:1597
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port)
Definition: router.c:1542
void check_descriptor_ipaddress_changed(time_t now)
Definition: router.c:2341
extrainfo_t * router_get_my_extrainfo(void)
Definition: router.c:1689
int init_keys(void)
Definition: router.c:923
int router_is_me(const routerinfo_t *router)
Definition: router.c:1618
void router_new_address_suggestion(const char *suggestion, const dir_connection_t *d_conn)
Definition: router.c:2390
crypto_pk_t * get_onion_key(void)
Definition: router.c:198
STATIC time_t desc_clean_since
Definition: router.c:1485
void router_upload_dir_desc_to_dirservers(int force)
Definition: router.c:1496
int should_refuse_unknown_exits(const or_options_t *options)
Definition: router.c:1328
void expire_old_onion_keys(void)
Definition: router.c:233
uint16_t router_get_advertised_dir_port(const or_options_t *options, uint16_t dirport)
Definition: router.c:1457
void router_reset_reachability(void)
Definition: selftest.c:48
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:2483
int router_has_bandwidth_to_be_dirserver(const or_options_t *options)
Definition: router.c:1186
STATIC void get_platform_str(char *platform, size_t len)
Definition: router.c:2466
time_t get_onion_key_set_at(void)
Definition: router.c:326
crypto_pk_t * get_tlsclient_identity_key(void)
Definition: router.c:407
int router_rebuild_descriptor(int force)
Definition: router.c:2149
uint16_t router_get_active_listener_port_by_type_af(int listener_type, sa_family_t family)
Definition: router.c:1406
const char * routerinfo_err_to_string(int err)
Definition: router.c:140
void set_client_identity_key(crypto_pk_t *k)
Definition: router.c:397
int router_digest_is_me(const char *digest)
Definition: router.c:1589
void router_reset_warnings(void)
Definition: router.c:3151
void router_free_all(void)
Definition: router.c:3161
STATIC int router_write_fingerprint(int hashed)
Definition: router.c:826
crypto_pk_t * get_my_v3_legacy_signing_key(void)
Definition: router.c:449
void set_server_identity_key(crypto_pk_t *k)
Definition: router.c:334
void rotate_onion_key(void)
Definition: router.c:462
char * router_dump_exit_policy_to_string(const routerinfo_t *router, int include_ipv4, int include_ipv6)
Definition: router.c:2866
int router_should_advertise_dirport(const or_options_t *options, uint16_t dir_port)
Definition: router.c:1306
int server_identity_key_is_set(void)
Definition: router.c:389
const char * router_get_descriptor_gen_reason(void)
Definition: router.c:1701
di_digest256_map_t * construct_ntor_key_map(void)
Definition: router.c:280
int get_onion_key_lifetime(void)
Definition: router.c:764
void consider_publishable_server(int force)
Definition: router.c:1384
Macros to implement mocking and selective exposure for the test code.
crypto_pk_t * get_server_identity_key(void)
Definition: router.c:378
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
void mark_my_descriptor_dirty(const char *reason)
Definition: router.c:2244
int get_onion_key_grace_period(void)
Definition: router.c:774
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:2937
int router_extrainfo_digest_is_me(const char *digest)
Definition: router.c:1605
void ntor_key_map_free_(di_digest256_map_t *map)
Definition: router.c:314
STATIC smartlist_t * get_my_declared_family(const or_options_t *options)
Definition: router.c:1828
uint16_t router_get_advertised_or_port(const or_options_t *options)
Definition: router.c:1427
void check_descriptor_bandwidth_changed(time_t now)
Definition: router.c:2273
void mark_my_descriptor_dirty_if_too_old(time_t now)
Definition: router.c:2203
int routerinfo_err_is_transient(int err)
Definition: router.c:167
uint16_t router_get_advertised_or_port_by_af(const or_options_t *options, sa_family_t family)
Definition: router.c:1435
void v3_authority_check_key_expiry(void)
Definition: router.c:701
STATIC const char * desc_dirty_reason
Definition: router.c:1487