Tor  0.4.7.0-alpha-dev
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"
14 #include "lib/container/handles.h"
16 
17 #include "ext/ht.h"
18 #include "tor_queue.h"
19 
20 #define tor_timer_t timeout
21 struct tor_timer_t;
22 
23 /* Channel handler function pointer typedefs */
24 typedef void (*channel_listener_fn_ptr)(channel_listener_t *, channel_t *);
25 typedef 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  */
32 typedef 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. */
39 typedef 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 
50 typedef 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_OPEN
101  * Permitted transitions to:
102  * - CHANNEL_STATE_CLOSED,
103  * - CHANNEL_STATE_ERROR
104  */
106  /**
107  * Error state - channel has experienced a permanent error
108  *
109  * Permitted transitions from:
110  * - CHANNEL_STATE_CLOSING
111  * - CHANNEL_STATE_MAINT
112  * - CHANNEL_STATE_OPENING
113  * - CHANNEL_STATE_OPEN
114  * Permitted transitions to:
115  * - None
116  */
118  /**
119  * Placeholder for maximum state value
120  */
123 
124 /* channel listener states for channel_listener_t */
125 
126 typedef enum {
127  /**
128  * Closed state - channel listener is inactive
129  *
130  * Permitted transitions from:
131  * - CHANNEL_LISTENER_STATE_CLOSING
132  * Permitted transitions to:
133  * - CHANNEL_LISTENER_STATE_LISTENING
134  */
136  /**
137  * Listening state - channel listener is listening for incoming
138  * connections
139  *
140  * Permitted transitions from:
141  * - CHANNEL_LISTENER_STATE_CLOSED
142  * Permitted transitions to:
143  * - CHANNEL_LISTENER_STATE_CLOSING
144  * - CHANNEL_LISTENER_STATE_ERROR
145  */
147  /**
148  * Closing state - channel listener is shutting down
149  *
150  * Permitted transitions from:
151  * - CHANNEL_LISTENER_STATE_LISTENING
152  * Permitted transitions to:
153  * - CHANNEL_LISTENER_STATE_CLOSED,
154  * - CHANNEL_LISTENER_STATE_ERROR
155  */
157  /**
158  * Error state - channel listener has experienced a permanent error
159  *
160  * Permitted transitions from:
161  * - CHANNEL_STATE_CLOSING
162  * - CHANNEL_STATE_LISTENING
163  * Permitted transitions to:
164  * - None
165  */
167  /**
168  * Placeholder for maximum state value
169  */
172 
173 /**
174  * Channel struct; see the channel_t typedef in or.h. A channel is an
175  * abstract interface for the OR-to-OR connection, similar to connection_or_t,
176  * but without the strong coupling to the underlying TLS implementation. They
177  * are constructed by calling a protocol-specific function to open a channel
178  * to a particular node, and once constructed support the abstract operations
179  * defined below.
180  */
181 struct channel_t {
182  /** Magic number for type-checking cast macros */
183  uint32_t magic;
184 
185  /** List entry for hashtable for global-identifier lookup. */
186  HT_ENTRY(channel_t) gidmap_node;
187 
188  /** Handle entry for handle-based lookup */
190 
191  /** Current channel state */
193 
194  /** Globally unique ID number for a channel over the lifetime of a Tor
195  * process. This may not be 0.
196  */
198 
199  /** Should we expect to see this channel in the channel lists? */
200  unsigned char registered:1;
201 
202  /** has this channel ever been open? */
203  unsigned int has_been_open:1;
204 
205  /**
206  * This field indicates if the other side has enabled or disabled
207  * padding via either the link protocol version or
208  * channelpadding_negotiate cells.
209  *
210  * Clients can override this with ConnectionPadding in torrc to
211  * disable or force padding to relays, but relays cannot override the
212  * client's request.
213  */
214  unsigned int padding_enabled:1;
215 
216  /** Cached value of our decision to pad (to avoid expensive
217  * checks during critical path statistics counting). */
218  unsigned int currently_padding:1;
219 
220  /** Is there a pending netflow padding callback? */
221  unsigned int pending_padding_callback:1;
222 
223  /** Is our peer likely to consider this channel canonical? */
224  unsigned int is_canonical_to_peer:1;
225 
226  /** Has this channel ever been used for non-directory traffic?
227  * Used to decide what channels to pad, and when. */
229 
230  /** When should we send a cell for netflow padding? 0 means no padding is
231  * scheduled. */
232  monotime_coarse_t next_padding_time;
233 
234  /** The callback pointer for the padding callbacks */
235  struct tor_timer_t *padding_timer;
236  /** The handle to this channel (to free on canceled timers) */
237  struct channel_handle_t *timer_handle;
238 
239  /** If not UNSPEC, the address that the peer says we have. */
241 
242  /**
243  * These two fields specify the minimum and maximum negotiated timeout
244  * values for inactivity (send or receive) before we decide to pad a
245  * channel. These fields can be set either via a PADDING_NEGOTIATE cell,
246  * or the torrc option ReducedConnectionPadding. The consensus parameters
247  * nf_ito_low and nf_ito_high are used to ensure that padding can only be
248  * negotiated to be less frequent than what is specified in the consensus.
249  * (This is done to prevent wingnut clients from requesting excessive
250  * padding).
251  *
252  * The actual timeout value is randomly chosen between these two values
253  * as per the table in channelpadding_get_netflow_inactive_timeout_ms(),
254  * after ensuring that these values do not specify lower timeouts than
255  * the consensus parameters.
256  *
257  * If these are 0, we have not negotiated or specified custom padding
258  * times, and instead use consensus defaults. */
260  uint16_t padding_timeout_high_ms;
261 
262  /** Why did we close?
263  */
264  enum {
265  CHANNEL_NOT_CLOSING = 0,
266  CHANNEL_CLOSE_REQUESTED,
267  CHANNEL_CLOSE_FROM_BELOW,
268  CHANNEL_CLOSE_FOR_ERROR
270 
271  /** State variable for use by the scheduler */
272  enum {
273  /**
274  * The channel is not open, or it has a full output buffer but no queued
275  * cells.
276  */
278  /**
279  * The channel has space on its output buffer to write, but no queued
280  * cells.
281  */
283  /**
284  * The scheduler has queued cells but no output buffer space to write.
285  */
287  /**
288  * The scheduler has both queued cells and output buffer space, and is
289  * eligible for the scheduler loop.
290  */
293 
294  /** Heap index for use by the scheduler */
296 
297  /** Timestamps for both cell channels and listeners */
298  time_t timestamp_created; /* Channel created */
299  time_t timestamp_active; /* Any activity */
300 
301  /**
302  * This is a monotonic timestamp that marks when we
303  * believe the channel has actually sent or received data to/from
304  * the wire. Right now, it is used to determine when we should send
305  * a padding cell for channelpadding.
306  *
307  * XXX: Are we setting timestamp_xfer_ms in the right places to
308  * accurately reflect actual network data transfer? Or might this be
309  * very wrong wrt when bytes actually go on the wire?
310  */
311  monotime_coarse_t timestamp_xfer;
312 
313  /* Methods implemented by the lower layer */
314 
315  /** Free a channel */
316  void (*free_fn)(channel_t *);
317  /** Close an open channel */
318  void (*close)(channel_t *);
319  /** Describe the transport subclass for this channel */
320  const char * (*describe_transport)(channel_t *);
321  /** Optional method to dump transport-specific statistics on the channel */
322  void (*dumpstats)(channel_t *, int);
323 
324  /** Registered handlers for incoming cells */
325  channel_cell_handler_fn_ptr cell_handler;
326 
327  /* Methods implemented by the lower layer */
328 
329  /**
330  * Ask the lower layer for an estimate of the average overhead for
331  * transmissions on this channel.
332  */
334  /*
335  * Ask the underlying transport what the remote endpoint address is, in a
336  * tor_addr_t. Write the address out to the provided tor_addr_t *, and
337  * return 1 if successful or 0 if no address available.
338  */
339  int (*get_remote_addr)(const channel_t *, tor_addr_t *);
340  int (*get_transport_name)(channel_t *chan, char **transport_out);
341 
342  /**
343  * Get a human-readable text description of the remote endpoint, for
344  * logging.
345  */
346  const char * (*describe_peer)(const channel_t *);
347  /** Check if the lower layer has queued writes */
349  /**
350  * Ask the lower layer if this is 'canonical', for a transport-specific
351  * definition of canonical.
352  */
354  /** Check if this channel matches a specified extend_info_t */
356  /** Check if this channel matches a target address when extending */
357  int (*matches_target)(channel_t *, const tor_addr_t *);
358  /* Ask the lower layer how many bytes it has queued but not yet sent */
359  size_t (*num_bytes_queued)(channel_t *);
360  /* Ask the lower layer how many cells can be written */
361  int (*num_cells_writeable)(channel_t *);
362  /* Write a cell to an open channel */
363  int (*write_cell)(channel_t *, cell_t *);
364  /** Write a packed cell to an open channel */
366  /** Write a variable-length cell to an open channel */
368 
369  /**
370  * Hash of the public RSA key for the other side's RSA identity key -- or
371  * zeroes if we don't have an RSA identity in mind for the other side, and
372  * it hasn't shown us one.
373  *
374  * Note that this is the RSA identity that we hope the other side has -- not
375  * necessarily its true identity. Don't believe this identity unless
376  * authentication has happened.
377  */
379  /**
380  * Ed25519 key for the other side of this channel -- or zeroes if we don't
381  * have an Ed25519 identity in mind for the other side, and it hasn't shown
382  * us one.
383  *
384  * Note that this is the identity that we hope the other side has -- not
385  * necessarily its true identity. Don't believe this identity unless
386  * authentication has happened.
387  */
389 
390  /**
391  * Linked list of channels with the same RSA identity digest, for use with
392  * the digest->channel map
393  */
394  TOR_LIST_ENTRY(channel_t) next_with_same_id;
395 
396  /** Circuit mux for circuits sending on this channel */
397  circuitmux_t *cmux;
398 
399  /** Circuit ID generation stuff for use by circuitbuild.c */
400 
401  /**
402  * When we send CREATE cells along this connection, which half of the
403  * space should we use?
404  */
405  circ_id_type_bitfield_t circ_id_type:2;
406  /* DOCDOC */
407  unsigned wide_circ_ids:1;
408 
409  /** For how many circuits are we n_chan? What about p_chan? */
410  unsigned int num_n_circuits, num_p_circuits;
411 
412  /**
413  * True iff this channel shouldn't get any new circs attached to it,
414  * because the connection is too old, or because there's a better one.
415  * More generally, this flag is used to note an unhealthy connection;
416  * for example, if a bad connection fails we shouldn't assume that the
417  * router itself has a problem.
418  */
419  unsigned int is_bad_for_new_circs:1;
420 
421  /** True iff we have decided that the other end of this connection
422  * is a client or bridge relay. Connections with this flag set should never
423  * be used to satisfy an EXTEND request. */
424  unsigned int is_client:1;
425 
426  /** Set if the channel was initiated remotely (came from a listener) */
427  unsigned int is_incoming:1;
428 
429  /** Set by lower layer if this is local; i.e., everything it communicates
430  * with for this channel returns true for is_local_addr(). This is used
431  * to decide whether to declare reachability when we receive something on
432  * this channel in circuitbuild.c
433  */
434  unsigned int is_local:1;
435 
436  /** Have we logged a warning about circID exhaustion on this channel?
437  * If so, when? */
439 
440  /** Channel timestamps for cell channels */
441  time_t timestamp_client; /*(< Client used this, according to relay.c */
442  time_t timestamp_recv; /**< Cell received from lower layer */
443  time_t timestamp_xmit; /**< Cell sent to lower layer */
444 
445  /** Timestamp for run_connection_housekeeping(). We update this once a
446  * second when we run housekeeping and find a circuit on this channel, and
447  * whenever we add a circuit to the channel. */
449 
450  /** Unique ID for measuring direct network status requests;vtunneled ones
451  * come over a circuit_t, which has a dirreq_id field as well, but is a
452  * distinct namespace. */
453  uint64_t dirreq_id;
454 
455  /** Channel counters for cells and bytes we have received. */
456  uint64_t n_cells_recved, n_bytes_recved;
457  /** Channel counters for cells and bytes we have sent. */
458  uint64_t n_cells_xmitted, n_bytes_xmitted;
459 };
460 
462  /** Current channel listener state */
464 
465  /** Globally unique ID number for a channel over the lifetime of a Tor
466  * process.
467  */
469 
470  /** Should we expect to see this channel in the channel lists? */
471  unsigned char registered:1;
472 
473  /** Why did we close?
474  */
475  enum {
476  CHANNEL_LISTENER_NOT_CLOSING = 0,
477  CHANNEL_LISTENER_CLOSE_REQUESTED,
478  CHANNEL_LISTENER_CLOSE_FROM_BELOW,
479  CHANNEL_LISTENER_CLOSE_FOR_ERROR
481 
482  /** Timestamps for both cell channels and listeners */
483  time_t timestamp_created; /* Channel created */
484  time_t timestamp_active; /* Any activity */
485 
486  /* Methods implemented by the lower layer */
487 
488  /** Free a channel */
490  /** Close an open channel */
492  /** Describe the transport subclass for this channel */
493  const char * (*describe_transport)(channel_listener_t *);
494  /** Optional method to dump transport-specific statistics on the channel */
495  void (*dumpstats)(channel_listener_t *, int);
496 
497  /** Registered listen handler to call on incoming connection */
498  channel_listener_fn_ptr listener;
499 
500  /** List of pending incoming connections */
502 
503  /** Timestamps for listeners */
505 
506  /** Counters for listeners */
507  uint64_t n_accepted;
508 };
509 
510 /* Channel state manipulations */
511 
514 
518 
519 const char * channel_state_to_string(channel_state_t state);
520 const char *
522 
523 /* Abstract channel operations */
524 
527 
530 
531 /* Channel callback registrations */
532 
533 /* Listener callback */
535  channel_listener_fn_ptr listener);
536 
537 /* Incoming cell callbacks */
538 channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan);
539 
541  channel_cell_handler_fn_ptr cell_handler);
542 
543 /* Clean up closed channels and channel listeners periodically; these are
544  * called from run_scheduled_events() in main.c.
545  */
546 void channel_run_cleanup(void);
548 
549 /* Close all channels and deallocate everything */
550 void channel_free_all(void);
551 
552 /* Dump some statistics in the log */
553 void channel_dumpstats(int severity);
554 void channel_listener_dumpstats(int severity);
555 
556 #ifdef CHANNEL_OBJECT_PRIVATE
557 
558 #ifdef CHANNEL_FILE_PRIVATE
559 
562  channel_t *chan,
563  const tor_addr_t *target_ipv4_addr,
564  const tor_addr_t *target_ipv6_addr);
565 #endif /* defined(CHANNEL_FILE_PRIVATE) */
566 
567 /* Channel operations for subclasses and internal use only */
568 
569 /* Initialize a newly allocated channel - do this first in subclass
570  * constructors.
571  */
572 
573 void channel_init(channel_t *chan);
575 
576 /* Channel registration/unregistration */
577 void channel_register(channel_t *chan);
578 void channel_unregister(channel_t *chan);
579 
580 /* Channel listener registration/unregistration */
583 
584 /* Close from below */
587 void channel_closed(channel_t *chan);
588 
589 /* Free a channel */
590 void channel_free_(channel_t *chan);
591 #define channel_free(chan) FREE_AND_NULL(channel_t, channel_free_, (chan))
593 #define channel_listener_free(chan_l) \
594  FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
595 
596 /* State/metadata setters */
597 
598 void channel_change_state(channel_t *chan, channel_state_t to_state);
602 void channel_mark_local(channel_t *chan);
603 void channel_mark_incoming(channel_t *chan);
604 void channel_mark_outgoing(channel_t *chan);
605 void channel_mark_remote(channel_t *chan);
607  const char *identity_digest,
608  const struct ed25519_public_key_t *ed_identity);
609 
611  channel_listener_state_t to_state);
612 
613 /* Timestamp updates */
618 
622 
623 /* Incoming channel handling */
626  channel_t *incoming);
627 
628 /* Incoming cell handling */
629 void channel_process_cell(channel_t *chan, cell_t *cell);
630 
631 /* Request from lower layer for more cells if available */
633  (channel_t *chan, ssize_t num_cells));
634 
635 /* Query if data available on this channel */
637 
638 /* Notify flushed outgoing for dirreq handling */
640 
641 /* Handle stuff we need to do on open like notifying circuits */
643 
644 #endif /* defined(CHANNEL_OBJECT_PRIVATE) */
645 
646 /* Helper functions to perform operations on channels */
647 
648 int channel_send_destroy(circid_t circ_id, channel_t *chan,
649  int reason);
650 
651 /*
652  * Outside abstract interfaces that should eventually get turned into
653  * something transport/address format independent.
654  */
655 
656 channel_t * channel_connect(const tor_addr_t *addr, uint16_t port,
657  const char *rsa_id_digest,
658  const struct ed25519_public_key_t *ed_id);
659 
661  const char *rsa_id_digest,
662  const struct ed25519_public_key_t *ed_id,
663  const tor_addr_t *target_ipv4_addr,
664  const tor_addr_t *target_ipv6_addr,
665  bool for_origin_circ,
666  const char **msg_out,
667  int *launch_out));
668 
669 /* Ask which of two channels is better for circuit-extension purposes */
671 
672 /** Channel lookups
673  */
674 
675 channel_t * channel_find_by_global_id(uint64_t global_identifier);
676 channel_t * channel_find_by_remote_identity(const char *rsa_id_digest,
677  const struct ed25519_public_key_t *ed_id);
678 
679 /** For things returned by channel_find_by_remote_digest(), walk the list.
680  * The RSA key will match for all returned elements; the Ed25519 key might not.
681  */
683 
684 /*
685  * Helper macros to lookup state of given channel.
686  */
687 
688 #define CHANNEL_IS_CLOSED(chan) (channel_is_in_state((chan), \
689  CHANNEL_STATE_CLOSED))
690 #define CHANNEL_IS_OPENING(chan) (channel_is_in_state((chan), \
691  CHANNEL_STATE_OPENING))
692 #define CHANNEL_IS_OPEN(chan) (channel_is_in_state((chan), \
693  CHANNEL_STATE_OPEN))
694 #define CHANNEL_IS_MAINT(chan) (channel_is_in_state((chan), \
695  CHANNEL_STATE_MAINT))
696 #define CHANNEL_IS_CLOSING(chan) (channel_is_in_state((chan), \
697  CHANNEL_STATE_CLOSING))
698 #define CHANNEL_IS_ERROR(chan) (channel_is_in_state((chan), \
699  CHANNEL_STATE_ERROR))
700 
701 #define CHANNEL_FINISHED(chan) (CHANNEL_IS_CLOSED(chan) || \
702  CHANNEL_IS_ERROR(chan))
703 
704 #define CHANNEL_CONDEMNED(chan) (CHANNEL_IS_CLOSING(chan) || \
705  CHANNEL_FINISHED(chan))
706 
707 #define CHANNEL_CAN_HANDLE_CELLS(chan) (CHANNEL_IS_OPENING(chan) || \
708  CHANNEL_IS_OPEN(chan) || \
709  CHANNEL_IS_MAINT(chan))
710 
711 static inline int
712 channel_is_in_state(channel_t *chan, channel_state_t state)
713 {
714  return chan->state == state;
715 }
716 
717 /*
718  * Metadata queries/updates
719  */
720 
721 const char * channel_describe_transport(channel_t *chan);
722 MOCK_DECL(void, channel_dump_statistics, (channel_t *chan, int severity));
723 void channel_dump_transport_statistics(channel_t *chan, int severity);
725  tor_addr_t *addr_out));
726 MOCK_DECL(const char *, channel_describe_peer,(channel_t *chan));
731 int channel_is_client(const channel_t *chan);
732 int channel_is_local(channel_t *chan);
733 int channel_is_incoming(channel_t *chan);
734 int channel_is_outgoing(channel_t *chan);
735 void channel_mark_client(channel_t *chan);
736 void channel_clear_client(channel_t *chan);
737 int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info);
739  const char *rsa_id_digest,
740  const ed25519_public_key_t *ed_id);
741 unsigned int channel_num_circuits(channel_t *chan);
743  crypto_pk_t *identity_rcvd,
744  int consider_identity));
746 
749  int severity);
751  int severity);
753 
754 void channel_update_bad_for_new_circs(const char *digest, int force);
755 
756 /* Flow control queries */
758 
759 /* Timestamp queries */
760 time_t channel_when_created(channel_t *chan);
761 time_t channel_when_last_client(channel_t *chan);
762 time_t channel_when_last_xmit(channel_t *chan);
763 
764 /* Counter queries */
766  const packed_cell_t *packed_cell,
767  circid_t *circid_out);
768 
769 /* Declare the handle helpers */
770 HANDLE_DECL(channel, channel_t,)
771 #define channel_handle_free(h) \
772  FREE_AND_NULL(channel_handle_t, channel_handle_free_, (h))
773 #undef tor_timer_t
774 
775 #endif /* !defined(TOR_CHANNEL_H) */
channel_t * channel_find_by_remote_identity(const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:697
void channel_timestamp_active(channel_t *chan)
Definition: channel.c:3122
void channel_listener_process_incoming(channel_listener_t *listener)
Definition: channel.c:1807
void channel_timestamp_recv(channel_t *chan)
Definition: channel.c:3189
void channel_set_identity_digest(channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
Definition: channel.c:1331
void channel_listener_unregister(channel_listener_t *chan_l)
Definition: channel.c:524
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:2319
void channel_mark_local(channel_t *chan)
Definition: channel.c:2994
void channel_mark_incoming(channel_t *chan)
Definition: channel.c:2962
void channel_closed(channel_t *chan)
Definition: channel.c:1271
void channel_init_listener(channel_listener_t *chan_l)
Definition: channel.c:886
STATIC void channel_add_to_digest_map(channel_t *chan)
Definition: channel.c:560
void channel_do_open_actions(channel_t *chan)
Definition: channel.c:1859
void channel_close_from_lower_layer(channel_t *chan)
Definition: channel.c:1216
void channel_process_cell(channel_t *chan, cell_t *cell)
Definition: channel.c:1976
void channel_change_state_open(channel_t *chan)
Definition: channel.c:1622
void channel_listener_queue_incoming(channel_listener_t *listener, channel_t *incoming)
Definition: channel.c:1925
void channel_timestamp_created(channel_t *chan)
Definition: channel.c:3086
void channel_register(channel_t *chan)
Definition: channel.c:386
void channel_listener_timestamp_created(channel_listener_t *chan_l)
Definition: channel.c:3102
void channel_listener_timestamp_active(channel_listener_t *chan_l)
Definition: channel.c:3139
void channel_listener_register(channel_listener_t *chan_l)
Definition: channel.c:483
void channel_mark_remote(channel_t *chan)
Definition: channel.c:3010
void channel_unregister(channel_t *chan)
Definition: channel.c:444
ssize_t channel_flush_some_cells(channel_t *chan, ssize_t num_cells)
Definition: channel.c:1730
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:3290
void channel_close_for_error(channel_t *chan)
Definition: channel.c:1244
void channel_listener_free_(channel_listener_t *chan_l)
Definition: channel.c:954
void channel_listener_timestamp_accepted(channel_listener_t *chan_l)
Definition: channel.c:3156
void channel_notify_flushed(channel_t *chan)
Definition: channel.c:1790
void channel_timestamp_xmit(channel_t *chan)
Definition: channel.c:3209
void channel_clear_identity_digest(channel_t *chan)
Definition: channel.c:1302
void channel_clear_remote_end(channel_t *chan)
Definition: channel.c:1390
void channel_listener_change_state(channel_listener_t *chan_l, channel_listener_state_t to_state)
Definition: channel.c:1639
void channel_mark_outgoing(channel_t *chan)
Definition: channel.c:3039
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:2409
int channel_more_to_flush(channel_t *chan)
Definition: channel.c:1773
void channel_init(channel_t *chan)
Definition: channel.c:847
void channel_free_(channel_t *chan)
Definition: channel.c:902
void channel_change_state(channel_t *chan, channel_state_t to_state)
Definition: channel.c:1612
const char * channel_listener_describe_transport(channel_listener_t *chan_l)
Definition: channel.c:2523
int channel_has_queued_writes(channel_t *chan)
Definition: channel.c:2849
channel_t * channel_find_by_global_id(uint64_t global_identifier)
Definition: channel.c:650
void channel_set_circid_type(channel_t *chan, crypto_pk_t *identity_rcvd, int consider_identity)
Definition: channel.c:3333
int channel_is_better(channel_t *a, channel_t *b)
Definition: channel.c:2337
int channel_is_bad_for_new_circs(channel_t *chan)
Definition: channel.c:2865
int channel_is_outgoing(channel_t *chan)
Definition: channel.c:3025
const char * channel_describe_transport(channel_t *chan)
Definition: channel.c:2508
channel_t * channel_next_with_rsa_identity(channel_t *chan)
Definition: channel.c:731
void channel_mark_as_used_for_origin_circuit(channel_t *chan)
Definition: channeltls.c:374
void channel_run_cleanup(void)
Definition: channel.c:2133
void channel_update_bad_for_new_circs(const char *digest, int force)
Definition: channel.c:3438
void channel_dumpstats(int severity)
Definition: channel.c:2071
void channel_timestamp_client(channel_t *chan)
Definition: channel.c:3173
void channel_listener_dump_statistics(channel_listener_t *chan_l, int severity)
Definition: channel.c:2719
void channel_set_cell_handlers(channel_t *chan, channel_cell_handler_fn_ptr cell_handler)
Definition: channel.c:1102
void channel_mark_client(channel_t *chan)
Definition: channel.c:2906
time_t channel_when_last_xmit(channel_t *chan)
Definition: channel.c:3253
void channel_listener_run_cleanup(void)
Definition: channel.c:2159
int channel_listener_state_can_transition(channel_listener_state_t from, channel_listener_state_t to)
Definition: channel.c:283
int channel_state_is_valid(channel_state_t state)
Definition: channel.c:185
void channel_listener_mark_for_close(channel_listener_t *chan_l)
Definition: channel.c:1176
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:105
@ CHANNEL_STATE_ERROR
Definition: channel.h:117
@ CHANNEL_STATE_LAST
Definition: channel.h:121
void channel_check_for_duplicates(void)
Definition: channel.c:748
int channel_is_canonical(channel_t *chan)
Definition: channel.c:2933
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:210
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
Definition: channel.c:3270
channel_listener_state_t
Definition: channel.h:126
@ CHANNEL_LISTENER_STATE_ERROR
Definition: channel.h:166
@ CHANNEL_LISTENER_STATE_LAST
Definition: channel.h:170
@ CHANNEL_LISTENER_STATE_LISTENING
Definition: channel.h:146
@ CHANNEL_LISTENER_STATE_CLOSING
Definition: channel.h:156
@ CHANNEL_LISTENER_STATE_CLOSED
Definition: channel.h:135
int channel_state_can_transition(channel_state_t from, channel_state_t to)
Definition: channel.c:237
int channel_remote_identity_matches(const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:667
channel_usage_info_t
Definition: channel.h:32
time_t channel_when_last_client(channel_t *chan)
Definition: channel.c:3242
void channel_listener_set_listener_fn(channel_listener_t *chan, channel_listener_fn_ptr listener)
Definition: channel.c:1062
void channel_listener_dump_transport_statistics(channel_listener_t *chan_l, int severity)
Definition: channel.c:2798
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
Definition: channel.c:2031
void channel_mark_bad_for_new_circs(channel_t *chan)
Definition: channel.c:2878
int channel_is_incoming(channel_t *chan)
Definition: channel.c:2948
int channel_is_client(const channel_t *chan)
Definition: channel.c:2893
channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan)
Definition: channel.c:1085
int packed_cell_is_destroy(channel_t *chan, const packed_cell_t *packed_cell, circid_t *circid_out)
Definition: channel.c:2005
void channel_listener_dumpstats(int severity)
Definition: channel.c:2102
int channel_is_local(channel_t *chan)
Definition: channel.c:2979
int channel_num_cells_writeable(channel_t *chan)
Definition: channel.c:3056
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
Definition: channel.c:2835
const char * channel_state_to_string(channel_state_t state)
Definition: channel.c:315
void channel_mark_for_close(channel_t *chan)
Definition: channel.c:1137
const char * channel_describe_peer(channel_t *chan)
Definition: channel.c:2815
void channel_dump_statistics(channel_t *chan, int severity)
Definition: channel.c:2537
void channel_free_all(void)
Definition: channel.c:2246
void channel_dump_transport_statistics(channel_t *chan, int severity)
Definition: channel.c:2785
unsigned int channel_num_circuits(channel_t *chan)
Definition: channel.c:3316
void channel_clear_client(channel_t *chan)
Definition: channel.c:2919
int channel_write_packed_cell(channel_t *chan, packed_cell_t *cell)
Definition: channel.c:1484
const char * channel_listener_state_to_string(channel_listener_state_t state)
Definition: channel.c:350
time_t channel_when_created(channel_t *chan)
Definition: channel.c:3231
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:489
Definition: cell_st.h:17
channel_listener_state_t state
Definition: channel.h:463
enum channel_listener_t::@10 reason_for_closing
void(* dumpstats)(channel_listener_t *, int)
Definition: channel.h:495
uint64_t global_identifier
Definition: channel.h:468
void(* free_fn)(channel_listener_t *)
Definition: channel.h:489
unsigned char registered
Definition: channel.h:471
smartlist_t * incoming_list
Definition: channel.h:501
uint64_t n_accepted
Definition: channel.h:507
time_t timestamp_created
Definition: channel.h:483
channel_listener_fn_ptr listener
Definition: channel.h:498
time_t timestamp_accepted
Definition: channel.h:504
void(* close)(channel_listener_t *)
Definition: channel.h:491
unsigned int is_local
Definition: channel.h:434
void(* free_fn)(channel_t *)
Definition: channel.h:316
channel_state_t state
Definition: channel.h:192
int sched_heap_idx
Definition: channel.h:295
int(* is_canonical)(channel_t *)
Definition: channel.h:353
void(* close)(channel_t *)
Definition: channel.h:318
uint16_t padding_timeout_low_ms
Definition: channel.h:259
monotime_coarse_t next_padding_time
Definition: channel.h:232
void(* dumpstats)(channel_t *, int)
Definition: channel.h:322
time_t timestamp_last_had_circuits
Definition: channel.h:448
unsigned int num_n_circuits
Definition: channel.h:410
int(* matches_extend_info)(channel_t *, extend_info_t *)
Definition: channel.h:355
enum channel_t::@9 scheduler_state
circ_id_type_bitfield_t circ_id_type
Definition: channel.h:405
uint64_t dirreq_id
Definition: channel.h:453
unsigned int padding_enabled
Definition: channel.h:214
char identity_digest[DIGEST_LEN]
Definition: channel.h:378
uint32_t magic
Definition: channel.h:183
uint64_t n_cells_xmitted
Definition: channel.h:458
uint64_t n_cells_recved
Definition: channel.h:456
uint64_t global_identifier
Definition: channel.h:197
int(* write_packed_cell)(channel_t *, packed_cell_t *)
Definition: channel.h:365
channel_usage_info_t channel_usage
Definition: channel.h:228
HT_ENTRY(channel_t) gidmap_node
TOR_LIST_ENTRY(channel_t) next_with_same_id
struct channel_handle_t * timer_handle
Definition: channel.h:237
unsigned char registered
Definition: channel.h:200
time_t timestamp_client
Definition: channel.h:441
unsigned int is_incoming
Definition: channel.h:427
double(* get_overhead_estimate)(channel_t *)
Definition: channel.h:333
time_t timestamp_xmit
Definition: channel.h:443
unsigned int pending_padding_callback
Definition: channel.h:221
tor_addr_t addr_according_to_peer
Definition: channel.h:240
channel_cell_handler_fn_ptr cell_handler
Definition: channel.h:325
@ SCHED_CHAN_IDLE
Definition: channel.h:277
@ SCHED_CHAN_WAITING_FOR_CELLS
Definition: channel.h:282
@ SCHED_CHAN_WAITING_TO_WRITE
Definition: channel.h:286
@ SCHED_CHAN_PENDING
Definition: channel.h:291
int(* matches_target)(channel_t *, const tor_addr_t *)
Definition: channel.h:357
time_t timestamp_recv
Definition: channel.h:442
struct ed25519_public_key_t ed25519_identity
Definition: channel.h:388
time_t timestamp_created
Definition: channel.h:298
unsigned int has_been_open
Definition: channel.h:203
monotime_coarse_t timestamp_xfer
Definition: channel.h:311
unsigned int currently_padding
Definition: channel.h:218
unsigned int is_client
Definition: channel.h:424
unsigned int is_bad_for_new_circs
Definition: channel.h:419
unsigned int is_canonical_to_peer
Definition: channel.h:224
int(* write_var_cell)(channel_t *, var_cell_t *)
Definition: channel.h:367
circuitmux_t * cmux
Definition: channel.h:397
struct tor_timer_t * padding_timer
Definition: channel.h:235
HANDLE_ENTRY(channel, channel_t)
ratelim_t last_warned_circ_ids_exhausted
Definition: channel.h:438
int(* has_queued_writes)(channel_t *)
Definition: channel.h:348
enum channel_t::@8 reason_for_closing
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127