tor  0.4.1.0-alpha-dev
circuitlist.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_CIRCUITLIST_H
13 #define TOR_CIRCUITLIST_H
14 
16 #include "feature/hs/hs_ident.h"
17 #include "core/or/ocirc_event.h"
18 
20 #define CIRCUIT_STATE_BUILDING 0
21 
22 #define CIRCUIT_STATE_ONIONSKIN_PENDING 1
23 
25 #define CIRCUIT_STATE_CHAN_WAIT 2
26 
29 #define CIRCUIT_STATE_GUARD_WAIT 3
30 
31 #define CIRCUIT_STATE_OPEN 4
32 
33 #define CIRCUIT_PURPOSE_MIN_ 1
34 
35 /* these circuits were initiated elsewhere */
36 #define CIRCUIT_PURPOSE_OR_MIN_ 1
37 
38 #define CIRCUIT_PURPOSE_OR 1
39 
41 #define CIRCUIT_PURPOSE_INTRO_POINT 2
42 
44 #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3
45 
46 #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4
47 #define CIRCUIT_PURPOSE_OR_MAX_ 4
48 
49 /* these circuits originate at this node */
50 
51 /* here's how circ client-side purposes work:
52  * normal circuits are C_GENERAL.
53  * circuits that are c_introducing are either on their way to
54  * becoming open, or they are open and waiting for a
55  * suitable rendcirc before they send the intro.
56  * circuits that are c_introduce_ack_wait have sent the intro,
57  * but haven't gotten a response yet.
58  * circuits that are c_establish_rend are either on their way
59  * to becoming open, or they are open and have sent the
60  * establish_rendezvous cell but haven't received an ack.
61  * circuits that are c_rend_ready are open and have received a
62  * rend ack, but haven't heard from the service yet. if they have a
63  * buildstate->pending_final_cpath then they're expecting a
64  * cell from the service, else they're not.
65  * circuits that are c_rend_ready_intro_acked are open, and
66  * some intro circ has sent its intro and received an ack.
67  * circuits that are c_rend_joined are open, have heard from
68  * the service, and are talking to it.
69  */
71 #define CIRCUIT_PURPOSE_C_GENERAL 5
72 #define CIRCUIT_PURPOSE_C_HS_MIN_ 6
73 
74 #define CIRCUIT_PURPOSE_C_INTRODUCING 6
75 
77 #define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT 7
78 
80 #define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED 8
81 
82 #define CIRCUIT_PURPOSE_C_ESTABLISH_REND 9
83 
84 #define CIRCUIT_PURPOSE_C_REND_READY 10
85 
87 #define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED 11
88 
89 #define CIRCUIT_PURPOSE_C_REND_JOINED 12
90 
91 #define CIRCUIT_PURPOSE_C_HSDIR_GET 13
92 #define CIRCUIT_PURPOSE_C_HS_MAX_ 13
93 
94 #define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT 14
95 #define CIRCUIT_PURPOSE_C_MAX_ 14
96 
97 #define CIRCUIT_PURPOSE_S_HS_MIN_ 15
98 
100 #define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO 15
101 
103 #define CIRCUIT_PURPOSE_S_INTRO 16
104 
106 #define CIRCUIT_PURPOSE_S_CONNECT_REND 17
107 
109 #define CIRCUIT_PURPOSE_S_REND_JOINED 18
110 
111 #define CIRCUIT_PURPOSE_S_HSDIR_POST 19
112 #define CIRCUIT_PURPOSE_S_HS_MAX_ 19
113 
115 #define CIRCUIT_PURPOSE_TESTING 20
116 
117 #define CIRCUIT_PURPOSE_CONTROLLER 21
118 
119 #define CIRCUIT_PURPOSE_PATH_BIAS_TESTING 22
120 
127 #define CIRCUIT_PURPOSE_HS_VANGUARDS 23
128 
129 #define CIRCUIT_PURPOSE_MAX_ 23
130 
132 #define CIRCUIT_PURPOSE_UNKNOWN 255
133 
136 #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>CIRCUIT_PURPOSE_OR_MAX_)
137 
139 #define CIRCUIT_PURPOSE_IS_CLIENT(p) \
140  ((p)> CIRCUIT_PURPOSE_OR_MAX_ && \
141  (p)<=CIRCUIT_PURPOSE_C_MAX_)
142 
143 #define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
144 
146 #define CIRCUIT_PURPOSE_IS_ESTABLISHED_REND(p) \
147  ((p) == CIRCUIT_PURPOSE_C_REND_JOINED || \
148  (p) == CIRCUIT_PURPOSE_S_REND_JOINED)
149 
150 #define CIRCUIT_IS_ORCIRC(c) (((circuit_t *)(c))->magic == OR_CIRCUIT_MAGIC)
151 
156 #define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING(p) \
157  ((p) == CIRCUIT_PURPOSE_C_GENERAL || \
158  (p) == CIRCUIT_PURPOSE_C_HSDIR_GET)
159 
163 const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
167 const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
168 
169 MOCK_DECL(smartlist_t *, circuit_get_global_list, (void));
173 void circuit_cache_opened_circuit_state(int circuits_are_opened);
174 
175 const char *circuit_state_to_string(int state);
176 const char *circuit_purpose_to_controller_string(uint8_t purpose);
177 const char *circuit_purpose_to_controller_hs_state_string(uint8_t purpose);
178 const char *circuit_purpose_to_string(uint8_t purpose);
179 void circuit_dump_by_conn(connection_t *conn, int severity);
181  channel_t *chan);
183  channel_t *chan);
187  channel_t *chan);
189  int reason_code);
190 void circuit_set_state(circuit_t *circ, uint8_t state);
191 void circuit_close_all_marked(void);
192 int32_t circuit_initial_package_window(void);
194 or_circuit_t *or_circuit_new(circid_t p_circ_id, channel_t *p_chan);
196  channel_t *chan);
197 circuit_t *
199  channel_t *chan);
202 void circuit_unlink_all_from_channel(channel_t *chan, int reason);
205  const rend_data_t *rend_data);
207  const uint8_t *digest, uint8_t purpose);
209  bool want_client_circ);
211 origin_circuit_t *circuit_get_next_service_hsdir_circ(origin_circuit_t *start);
213  extend_info_t *info, int flags);
218 MOCK_DECL(void, circuit_mark_for_close_, (circuit_t *circ, int reason,
219  int line, const char *file));
225  channel_t *chan);
227 
228 #define circuit_mark_for_close(c, reason) \
229  circuit_mark_for_close_((c), (reason), __LINE__, SHORT_FILE__)
230 
231 void assert_cpath_layer_ok(const crypt_path_t *cp);
232 MOCK_DECL(void, assert_circuit_ok,(const circuit_t *c));
233 void circuit_free_all(void);
234 void circuits_handle_oom(size_t current_allocation);
235 
237 
239 MOCK_DECL(void, channel_note_destroy_not_pending,
240  (channel_t *chan, circid_t id));
241 
243 
244 #ifdef CIRCUITLIST_PRIVATE
245 STATIC void circuit_free_(circuit_t *circ);
246 #define circuit_free(circ) FREE_AND_NULL(circuit_t, circuit_free_, (circ))
247 STATIC size_t n_cells_in_circ_queues(const circuit_t *c);
248 STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now);
249 STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now);
250 STATIC uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now);
251 #endif /* defined(CIRCUITLIST_PRIVATE) */
252 
253 #endif /* !defined(TOR_CIRCUITLIST_H) */
int32_t circuit_initial_package_window(void)
Definition: circuitlist.c:965
or_circuit_t * or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
Definition: circuitlist.c:1079
origin_circuit_t * circuit_get_next_service_rp_circ(origin_circuit_t *start)
Definition: circuitlist.c:1774
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *)
Definition: circuitlist.c:163
void circuit_set_p_circid_chan(or_circuit_t *circ, circid_t id, channel_t *chan)
Definition: circuitlist.c:448
time_t circuit_id_when_marked_unusable_on_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1557
void circuit_cache_opened_circuit_state(int circuits_are_opened)
Definition: circuitlist.c:740
void circuit_synchronize_written_or_bandwidth(const circuit_t *c, circuit_channel_direction_t dir)
Definition: circuitlist.c:2138
void circuit_mark_all_dirty_circs_as_unusable(void)
Definition: circuitlist.c:2110
void circuit_mark_all_unused_circs(void)
Definition: circuitlist.c:2091
void channel_mark_circid_usable(channel_t *chan, circid_t id)
Definition: circuitlist.c:383
smartlist_t * circuit_get_global_origin_circuit_list(void)
Definition: circuitlist.c:699
origin_circuit_t * circuit_get_ready_rend_circ_by_rend_data(const rend_data_t *rend_data)
Definition: circuitlist.c:1685
void circuit_dump_by_conn(connection_t *conn, int severity)
Definition: circuitlist.c:1382
const char * circuit_purpose_to_controller_string(uint8_t purpose)
Definition: circuitlist.c:778
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
Definition: circuitlist.c:471
origin_circuit_t * circuit_get_next_intro_circ(const origin_circuit_t *start, bool want_client_circ)
Definition: circuitlist.c:1722
circuit_t * circuit_get_by_circid_channel_even_if_marked(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1530
STATIC size_t n_cells_in_circ_queues(const circuit_t *c)
Definition: circuitlist.c:2500
const char * circuit_state_to_string(int state)
Definition: circuitlist.c:758
int circuit_any_opened_circuits(void)
Definition: circuitlist.c:714
void assert_cpath_layer_ok(const crypt_path_t *cp)
Definition: circuitlist.c:2790
or_circuit_t * TO_OR_CIRCUIT(circuit_t *)
Definition: circuitlist.c:151
STATIC uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now)
Definition: circuitlist.c:2613
void circuit_clear_testing_cell_stats(circuit_t *circ)
Definition: circuitlist.c:1100
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
Definition: circuitlist.c:1576
void channel_mark_circid_unusable(channel_t *chan, circid_t id)
Definition: circuitlist.c:350
int circuit_count_pending_on_channel(channel_t *chan)
Definition: circuitlist.c:605
void circuit_set_state(circuit_t *circ, uint8_t state)
Definition: circuitlist.c:542
origin_circuit_t * circuit_get_next_by_pk_and_purpose(origin_circuit_t *start, const uint8_t *digest, uint8_t purpose)
Definition: circuitlist.c:1808
origin_circuit_t * circuit_find_to_cannibalize(uint8_t purpose, extend_info_t *info, int flags)
Definition: circuitlist.c:1901
void circuits_handle_oom(size_t current_allocation)
Definition: circuitlist.c:2667
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
Definition: circuitlist.c:2011
int circuit_get_cpath_opened_len(const origin_circuit_t *)
Definition: circuitlist.c:2055
Header file containing circuit and connection identifier data for the whole HS subsytem.
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
Definition: circuitlist.c:2598
void circuit_free_all(void)
Definition: circuitlist.c:1279
const char * circuit_purpose_to_string(uint8_t purpose)
Definition: circuitlist.c:896
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
Definition: circuitlist.c:837
STATIC void circuit_free_(circuit_t *circ)
Definition: circuitlist.c:1113
void channel_note_destroy_pending(channel_t *chan, circid_t id)
Definition: circuitlist.c:406
void circuit_unlink_all_from_channel(channel_t *chan, int reason)
Definition: circuitlist.c:1593
STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
Definition: circuitlist.c:2533
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
Definition: circuitlist.c:2075
int circuit_get_cpath_len(origin_circuit_t *circ)
Definition: circuitlist.c:2039
void circuit_clear_cpath(origin_circuit_t *circ)
Definition: circuitlist.c:1255
uint32_t circid_t
Definition: or.h:608
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
Definition: circuitlist.c:574
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
int circuit_any_opened_circuits_cached(void)
Definition: circuitlist.c:751
origin_circuit_t * circuit_get_by_global_id(uint32_t id)
Definition: circuitlist.c:1423
Header file for ocirc_event.c.
void circuit_close_all_marked(void)
Definition: circuitlist.c:658
int circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
Definition: circuitlist.c:496
circuit_t * circuit_get_by_circid_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1515
circuit_channel_direction_t
Definition: or.h:494
origin_circuit_t * origin_circuit_new(void)
Definition: circuitlist.c:1007
circuit_status_event_t
Definition: ocirc_event.h:18
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1544