tor  0.4.2.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 
96 #define CIRCUIT_PURPOSE_C_CIRCUIT_PADDING 15
97 #define CIRCUIT_PURPOSE_C_MAX_ 15
98 
99 #define CIRCUIT_PURPOSE_S_HS_MIN_ 16
100 
102 #define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO 16
103 
105 #define CIRCUIT_PURPOSE_S_INTRO 17
106 
108 #define CIRCUIT_PURPOSE_S_CONNECT_REND 18
109 
111 #define CIRCUIT_PURPOSE_S_REND_JOINED 19
112 
113 #define CIRCUIT_PURPOSE_S_HSDIR_POST 20
114 #define CIRCUIT_PURPOSE_S_HS_MAX_ 20
115 
117 #define CIRCUIT_PURPOSE_TESTING 21
118 
119 #define CIRCUIT_PURPOSE_CONTROLLER 22
120 
121 #define CIRCUIT_PURPOSE_PATH_BIAS_TESTING 23
122 
129 #define CIRCUIT_PURPOSE_HS_VANGUARDS 24
130 
131 #define CIRCUIT_PURPOSE_MAX_ 24
132 
134 #define CIRCUIT_PURPOSE_UNKNOWN 255
135 
138 #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>CIRCUIT_PURPOSE_OR_MAX_)
139 
141 #define CIRCUIT_PURPOSE_IS_CLIENT(p) \
142  ((p)> CIRCUIT_PURPOSE_OR_MAX_ && \
143  (p)<=CIRCUIT_PURPOSE_C_MAX_)
144 
145 #define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
146 
148 #define CIRCUIT_PURPOSE_IS_ESTABLISHED_REND(p) \
149  ((p) == CIRCUIT_PURPOSE_C_REND_JOINED || \
150  (p) == CIRCUIT_PURPOSE_S_REND_JOINED)
151 
152 #define CIRCUIT_IS_ORCIRC(c) (((circuit_t *)(c))->magic == OR_CIRCUIT_MAGIC)
153 
158 #define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING(p) \
159  ((p) == CIRCUIT_PURPOSE_C_GENERAL || \
160  (p) == CIRCUIT_PURPOSE_C_HSDIR_GET)
161 
165 const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
169 const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
170 
171 MOCK_DECL(smartlist_t *, circuit_get_global_list, (void));
175 void circuit_cache_opened_circuit_state(int circuits_are_opened);
176 
177 const char *circuit_state_to_string(int state);
178 const char *circuit_purpose_to_controller_string(uint8_t purpose);
179 const char *circuit_purpose_to_controller_hs_state_string(uint8_t purpose);
180 const char *circuit_purpose_to_string(uint8_t purpose);
181 void circuit_dump_by_conn(connection_t *conn, int severity);
183  channel_t *chan);
185  channel_t *chan);
189  channel_t *chan);
191  int reason_code);
192 void circuit_set_state(circuit_t *circ, uint8_t state);
193 void circuit_close_all_marked(void);
194 int32_t circuit_initial_package_window(void);
196 or_circuit_t *or_circuit_new(circid_t p_circ_id, channel_t *p_chan);
198  channel_t *chan);
199 circuit_t *
201  channel_t *chan);
204 void circuit_unlink_all_from_channel(channel_t *chan, int reason);
207  const rend_data_t *rend_data);
209  const uint8_t *digest, uint8_t purpose);
211  bool want_client_circ);
213 origin_circuit_t *circuit_get_next_service_hsdir_circ(origin_circuit_t *start);
215  extend_info_t *info, int flags);
220 MOCK_DECL(void, circuit_mark_for_close_, (circuit_t *circ, int reason,
221  int line, const char *cfile));
227  channel_t *chan);
229 
230 #define circuit_mark_for_close(c, reason) \
231  circuit_mark_for_close_((c), (reason), __LINE__, SHORT_FILE__)
232 
233 MOCK_DECL(void, assert_circuit_ok,(const circuit_t *c));
234 void circuit_free_all(void);
235 void circuits_handle_oom(size_t current_allocation);
236 
238 
240 MOCK_DECL(void, channel_note_destroy_not_pending,
241  (channel_t *chan, circid_t id));
242 
244 
245 #ifdef CIRCUITLIST_PRIVATE
246 STATIC void circuit_free_(circuit_t *circ);
247 #define circuit_free(circ) FREE_AND_NULL(circuit_t, circuit_free_, (circ))
248 STATIC size_t n_cells_in_circ_queues(const circuit_t *c);
249 STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now);
250 STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now);
251 STATIC uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now);
252 #endif /* defined(CIRCUITLIST_PRIVATE) */
253 
254 #endif /* !defined(TOR_CIRCUITLIST_H) */
int32_t circuit_initial_package_window(void)
Definition: circuitlist.c:970
or_circuit_t * or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
Definition: circuitlist.c:1085
origin_circuit_t * circuit_get_next_service_rp_circ(origin_circuit_t *start)
Definition: circuitlist.c:1770
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:1553
void circuit_cache_opened_circuit_state(int circuits_are_opened)
Definition: circuitlist.c:739
void circuit_synchronize_written_or_bandwidth(const circuit_t *c, circuit_channel_direction_t dir)
Definition: circuitlist.c:2134
void circuit_mark_all_dirty_circs_as_unusable(void)
Definition: circuitlist.c:2106
void circuit_mark_all_unused_circs(void)
Definition: circuitlist.c:2087
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:698
origin_circuit_t * circuit_get_ready_rend_circ_by_rend_data(const rend_data_t *rend_data)
Definition: circuitlist.c:1681
void circuit_dump_by_conn(connection_t *conn, int severity)
Definition: circuitlist.c:1378
const char * circuit_purpose_to_controller_string(uint8_t purpose)
Definition: circuitlist.c:777
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:1718
circuit_t * circuit_get_by_circid_channel_even_if_marked(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1526
STATIC size_t n_cells_in_circ_queues(const circuit_t *c)
Definition: circuitlist.c:2497
const char * circuit_state_to_string(int state)
Definition: circuitlist.c:757
int circuit_any_opened_circuits(void)
Definition: circuitlist.c:713
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:2610
void circuit_clear_testing_cell_stats(circuit_t *circ)
Definition: circuitlist.c:1106
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
Definition: circuitlist.c:1572
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:604
void circuit_set_state(circuit_t *circ, uint8_t state)
Definition: circuitlist.c:540
origin_circuit_t * circuit_get_next_by_pk_and_purpose(origin_circuit_t *start, const uint8_t *digest, uint8_t purpose)
Definition: circuitlist.c:1804
origin_circuit_t * circuit_find_to_cannibalize(uint8_t purpose, extend_info_t *info, int flags)
Definition: circuitlist.c:1897
void circuits_handle_oom(size_t current_allocation)
Definition: circuitlist.c:2664
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
Definition: circuitlist.c:2007
int circuit_get_cpath_opened_len(const origin_circuit_t *)
Definition: circuitlist.c:2051
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:2595
void circuit_free_all(void)
Definition: circuitlist.c:1291
const char * circuit_purpose_to_string(uint8_t purpose)
Definition: circuitlist.c:898
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
Definition: circuitlist.c:838
STATIC void circuit_free_(circuit_t *circ)
Definition: circuitlist.c:1119
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:1589
STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
Definition: circuitlist.c:2530
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
Definition: circuitlist.c:2071
int circuit_get_cpath_len(origin_circuit_t *circ)
Definition: circuitlist.c:2035
void circuit_clear_cpath(origin_circuit_t *circ)
Definition: circuitlist.c:1267
uint32_t circid_t
Definition: or.h:608
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
Definition: circuitlist.c:573
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:750
origin_circuit_t * circuit_get_by_global_id(uint32_t id)
Definition: circuitlist.c:1419
Header file for ocirc_event.c.
void circuit_close_all_marked(void)
Definition: circuitlist.c:657
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:1511
circuit_channel_direction_t
Definition: or.h:494
origin_circuit_t * origin_circuit_new(void)
Definition: circuitlist.c:1013
circuit_status_event_t
Definition: ocirc_event.h:19
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1540