Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
channel.h
Go to the documentation of this file.
1/* * Copyright (c) 2012-2021, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * \file channel.h
6 * \brief Header file for channel.c
7 **/
8
9#ifndef TOR_CHANNEL_H
10#define TOR_CHANNEL_H
11
12#include "core/or/or.h"
13#include "core/or/circuitmux.h"
16
17#include "ext/ht.h"
18#include "tor_queue.h"
19
20#define tor_timer_t timeout
21struct tor_timer_t;
22
23/* Channel handler function pointer typedefs */
24typedef void (*channel_listener_fn_ptr)(channel_listener_t *, channel_t *);
25typedef void (*channel_cell_handler_fn_ptr)(channel_t *, cell_t *);
26
27/**
28 * This enum is used by channelpadding to decide when to pad channels.
29 * Don't add values to it without updating the checks in
30 * channelpadding_decide_to_pad_channel().
31 */
32typedef enum {
33 CHANNEL_USED_NOT_USED_FOR_FULL_CIRCS = 0,
34 CHANNEL_USED_FOR_FULL_CIRCS,
35 CHANNEL_USED_FOR_USER_TRAFFIC,
37
38/** Possible rules for generating circuit IDs on an OR connection. */
39typedef enum {
40 CIRC_ID_TYPE_LOWER=0, /**< Pick from 0..1<<15-1. */
41 CIRC_ID_TYPE_HIGHER=1, /**< Pick from 1<<15..1<<16-1. */
42 /** The other side of a connection is an OP: never create circuits to it,
43 * and let it use any circuit ID it wants. */
46#define circ_id_type_bitfield_t ENUM_BF(circ_id_type_t)
47
48/* channel states for channel_t */
49
50typedef enum {
51 /**
52 * Closed state - channel is inactive
53 *
54 * Permitted transitions from:
55 * - CHANNEL_STATE_CLOSING
56 * Permitted transitions to:
57 * - CHANNEL_STATE_OPENING
58 */
60 /**
61 * Opening state - channel is trying to connect
62 *
63 * Permitted transitions from:
64 * - CHANNEL_STATE_CLOSED
65 * Permitted transitions to:
66 * - CHANNEL_STATE_CLOSING
67 * - CHANNEL_STATE_ERROR
68 * - CHANNEL_STATE_OPEN
69 */
71 /**
72 * Open state - channel is active and ready for use
73 *
74 * Permitted transitions from:
75 * - CHANNEL_STATE_MAINT
76 * - CHANNEL_STATE_OPENING
77 * Permitted transitions to:
78 * - CHANNEL_STATE_CLOSING
79 * - CHANNEL_STATE_ERROR
80 * - CHANNEL_STATE_MAINT
81 */
83 /**
84 * Maintenance state - channel is temporarily offline for subclass specific
85 * maintenance activities such as TLS renegotiation.
86 *
87 * Permitted transitions from:
88 * - CHANNEL_STATE_OPEN
89 * Permitted transitions to:
90 * - CHANNEL_STATE_CLOSING
91 * - CHANNEL_STATE_ERROR
92 * - CHANNEL_STATE_OPEN
93 */
95 /**
96 * Closing state - channel is shutting down
97 *
98 * Permitted transitions from:
99 * - CHANNEL_STATE_MAINT
100 * - CHANNEL_STATE_OPENING
101 * - CHANNEL_STATE_OPEN
102 * Permitted transitions to:
103 * - CHANNEL_STATE_CLOSED,
104 * - CHANNEL_STATE_ERROR
105 */
107 /**
108 * Error state - channel has experienced a permanent error
109 *
110 * Permitted transitions from:
111 * - CHANNEL_STATE_CLOSING
112 * - CHANNEL_STATE_MAINT
113 * - CHANNEL_STATE_OPENING
114 * - CHANNEL_STATE_OPEN
115 * Permitted transitions to:
116 * - None
117 */
119 /**
120 * Placeholder for maximum state value
121 */
124
125/* channel listener states for channel_listener_t */
126
127typedef enum {
128 /**
129 * Closed state - channel listener is inactive
130 *
131 * Permitted transitions from:
132 * - CHANNEL_LISTENER_STATE_CLOSING
133 * Permitted transitions to:
134 * - CHANNEL_LISTENER_STATE_LISTENING
135 */
137 /**
138 * Listening state - channel listener is listening for incoming
139 * connections
140 *
141 * Permitted transitions from:
142 * - CHANNEL_LISTENER_STATE_CLOSED
143 * Permitted transitions to:
144 * - CHANNEL_LISTENER_STATE_CLOSING
145 * - CHANNEL_LISTENER_STATE_ERROR
146 */
148 /**
149 * Closing state - channel listener is shutting down
150 *
151 * Permitted transitions from:
152 * - CHANNEL_LISTENER_STATE_LISTENING
153 * Permitted transitions to:
154 * - CHANNEL_LISTENER_STATE_CLOSED,
155 * - CHANNEL_LISTENER_STATE_ERROR
156 */
158 /**
159 * Error state - channel listener has experienced a permanent error
160 *
161 * Permitted transitions from:
162 * - CHANNEL_STATE_CLOSING
163 * - CHANNEL_STATE_LISTENING
164 * Permitted transitions to:
165 * - None
166 */
168 /**
169 * Placeholder for maximum state value
170 */
173
174/**
175 * Channel struct; see the channel_t typedef in or.h. A channel is an
176 * abstract interface for the OR-to-OR connection, similar to connection_or_t,
177 * but without the strong coupling to the underlying TLS implementation. They
178 * are constructed by calling a protocol-specific function to open a channel
179 * to a particular node, and once constructed support the abstract operations
180 * defined below.
181 */
182struct channel_t {
183 /** Magic number for type-checking cast macros */
184 uint32_t magic;
185
186 /** List entry for hashtable for global-identifier lookup. */
187 HT_ENTRY(channel_t) gidmap_node;
188
189 /** Handle entry for handle-based lookup */
191
192 /** Current channel state */
194
195 /** Globally unique ID number for a channel over the lifetime of a Tor
196 * process. This may not be 0.
197 */
199
200 /** Should we expect to see this channel in the channel lists? */
201 unsigned char registered:1;
202
203 /** has this channel ever been open? */
204 unsigned int has_been_open:1;
205
206 /**
207 * This field indicates if the other side has enabled or disabled
208 * padding via either the link protocol version or
209 * channelpadding_negotiate cells.
210 *
211 * Clients can override this with ConnectionPadding in torrc to
212 * disable or force padding to relays, but relays cannot override the
213 * client's request.
214 */
215 unsigned int padding_enabled:1;
216
217 /** Cached value of our decision to pad (to avoid expensive
218 * checks during critical path statistics counting). */
219 unsigned int currently_padding:1;
220
221 /** Is there a pending netflow padding callback? */
223
224 /** Is our peer likely to consider this channel canonical? */
225 unsigned int is_canonical_to_peer:1;
226
227 /** Has this channel ever been used for non-directory traffic?
228 * Used to decide what channels to pad, and when. */
230
231 /** When should we send a cell for netflow padding? 0 means no padding is
232 * scheduled. */
233 monotime_coarse_t next_padding_time;
234
235 /** The callback pointer for the padding callbacks */
236 struct tor_timer_t *padding_timer;
237 /** The handle to this channel (to free on canceled timers) */
238 struct channel_handle_t *timer_handle;
239
240 /** If not UNSPEC, the address that the peer says we have. */
242
243 /**
244 * These two fields specify the minimum and maximum negotiated timeout
245 * values for inactivity (send or receive) before we decide to pad a
246 * channel. These fields can be set either via a PADDING_NEGOTIATE cell,
247 * or the torrc option ReducedConnectionPadding. The consensus parameters
248 * nf_ito_low and nf_ito_high are used to ensure that padding can only be
249 * negotiated to be less frequent than what is specified in the consensus.
250 * (This is done to prevent wingnut clients from requesting excessive
251 * padding).
252 *
253 * The actual timeout value is randomly chosen between these two values
254 * as per the table in channelpadding_get_netflow_inactive_timeout_ms(),
255 * after ensuring that these values do not specify lower timeouts than
256 * the consensus parameters.
257 *
258 * If these are 0, we have not negotiated or specified custom padding
259 * times, and instead use consensus defaults. */
261 uint16_t padding_timeout_high_ms;
262
263 /** Why did we close?
264 */
265 enum {
266 CHANNEL_NOT_CLOSING = 0,
267 CHANNEL_CLOSE_REQUESTED,
268 CHANNEL_CLOSE_FROM_BELOW,
269 CHANNEL_CLOSE_FOR_ERROR
271
272 /** State variable for use by the scheduler */
273 enum {
274 /**
275 * The channel is not open, or it has a full output buffer but no queued
276 * cells.
277 */
279 /**
280 * The channel has space on its output buffer to write, but no queued
281 * cells.
282 */
284 /**
285 * The scheduler has queued cells but no output buffer space to write.
286 */
288 /**
289 * The scheduler has both queued cells and output buffer space, and is
290 * eligible for the scheduler loop.
291 */
294
295 /** Heap index for use by the scheduler */
297
298 /** Timestamps for both cell channels and listeners */
299 time_t timestamp_created; /* Channel created */
300 time_t timestamp_active; /* Any activity */
301
302 /**
303 * This is a monotonic timestamp that marks when we
304 * believe the channel has actually sent or received data to/from
305 * the wire. Right now, it is used to determine when we should send
306 * a padding cell for channelpadding.
307 *
308 * XXX: Are we setting timestamp_xfer_ms in the right places to
309 * accurately reflect actual network data transfer? Or might this be
310 * very wrong wrt when bytes actually go on the wire?
311 */
312 monotime_coarse_t timestamp_xfer;
313
314 /* Methods implemented by the lower layer */
315
316 /** Free a channel */
317 void (*free_fn)(channel_t *);
318 /** Close an open channel */
319 void (*close)(channel_t *);
320 /** Describe the transport subclass for this channel */
321 const char * (*describe_transport)(channel_t *);
322 /** Optional method to dump transport-specific statistics on the channel */
323 void (*dumpstats)(channel_t *, int);
324
325 /** Registered handlers for incoming cells */
326 channel_cell_handler_fn_ptr cell_handler;
327
328 /* Methods implemented by the lower layer */
329
330 /**
331 * Ask the lower layer for an estimate of the average overhead for
332 * transmissions on this channel.
333 */
335 /*
336 * Ask the underlying transport what the remote endpoint address is, in a
337 * tor_addr_t. Write the address out to the provided tor_addr_t *, and
338 * return 1 if successful or 0 if no address available.
339 */
340 int (*get_remote_addr)(const channel_t *, tor_addr_t *);
341 int (*get_transport_name)(channel_t *chan, char **transport_out);
342
343 /**
344 * Get a human-readable text description of the remote endpoint, for
345 * logging.
346 */
347 const char * (*describe_peer)(const channel_t *);
348 /** Check if the lower layer has queued writes */
350 /**
351 * Ask the lower layer if this is 'canonical', for a transport-specific
352 * definition of canonical.
353 */
355 /** Check if this channel matches a specified extend_info_t */
357 /** Check if this channel matches a target address when extending */
359 /* Ask the lower layer how many bytes it has queued but not yet sent */
360 size_t (*num_bytes_queued)(channel_t *);
361 /* Ask the lower layer how many cells can be written */
362 int (*num_cells_writeable)(channel_t *);
363 /* Write a cell to an open channel */
364 int (*write_cell)(channel_t *, cell_t *);
365 /** Write a packed cell to an open channel */
367 /** Write a variable-length cell to an open channel */
369
370 /**
371 * Hash of the public RSA key for the other side's RSA identity key -- or
372 * zeroes if we don't have an RSA identity in mind for the other side, and
373 * it hasn't shown us one.
374 *
375 * Note that this is the RSA identity that we hope the other side has -- not
376 * necessarily its true identity. Don't believe this identity unless
377 * authentication has happened.
378 */
380 /**
381 * Ed25519 key for the other side of this channel -- or zeroes if we don't
382 * have an Ed25519 identity in mind for the other side, and it hasn't shown
383 * us one.
384 *
385 * Note that this is the identity that we hope the other side has -- not
386 * necessarily its true identity. Don't believe this identity unless
387 * authentication has happened.
388 */
390
391 /**
392 * Linked list of channels with the same RSA identity digest, for use with
393 * the digest->channel map
394 */
395 TOR_LIST_ENTRY(channel_t) next_with_same_id;
396
397 /** Circuit mux for circuits sending on this channel */
398 circuitmux_t *cmux;
399
400 /** Circuit ID generation stuff for use by circuitbuild.c */
401
402 /**
403 * When we send CREATE cells along this connection, which half of the
404 * space should we use?
405 */
406 circ_id_type_bitfield_t circ_id_type:2;
407 /* DOCDOC */
408 unsigned wide_circ_ids:1;
409
410 /** For how many circuits are we n_chan? What about p_chan? */
411 unsigned int num_n_circuits, num_p_circuits;
412
413 /**
414 * True iff this channel shouldn't get any new circs attached to it,
415 * because the connection is too old, or because there's a better one.
416 * More generally, this flag is used to note an unhealthy connection;
417 * for example, if a bad connection fails we shouldn't assume that the
418 * router itself has a problem.
419 */
420 unsigned int is_bad_for_new_circs:1;
421
422 /** True iff we have decided that the other end of this connection
423 * is a client or bridge relay. Connections with this flag set should never
424 * be used to satisfy an EXTEND request. */
425 unsigned int is_client:1;
426
427 /** Set if the channel was initiated remotely (came from a listener) */
428 unsigned int is_incoming:1;
429
430 /** Set by lower layer if this is local; i.e., everything it communicates
431 * with for this channel returns true for is_local_addr(). This is used
432 * to decide whether to declare reachability when we receive something on
433 * this channel in circuitbuild.c
434 */
435 unsigned int is_local:1;
436
437 /** Have we logged a warning about circID exhaustion on this channel?
438 * If so, when? */
440
441 /** Channel timestamps for cell channels */
442 time_t timestamp_client; /*(< Client used this, according to relay.c */
443 time_t timestamp_recv; /**< Cell received from lower layer */
444 time_t timestamp_xmit; /**< Cell sent to lower layer */
445
446 /** Timestamp for run_connection_housekeeping(). We update this once a
447 * second when we run housekeeping and find a circuit on this channel, and
448 * whenever we add a circuit to the channel. */
450
451 /** Unique ID for measuring direct network status requests;vtunneled ones
452 * come over a circuit_t, which has a dirreq_id field as well, but is a
453 * distinct namespace. */
454 uint64_t dirreq_id;
455
456 /** Channel counters for cells and bytes we have received. */
457 uint64_t n_cells_recved, n_bytes_recved;
458 /** Channel counters for cells and bytes we have sent. */
459 uint64_t n_cells_xmitted, n_bytes_xmitted;
460};
461
463 /** Current channel listener state */
465
466 /** Globally unique ID number for a channel over the lifetime of a Tor
467 * process.
468 */
470
471 /** Should we expect to see this channel in the channel lists? */
472 unsigned char registered:1;
473
474 /** Why did we close?
475 */
476 enum {
477 CHANNEL_LISTENER_NOT_CLOSING = 0,
478 CHANNEL_LISTENER_CLOSE_REQUESTED,
479 CHANNEL_LISTENER_CLOSE_FROM_BELOW,
480 CHANNEL_LISTENER_CLOSE_FOR_ERROR
482
483 /** Timestamps for both cell channels and listeners */
484 time_t timestamp_created; /* Channel created */
485 time_t timestamp_active; /* Any activity */
486
487 /* Methods implemented by the lower layer */
488
489 /** Free a channel */
491 /** Close an open channel */
493 /** Describe the transport subclass for this channel */
494 const char * (*describe_transport)(channel_listener_t *);
495 /** Optional method to dump transport-specific statistics on the channel */
497
498 /** Registered listen handler to call on incoming connection */
499 channel_listener_fn_ptr listener;
500
501 /** List of pending incoming connections */
503
504 /** Timestamps for listeners */
506
507 /** Counters for listeners */
508 uint64_t n_accepted;
509};
510
511/* Channel state manipulations */
512
515
519
520const char * channel_state_to_string(channel_state_t state);
521const char *
523
524/* Abstract channel operations */
525
528
531
532/* Channel callback registrations */
533
534/* Listener callback */
536 channel_listener_fn_ptr listener);
537
538/* Incoming cell callbacks */
539channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan);
540
542 channel_cell_handler_fn_ptr cell_handler);
543
544/* Clean up closed channels and channel listeners periodically; these are
545 * called from run_scheduled_events() in main.c.
546 */
547void channel_run_cleanup(void);
549
550/* Close all channels and deallocate everything */
551void channel_free_all(void);
552
553/* Dump some statistics in the log */
554void channel_dumpstats(int severity);
555void channel_listener_dumpstats(int severity);
556
557#ifdef CHANNEL_OBJECT_PRIVATE
558
559#ifdef CHANNEL_FILE_PRIVATE
560
563 channel_t *chan,
564 const tor_addr_t *target_ipv4_addr,
565 const tor_addr_t *target_ipv6_addr);
566#endif /* defined(CHANNEL_FILE_PRIVATE) */
567
568/* Channel operations for subclasses and internal use only */
569
570/* Initialize a newly allocated channel - do this first in subclass
571 * constructors.
572 */
573
574void channel_init(channel_t *chan);
576
577/* Channel registration/unregistration */
578void channel_register(channel_t *chan);
579void channel_unregister(channel_t *chan);
580
581/* Channel listener registration/unregistration */
584
585/* Close from below */
588void channel_closed(channel_t *chan);
589
590/* Free a channel */
591void channel_free_(channel_t *chan);
592#define channel_free(chan) FREE_AND_NULL(channel_t, channel_free_, (chan))
594#define channel_listener_free(chan_l) \
595 FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
596
597/* State/metadata setters */
598
603void channel_mark_local(channel_t *chan);
608 const char *identity_digest,
609 const struct ed25519_public_key_t *ed_identity);
610
612 channel_listener_state_t to_state);
613
614/* Timestamp updates */
619
623
624/* Incoming channel handling */
627 channel_t *incoming);
628
629/* Incoming cell handling */
630void channel_process_cell(channel_t *chan, cell_t *cell);
631
632/* Request from lower layer for more cells if available */
634 (channel_t *chan, ssize_t num_cells));
635
636/* Query if data available on this channel */
638
639/* Notify flushed outgoing for dirreq handling */
641
642/* Handle stuff we need to do on open like notifying circuits */
644
645#endif /* defined(CHANNEL_OBJECT_PRIVATE) */
646
647/* Helper functions to perform operations on channels */
648
649int channel_send_destroy(circid_t circ_id, channel_t *chan,
650 int reason);
651
652/*
653 * Outside abstract interfaces that should eventually get turned into
654 * something transport/address format independent.
655 */
656
657channel_t * channel_connect(const tor_addr_t *addr, uint16_t port,
658 const char *rsa_id_digest,
659 const struct ed25519_public_key_t *ed_id);
660
662 const char *rsa_id_digest,
663 const struct ed25519_public_key_t *ed_id,
664 const tor_addr_t *target_ipv4_addr,
665 const tor_addr_t *target_ipv6_addr,
666 bool for_origin_circ,
667 const char **msg_out,
668 int *launch_out));
669
670/* Ask which of two channels is better for circuit-extension purposes */
672
673/** Channel lookups
674 */
675
676channel_t * channel_find_by_global_id(uint64_t global_identifier);
677channel_t * channel_find_by_remote_identity(const char *rsa_id_digest,
678 const struct ed25519_public_key_t *ed_id);
679
680/** For things returned by channel_find_by_remote_digest(), walk the list.
681 * The RSA key will match for all returned elements; the Ed25519 key might not.
682 */
684
685/*
686 * Helper macros to lookup state of given channel.
687 */
688
689#define CHANNEL_IS_CLOSED(chan) (channel_is_in_state((chan), \
690 CHANNEL_STATE_CLOSED))
691#define CHANNEL_IS_OPENING(chan) (channel_is_in_state((chan), \
692 CHANNEL_STATE_OPENING))
693#define CHANNEL_IS_OPEN(chan) (channel_is_in_state((chan), \
694 CHANNEL_STATE_OPEN))
695#define CHANNEL_IS_MAINT(chan) (channel_is_in_state((chan), \
696 CHANNEL_STATE_MAINT))
697#define CHANNEL_IS_CLOSING(chan) (channel_is_in_state((chan), \
698 CHANNEL_STATE_CLOSING))
699#define CHANNEL_IS_ERROR(chan) (channel_is_in_state((chan), \
700 CHANNEL_STATE_ERROR))
701
702#define CHANNEL_FINISHED(chan) (CHANNEL_IS_CLOSED(chan) || \
703 CHANNEL_IS_ERROR(chan))
704
705#define CHANNEL_CONDEMNED(chan) (CHANNEL_IS_CLOSING(chan) || \
706 CHANNEL_FINISHED(chan))
707
708#define CHANNEL_CAN_HANDLE_CELLS(chan) (CHANNEL_IS_OPENING(chan) || \
709 CHANNEL_IS_OPEN(chan) || \
710 CHANNEL_IS_MAINT(chan))
711
712static inline int
713channel_is_in_state(channel_t *chan, channel_state_t state)
714{
715 return chan->state == state;
716}
717
718/*
719 * Metadata queries/updates
720 */
721
722const char * channel_describe_transport(channel_t *chan);
723MOCK_DECL(void, channel_dump_statistics, (channel_t *chan, int severity));
724void channel_dump_transport_statistics(channel_t *chan, int severity);
726 tor_addr_t *addr_out));
727MOCK_DECL(const char *, channel_describe_peer,(channel_t *chan));
732int channel_is_client(const channel_t *chan);
733int channel_is_local(channel_t *chan);
740 const char *rsa_id_digest,
741 const ed25519_public_key_t *ed_id);
742unsigned int channel_num_circuits(channel_t *chan);
744 crypto_pk_t *identity_rcvd,
745 int consider_identity));
747
750 int severity);
752 int severity);
754
755void channel_update_bad_for_new_circs(const char *digest, int force);
756
757/* Flow control queries */
759
760/* Timestamp queries */
761time_t channel_when_created(channel_t *chan);
764
765/* Counter queries */
767 const packed_cell_t *packed_cell,
768 circid_t *circid_out);
769
770/* Declare the handle helpers */
771HANDLE_DECL(channel, channel_t,)
772#define channel_handle_free(h) \
773 FREE_AND_NULL(channel_handle_t, channel_handle_free_, (h))
774#undef tor_timer_t
775
776#endif /* !defined(TOR_CHANNEL_H) */
void channel_timestamp_active(channel_t *chan)
Definition: channel.c:3147
void channel_listener_process_incoming(channel_listener_t *listener)
Definition: channel.c:1812
void channel_timestamp_recv(channel_t *chan)
Definition: channel.c:3214
void channel_set_identity_digest(channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
Definition: channel.c:1336
void channel_listener_unregister(channel_listener_t *chan_l)
Definition: channel.c:525
void channel_mark_local(channel_t *chan)
Definition: channel.c:3019
void channel_mark_incoming(channel_t *chan)
Definition: channel.c:2987
void channel_closed(channel_t *chan)
Definition: channel.c:1276
void channel_init_listener(channel_listener_t *chan_l)
Definition: channel.c:891
STATIC void channel_add_to_digest_map(channel_t *chan)
Definition: channel.c:561
channel_t * channel_get_for_extend(const char *rsa_id_digest, const ed25519_public_key_t *ed_id, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr, bool for_origin_circ, const char **msg_out, int *launch_out)
Definition: channel.c:2416
void channel_do_open_actions(channel_t *chan)
Definition: channel.c:1864
void channel_close_from_lower_layer(channel_t *chan)
Definition: channel.c:1221
void channel_process_cell(channel_t *chan, cell_t *cell)
Definition: channel.c:1983
void channel_change_state_open(channel_t *chan)
Definition: channel.c:1627
void channel_listener_queue_incoming(channel_listener_t *listener, channel_t *incoming)
Definition: channel.c:1932
void channel_timestamp_created(channel_t *chan)
Definition: channel.c:3111
void channel_register(channel_t *chan)
Definition: channel.c:387
void channel_listener_timestamp_created(channel_listener_t *chan_l)
Definition: channel.c:3127
void channel_listener_timestamp_active(channel_listener_t *chan_l)
Definition: channel.c:3164
void channel_listener_register(channel_listener_t *chan_l)
Definition: channel.c:484
channel_t * channel_connect(const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:2326
channel_t * channel_find_by_remote_identity(const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:698
void channel_mark_remote(channel_t *chan)
Definition: channel.c:3035
void channel_unregister(channel_t *chan)
Definition: channel.c:445
ssize_t channel_flush_some_cells(channel_t *chan, ssize_t num_cells)
Definition: channel.c:1735
STATIC bool channel_matches_target_addr_for_extend(channel_t *chan, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr)
Definition: channel.c:3315
void channel_close_for_error(channel_t *chan)
Definition: channel.c:1249
void channel_listener_free_(channel_listener_t *chan_l)
Definition: channel.c:959
void channel_listener_timestamp_accepted(channel_listener_t *chan_l)
Definition: channel.c:3181
void channel_notify_flushed(channel_t *chan)
Definition: channel.c:1795
void channel_timestamp_xmit(channel_t *chan)
Definition: channel.c:3234
void channel_clear_identity_digest(channel_t *chan)
Definition: channel.c:1307
void channel_clear_remote_end(channel_t *chan)
Definition: channel.c:1395
void channel_listener_change_state(channel_listener_t *chan_l, channel_listener_state_t to_state)
Definition: channel.c:1644
void channel_mark_outgoing(channel_t *chan)
Definition: channel.c:3064
int channel_more_to_flush(channel_t *chan)
Definition: channel.c:1778
void channel_init(channel_t *chan)
Definition: channel.c:852
void channel_free_(channel_t *chan)
Definition: channel.c:907
void channel_change_state(channel_t *chan, channel_state_t to_state)
Definition: channel.c:1617
int channel_has_queued_writes(channel_t *chan)
Definition: channel.c:2874
void channel_set_circid_type(channel_t *chan, crypto_pk_t *identity_rcvd, int consider_identity)
Definition: channel.c:3358
int channel_is_better(channel_t *a, channel_t *b)
Definition: channel.c:2344
int channel_is_bad_for_new_circs(channel_t *chan)
Definition: channel.c:2890
int channel_is_outgoing(channel_t *chan)
Definition: channel.c:3050
void channel_mark_as_used_for_origin_circuit(channel_t *chan)
Definition: channeltls.c:391
void channel_run_cleanup(void)
Definition: channel.c:2140
void channel_update_bad_for_new_circs(const char *digest, int force)
Definition: channel.c:3463
void channel_dumpstats(int severity)
Definition: channel.c:2078
void channel_timestamp_client(channel_t *chan)
Definition: channel.c:3198
void channel_listener_dump_statistics(channel_listener_t *chan_l, int severity)
Definition: channel.c:2744
void channel_set_cell_handlers(channel_t *chan, channel_cell_handler_fn_ptr cell_handler)
Definition: channel.c:1107
void channel_mark_client(channel_t *chan)
Definition: channel.c:2931
time_t channel_when_last_xmit(channel_t *chan)
Definition: channel.c:3278
void channel_listener_run_cleanup(void)
Definition: channel.c:2166
int channel_listener_state_can_transition(channel_listener_state_t from, channel_listener_state_t to)
Definition: channel.c:284
int channel_state_is_valid(channel_state_t state)
Definition: channel.c:186
void channel_listener_mark_for_close(channel_listener_t *chan_l)
Definition: channel.c:1181
channel_state_t
Definition: channel.h:50
@ CHANNEL_STATE_OPEN
Definition: channel.h:82
@ CHANNEL_STATE_CLOSED
Definition: channel.h:59
@ CHANNEL_STATE_MAINT
Definition: channel.h:94
@ CHANNEL_STATE_OPENING
Definition: channel.h:70
@ CHANNEL_STATE_CLOSING
Definition: channel.h:106
@ CHANNEL_STATE_ERROR
Definition: channel.h:118
@ CHANNEL_STATE_LAST
Definition: channel.h:122
void channel_check_for_duplicates(void)
Definition: channel.c:749
int channel_is_canonical(channel_t *chan)
Definition: channel.c:2958
circ_id_type_t
Definition: channel.h:39
@ CIRC_ID_TYPE_NEITHER
Definition: channel.h:44
@ CIRC_ID_TYPE_LOWER
Definition: channel.h:40
@ CIRC_ID_TYPE_HIGHER
Definition: channel.h:41
int channel_listener_state_is_valid(channel_listener_state_t state)
Definition: channel.c:211
const char * channel_state_to_string(channel_state_t state)
Definition: channel.c:316
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
Definition: channel.c:3295
channel_listener_state_t
Definition: channel.h:127
@ CHANNEL_LISTENER_STATE_ERROR
Definition: channel.h:167
@ CHANNEL_LISTENER_STATE_LAST
Definition: channel.h:171
@ CHANNEL_LISTENER_STATE_LISTENING
Definition: channel.h:147
@ CHANNEL_LISTENER_STATE_CLOSING
Definition: channel.h:157
@ CHANNEL_LISTENER_STATE_CLOSED
Definition: channel.h:136
int channel_state_can_transition(channel_state_t from, channel_state_t to)
Definition: channel.c:238
const char * channel_describe_transport(channel_t *chan)
Definition: channel.c:2515
int channel_remote_identity_matches(const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:668
channel_usage_info_t
Definition: channel.h:32
time_t channel_when_last_client(channel_t *chan)
Definition: channel.c:3267
void channel_listener_set_listener_fn(channel_listener_t *chan, channel_listener_fn_ptr listener)
Definition: channel.c:1067
const char * channel_listener_describe_transport(channel_listener_t *chan_l)
Definition: channel.c:2530
void channel_listener_dump_transport_statistics(channel_listener_t *chan_l, int severity)
Definition: channel.c:2823
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
Definition: channel.c:2038
void channel_mark_bad_for_new_circs(channel_t *chan)
Definition: channel.c:2903
int channel_is_incoming(channel_t *chan)
Definition: channel.c:2973
int channel_is_client(const channel_t *chan)
Definition: channel.c:2918
const char * channel_listener_state_to_string(channel_listener_state_t state)
Definition: channel.c:351
channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan)
Definition: channel.c:1090
int packed_cell_is_destroy(channel_t *chan, const packed_cell_t *packed_cell, circid_t *circid_out)
Definition: channel.c:2012
void channel_listener_dumpstats(int severity)
Definition: channel.c:2109
int channel_is_local(channel_t *chan)
Definition: channel.c:3004
int channel_num_cells_writeable(channel_t *chan)
Definition: channel.c:3081
channel_t * channel_find_by_global_id(uint64_t global_identifier)
Definition: channel.c:651
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
Definition: channel.c:2860
channel_t * channel_next_with_rsa_identity(channel_t *chan)
Definition: channel.c:732
const char * channel_describe_peer(channel_t *chan)
Definition: channel.c:2840
void channel_mark_for_close(channel_t *chan)
Definition: channel.c:1142
void channel_dump_statistics(channel_t *chan, int severity)
Definition: channel.c:2544
void channel_free_all(void)
Definition: channel.c:2253
void channel_dump_transport_statistics(channel_t *chan, int severity)
Definition: channel.c:2810
unsigned int channel_num_circuits(channel_t *chan)
Definition: channel.c:3341
void channel_clear_client(channel_t *chan)
Definition: channel.c:2944
int channel_write_packed_cell(channel_t *chan, packed_cell_t *cell)
Definition: channel.c:1489
time_t channel_when_created(channel_t *chan)
Definition: channel.c:3256
Header file for circuitmux.c.
Header for crypto_ed25519.c.
#define DIGEST_LEN
Definition: digest_sizes.h:20
Macros for C weak-handle implementation.
Master header file for Tor-specific functionality.
uint32_t circid_t
Definition: or.h:584
Definition: cell_st.h:17
channel_listener_state_t state
Definition: channel.h:464
enum channel_listener_t::@11 reason_for_closing
void(* dumpstats)(channel_listener_t *, int)
Definition: channel.h:496
uint64_t global_identifier
Definition: channel.h:469
void(* free_fn)(channel_listener_t *)
Definition: channel.h:490
unsigned char registered
Definition: channel.h:472
smartlist_t * incoming_list
Definition: channel.h:502
uint64_t n_accepted
Definition: channel.h:508
time_t timestamp_created
Definition: channel.h:484
channel_listener_fn_ptr listener
Definition: channel.h:499
time_t timestamp_accepted
Definition: channel.h:505
void(* close)(channel_listener_t *)
Definition: channel.h:492
unsigned int is_local
Definition: channel.h:435
void(* free_fn)(channel_t *)
Definition: channel.h:317
channel_state_t state
Definition: channel.h:193
int sched_heap_idx
Definition: channel.h:296
int(* is_canonical)(channel_t *)
Definition: channel.h:354
void(* close)(channel_t *)
Definition: channel.h:319
uint16_t padding_timeout_low_ms
Definition: channel.h:260
monotime_coarse_t next_padding_time
Definition: channel.h:233
void(* dumpstats)(channel_t *, int)
Definition: channel.h:323
enum channel_t::@9 reason_for_closing
time_t timestamp_last_had_circuits
Definition: channel.h:449
@ SCHED_CHAN_IDLE
Definition: channel.h:278
@ SCHED_CHAN_WAITING_FOR_CELLS
Definition: channel.h:283
@ SCHED_CHAN_WAITING_TO_WRITE
Definition: channel.h:287
@ SCHED_CHAN_PENDING
Definition: channel.h:292
unsigned int num_n_circuits
Definition: channel.h:411
int(* matches_extend_info)(channel_t *, extend_info_t *)
Definition: channel.h:356
circ_id_type_bitfield_t circ_id_type
Definition: channel.h:406
uint64_t dirreq_id
Definition: channel.h:454
unsigned int padding_enabled
Definition: channel.h:215
char identity_digest[DIGEST_LEN]
Definition: channel.h:379
uint32_t magic
Definition: channel.h:184
uint64_t n_cells_xmitted
Definition: channel.h:459
uint64_t n_cells_recved
Definition: channel.h:457
uint64_t global_identifier
Definition: channel.h:198
int(* write_packed_cell)(channel_t *, packed_cell_t *)
Definition: channel.h:366
channel_usage_info_t channel_usage
Definition: channel.h:229
HT_ENTRY(channel_t) gidmap_node
TOR_LIST_ENTRY(channel_t) next_with_same_id
struct channel_handle_t * timer_handle
Definition: channel.h:238
unsigned char registered
Definition: channel.h:201
time_t timestamp_client
Definition: channel.h:442
unsigned int is_incoming
Definition: channel.h:428
double(* get_overhead_estimate)(channel_t *)
Definition: channel.h:334
time_t timestamp_xmit
Definition: channel.h:444
unsigned int pending_padding_callback
Definition: channel.h:222
tor_addr_t addr_according_to_peer
Definition: channel.h:241
channel_cell_handler_fn_ptr cell_handler
Definition: channel.h:326
int(* matches_target)(channel_t *, const tor_addr_t *)
Definition: channel.h:358
time_t timestamp_recv
Definition: channel.h:443
struct ed25519_public_key_t ed25519_identity
Definition: channel.h:389
time_t timestamp_created
Definition: channel.h:299
unsigned int has_been_open
Definition: channel.h:204
monotime_coarse_t timestamp_xfer
Definition: channel.h:312
unsigned int currently_padding
Definition: channel.h:219
unsigned int is_client
Definition: channel.h:425
unsigned int is_bad_for_new_circs
Definition: channel.h:420
unsigned int is_canonical_to_peer
Definition: channel.h:225
enum channel_t::@10 scheduler_state
int(* write_var_cell)(channel_t *, var_cell_t *)
Definition: channel.h:368
circuitmux_t * cmux
Definition: channel.h:398
struct tor_timer_t * padding_timer
Definition: channel.h:236
HANDLE_ENTRY(channel, channel_t)
ratelim_t last_warned_circ_ids_exhausted
Definition: channel.h:439
int(* has_queued_writes)(channel_t *)
Definition: channel.h:349
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127