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