channel.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /* * Copyright (c) 2012-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file channel.h
  5. * \brief Header file for channel.c
  6. **/
  7. #ifndef TOR_CHANNEL_H
  8. #define TOR_CHANNEL_H
  9. #include "or.h"
  10. #include "circuitmux.h"
  11. #include "timers.h"
  12. #include "handles.h"
  13. /* Channel handler function pointer typedefs */
  14. typedef void (*channel_listener_fn_ptr)(channel_listener_t *, channel_t *);
  15. typedef void (*channel_cell_handler_fn_ptr)(channel_t *, cell_t *);
  16. typedef void (*channel_var_cell_handler_fn_ptr)(channel_t *, var_cell_t *);
  17. /**
  18. * This enum is used by channelpadding to decide when to pad channels.
  19. * Don't add values to it without updating the checks in
  20. * channelpadding_decide_to_pad_channel().
  21. */
  22. typedef enum {
  23. CHANNEL_USED_NOT_USED_FOR_FULL_CIRCS = 0,
  24. CHANNEL_USED_FOR_FULL_CIRCS,
  25. CHANNEL_USED_FOR_USER_TRAFFIC,
  26. } channel_usage_info_t;
  27. /**
  28. * Channel struct; see the channel_t typedef in or.h. A channel is an
  29. * abstract interface for the OR-to-OR connection, similar to connection_or_t,
  30. * but without the strong coupling to the underlying TLS implementation. They
  31. * are constructed by calling a protocol-specific function to open a channel
  32. * to a particular node, and once constructed support the abstract operations
  33. * defined below.
  34. */
  35. struct channel_s {
  36. /** Magic number for type-checking cast macros */
  37. uint32_t magic;
  38. /** List entry for hashtable for global-identifier lookup. */
  39. HT_ENTRY(channel_s) gidmap_node;
  40. /** Handle entry for handle-based lookup */
  41. HANDLE_ENTRY(channel, channel_s);
  42. /** Current channel state */
  43. channel_state_t state;
  44. /** Globally unique ID number for a channel over the lifetime of a Tor
  45. * process. This may not be 0.
  46. */
  47. uint64_t global_identifier;
  48. /** Should we expect to see this channel in the channel lists? */
  49. unsigned char registered:1;
  50. /** has this channel ever been open? */
  51. unsigned int has_been_open:1;
  52. /**
  53. * This field indicates if the other side has enabled or disabled
  54. * padding via either the link protocol version or
  55. * channelpadding_negotiate cells.
  56. *
  57. * Clients can override this with ConnectionPadding in torrc to
  58. * disable or force padding to relays, but relays cannot override the
  59. * client's request.
  60. */
  61. unsigned int padding_enabled:1;
  62. /** Cached value of our decision to pad (to avoid expensive
  63. * checks during critical path statistics counting). */
  64. unsigned int currently_padding:1;
  65. /** Is there a pending netflow padding callback? */
  66. unsigned int pending_padding_callback:1;
  67. /** Is our peer likely to consider this channel canonical? */
  68. unsigned int is_canonical_to_peer:1;
  69. /** Has this channel ever been used for non-directory traffic?
  70. * Used to decide what channels to pad, and when. */
  71. channel_usage_info_t channel_usage;
  72. /** When should we send a cell for netflow padding, in absolute
  73. * milliseconds since monotime system start. 0 means no padding
  74. * is scheduled. */
  75. uint64_t next_padding_time_ms;
  76. /** The callback pointer for the padding callbacks */
  77. tor_timer_t *padding_timer;
  78. /** The handle to this channel (to free on canceled timers) */
  79. struct channel_handle_t *timer_handle;
  80. /**
  81. * These two fields specify the minimum and maximum negotiated timeout
  82. * values for inactivity (send or receive) before we decide to pad a
  83. * channel. These fields can be set either via a PADDING_NEGOTIATE cell,
  84. * or the torrc option ReducedConnectionPadding. The consensus parameters
  85. * nf_ito_low and nf_ito_high are used to ensure that padding can only be
  86. * negotiated to be less frequent than what is specified in the consensus.
  87. * (This is done to prevent wingnut clients from requesting excessive
  88. * padding).
  89. *
  90. * The actual timeout value is randomly chosen between these two values
  91. * as per the table in channelpadding_get_netflow_inactive_timeout_ms(),
  92. * after ensuring that these values do not specify lower timeouts than
  93. * the consensus parameters.
  94. *
  95. * If these are 0, we have not negotiated or specified custom padding
  96. * times, and instead use consensus defaults. */
  97. uint16_t padding_timeout_low_ms;
  98. uint16_t padding_timeout_high_ms;
  99. /** Why did we close?
  100. */
  101. enum {
  102. CHANNEL_NOT_CLOSING = 0,
  103. CHANNEL_CLOSE_REQUESTED,
  104. CHANNEL_CLOSE_FROM_BELOW,
  105. CHANNEL_CLOSE_FOR_ERROR
  106. } reason_for_closing;
  107. /** State variable for use by the scheduler */
  108. enum {
  109. /*
  110. * The channel is not open, or it has a full output buffer but no queued
  111. * cells.
  112. */
  113. SCHED_CHAN_IDLE = 0,
  114. /*
  115. * The channel has space on its output buffer to write, but no queued
  116. * cells.
  117. */
  118. SCHED_CHAN_WAITING_FOR_CELLS,
  119. /*
  120. * The scheduler has queued cells but no output buffer space to write.
  121. */
  122. SCHED_CHAN_WAITING_TO_WRITE,
  123. /*
  124. * The scheduler has both queued cells and output buffer space, and is
  125. * eligible for the scheduler loop.
  126. */
  127. SCHED_CHAN_PENDING
  128. } scheduler_state;
  129. /** Heap index for use by the scheduler */
  130. int sched_heap_idx;
  131. /** Timestamps for both cell channels and listeners */
  132. time_t timestamp_created; /* Channel created */
  133. time_t timestamp_active; /* Any activity */
  134. /**
  135. * This is a high-resolution monotonic timestamp that marks when we
  136. * believe the channel has actually sent or received data to/from
  137. * the wire. Right now, it is used to determine when we should send
  138. * a padding cell for channelpadding.
  139. *
  140. * XXX: Are we setting timestamp_xfer_ms in the right places to
  141. * accurately reflect actual network data transfer? Or might this be
  142. * very wrong wrt when bytes actually go on the wire?
  143. */
  144. uint64_t timestamp_xfer_ms;
  145. /* Methods implemented by the lower layer */
  146. /** Free a channel */
  147. void (*free_fn)(channel_t *);
  148. /** Close an open channel */
  149. void (*close)(channel_t *);
  150. /** Describe the transport subclass for this channel */
  151. const char * (*describe_transport)(channel_t *);
  152. /** Optional method to dump transport-specific statistics on the channel */
  153. void (*dumpstats)(channel_t *, int);
  154. /** Registered handlers for incoming cells */
  155. channel_cell_handler_fn_ptr cell_handler;
  156. channel_var_cell_handler_fn_ptr var_cell_handler;
  157. /* Methods implemented by the lower layer */
  158. /**
  159. * Ask the lower layer for an estimate of the average overhead for
  160. * transmissions on this channel.
  161. */
  162. double (*get_overhead_estimate)(channel_t *);
  163. /*
  164. * Ask the underlying transport what the remote endpoint address is, in
  165. * a tor_addr_t. This is optional and subclasses may leave this NULL.
  166. * If they implement it, they should write the address out to the
  167. * provided tor_addr_t *, and return 1 if successful or 0 if no address
  168. * available.
  169. */
  170. int (*get_remote_addr)(channel_t *, tor_addr_t *);
  171. int (*get_transport_name)(channel_t *chan, char **transport_out);
  172. #define GRD_FLAG_ORIGINAL 1
  173. #define GRD_FLAG_ADDR_ONLY 2
  174. /**
  175. * Get a text description of the remote endpoint; canonicalized if the flag
  176. * GRD_FLAG_ORIGINAL is not set, or the one we originally connected
  177. * to/received from if it is. If GRD_FLAG_ADDR_ONLY is set, we return only
  178. * the original address.
  179. */
  180. const char * (*get_remote_descr)(channel_t *, int);
  181. /** Check if the lower layer has queued writes */
  182. int (*has_queued_writes)(channel_t *);
  183. /**
  184. * If the second param is zero, ask the lower layer if this is
  185. * 'canonical', for a transport-specific definition of canonical; if
  186. * it is 1, ask if the answer to the preceding query is safe to rely
  187. * on.
  188. */
  189. int (*is_canonical)(channel_t *, int);
  190. /** Check if this channel matches a specified extend_info_t */
  191. int (*matches_extend_info)(channel_t *, extend_info_t *);
  192. /** Check if this channel matches a target address when extending */
  193. int (*matches_target)(channel_t *, const tor_addr_t *);
  194. /* Ask the lower layer how many bytes it has queued but not yet sent */
  195. size_t (*num_bytes_queued)(channel_t *);
  196. /* Ask the lower layer how many cells can be written */
  197. int (*num_cells_writeable)(channel_t *);
  198. /* Write a cell to an open channel */
  199. int (*write_cell)(channel_t *, cell_t *);
  200. /** Write a packed cell to an open channel */
  201. int (*write_packed_cell)(channel_t *, packed_cell_t *);
  202. /** Write a variable-length cell to an open channel */
  203. int (*write_var_cell)(channel_t *, var_cell_t *);
  204. /**
  205. * Hash of the public RSA key for the other side's RSA identity key -- or
  206. * zeroes if we don't have an RSA identity in mind for the other side, and
  207. * it hasn't shown us one.
  208. *
  209. * Note that this is the RSA identity that we hope the other side has -- not
  210. * necessarily its true identity. Don't believe this identity unless
  211. * authentication has happened.
  212. */
  213. char identity_digest[DIGEST_LEN];
  214. /**
  215. * Ed25519 key for the other side of this channel -- or zeroes if we don't
  216. * have an Ed25519 identity in mind for the other side, and it hasn't shown
  217. * us one.
  218. *
  219. * Note that this is the identity that we hope the other side has -- not
  220. * necessarily its true identity. Don't believe this identity unless
  221. * authentication has happened.
  222. */
  223. ed25519_public_key_t ed25519_identity;
  224. /**
  225. * Linked list of channels with the same RSA identity digest, for use with
  226. * the digest->channel map
  227. */
  228. TOR_LIST_ENTRY(channel_s) next_with_same_id;
  229. /** Circuit mux for circuits sending on this channel */
  230. circuitmux_t *cmux;
  231. /** Circuit ID generation stuff for use by circuitbuild.c */
  232. /**
  233. * When we send CREATE cells along this connection, which half of the
  234. * space should we use?
  235. */
  236. circ_id_type_bitfield_t circ_id_type:2;
  237. /* DOCDOC */
  238. unsigned wide_circ_ids:1;
  239. /** For how many circuits are we n_chan? What about p_chan? */
  240. unsigned int num_n_circuits, num_p_circuits;
  241. /**
  242. * True iff this channel shouldn't get any new circs attached to it,
  243. * because the connection is too old, or because there's a better one.
  244. * More generally, this flag is used to note an unhealthy connection;
  245. * for example, if a bad connection fails we shouldn't assume that the
  246. * router itself has a problem.
  247. */
  248. unsigned int is_bad_for_new_circs:1;
  249. /** True iff we have decided that the other end of this connection
  250. * is a client or bridge relay. Connections with this flag set should never
  251. * be used to satisfy an EXTEND request. */
  252. unsigned int is_client:1;
  253. /** Set if the channel was initiated remotely (came from a listener) */
  254. unsigned int is_incoming:1;
  255. /** Set by lower layer if this is local; i.e., everything it communicates
  256. * with for this channel returns true for is_local_addr(). This is used
  257. * to decide whether to declare reachability when we receive something on
  258. * this channel in circuitbuild.c
  259. */
  260. unsigned int is_local:1;
  261. /** Have we logged a warning about circID exhaustion on this channel?
  262. * If so, when? */
  263. ratelim_t last_warned_circ_ids_exhausted;
  264. /** Channel timestamps for cell channels */
  265. time_t timestamp_client; /* Client used this, according to relay.c */
  266. time_t timestamp_recv; /* Cell received from lower layer */
  267. time_t timestamp_xmit; /* Cell sent to lower layer */
  268. /** Timestamp for run_connection_housekeeping(). We update this once a
  269. * second when we run housekeeping and find a circuit on this channel, and
  270. * whenever we add a circuit to the channel. */
  271. time_t timestamp_last_had_circuits;
  272. /** Unique ID for measuring direct network status requests;vtunneled ones
  273. * come over a circuit_t, which has a dirreq_id field as well, but is a
  274. * distinct namespace. */
  275. uint64_t dirreq_id;
  276. /** Channel counters for cell channels */
  277. uint64_t n_cells_recved, n_bytes_recved;
  278. uint64_t n_cells_xmitted, n_bytes_xmitted;
  279. };
  280. struct channel_listener_s {
  281. /* Current channel listener state */
  282. channel_listener_state_t state;
  283. /* Globally unique ID number for a channel over the lifetime of a Tor
  284. * process.
  285. */
  286. uint64_t global_identifier;
  287. /** Should we expect to see this channel in the channel lists? */
  288. unsigned char registered:1;
  289. /** Why did we close?
  290. */
  291. enum {
  292. CHANNEL_LISTENER_NOT_CLOSING = 0,
  293. CHANNEL_LISTENER_CLOSE_REQUESTED,
  294. CHANNEL_LISTENER_CLOSE_FROM_BELOW,
  295. CHANNEL_LISTENER_CLOSE_FOR_ERROR
  296. } reason_for_closing;
  297. /** Timestamps for both cell channels and listeners */
  298. time_t timestamp_created; /* Channel created */
  299. time_t timestamp_active; /* Any activity */
  300. /* Methods implemented by the lower layer */
  301. /** Free a channel */
  302. void (*free_fn)(channel_listener_t *);
  303. /** Close an open channel */
  304. void (*close)(channel_listener_t *);
  305. /** Describe the transport subclass for this channel */
  306. const char * (*describe_transport)(channel_listener_t *);
  307. /** Optional method to dump transport-specific statistics on the channel */
  308. void (*dumpstats)(channel_listener_t *, int);
  309. /** Registered listen handler to call on incoming connection */
  310. channel_listener_fn_ptr listener;
  311. /** List of pending incoming connections */
  312. smartlist_t *incoming_list;
  313. /** Timestamps for listeners */
  314. time_t timestamp_accepted;
  315. /** Counters for listeners */
  316. uint64_t n_accepted;
  317. };
  318. /* Channel state manipulations */
  319. int channel_state_is_valid(channel_state_t state);
  320. int channel_listener_state_is_valid(channel_listener_state_t state);
  321. int channel_state_can_transition(channel_state_t from, channel_state_t to);
  322. int channel_listener_state_can_transition(channel_listener_state_t from,
  323. channel_listener_state_t to);
  324. const char * channel_state_to_string(channel_state_t state);
  325. const char *
  326. channel_listener_state_to_string(channel_listener_state_t state);
  327. /* Abstract channel operations */
  328. void channel_mark_for_close(channel_t *chan);
  329. int channel_write_packed_cell(channel_t *chan, packed_cell_t *cell);
  330. void channel_listener_mark_for_close(channel_listener_t *chan_l);
  331. /* Channel callback registrations */
  332. /* Listener callback */
  333. void channel_listener_set_listener_fn(channel_listener_t *chan,
  334. channel_listener_fn_ptr listener);
  335. /* Incoming cell callbacks */
  336. channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan);
  337. channel_var_cell_handler_fn_ptr
  338. channel_get_var_cell_handler(channel_t *chan);
  339. void channel_set_cell_handlers(channel_t *chan,
  340. channel_cell_handler_fn_ptr cell_handler,
  341. channel_var_cell_handler_fn_ptr
  342. var_cell_handler);
  343. /* Clean up closed channels and channel listeners periodically; these are
  344. * called from run_scheduled_events() in main.c.
  345. */
  346. void channel_run_cleanup(void);
  347. void channel_listener_run_cleanup(void);
  348. /* Close all channels and deallocate everything */
  349. void channel_free_all(void);
  350. /* Dump some statistics in the log */
  351. void channel_dumpstats(int severity);
  352. void channel_listener_dumpstats(int severity);
  353. /* Set the cmux policy on all active channels */
  354. void channel_set_cmux_policy_everywhere(circuitmux_policy_t *pol);
  355. #ifdef TOR_CHANNEL_INTERNAL_
  356. #ifdef CHANNEL_PRIVATE_
  357. #endif /* defined(CHANNEL_PRIVATE_) */
  358. /* Channel operations for subclasses and internal use only */
  359. /* Initialize a newly allocated channel - do this first in subclass
  360. * constructors.
  361. */
  362. void channel_init(channel_t *chan);
  363. void channel_init_listener(channel_listener_t *chan);
  364. /* Channel registration/unregistration */
  365. void channel_register(channel_t *chan);
  366. void channel_unregister(channel_t *chan);
  367. /* Channel listener registration/unregistration */
  368. void channel_listener_register(channel_listener_t *chan_l);
  369. void channel_listener_unregister(channel_listener_t *chan_l);
  370. /* Close from below */
  371. void channel_close_from_lower_layer(channel_t *chan);
  372. void channel_close_for_error(channel_t *chan);
  373. void channel_closed(channel_t *chan);
  374. /* Free a channel */
  375. void channel_free(channel_t *chan);
  376. void channel_listener_free(channel_listener_t *chan_l);
  377. /* State/metadata setters */
  378. void channel_change_state(channel_t *chan, channel_state_t to_state);
  379. void channel_change_state_open(channel_t *chan);
  380. void channel_clear_identity_digest(channel_t *chan);
  381. void channel_clear_remote_end(channel_t *chan);
  382. void channel_mark_local(channel_t *chan);
  383. void channel_mark_incoming(channel_t *chan);
  384. void channel_mark_outgoing(channel_t *chan);
  385. void channel_mark_remote(channel_t *chan);
  386. void channel_set_identity_digest(channel_t *chan,
  387. const char *identity_digest,
  388. const ed25519_public_key_t *ed_identity);
  389. void channel_listener_change_state(channel_listener_t *chan_l,
  390. channel_listener_state_t to_state);
  391. /* Timestamp updates */
  392. void channel_timestamp_created(channel_t *chan);
  393. void channel_timestamp_active(channel_t *chan);
  394. void channel_timestamp_recv(channel_t *chan);
  395. void channel_timestamp_xmit(channel_t *chan);
  396. void channel_listener_timestamp_created(channel_listener_t *chan_l);
  397. void channel_listener_timestamp_active(channel_listener_t *chan_l);
  398. void channel_listener_timestamp_accepted(channel_listener_t *chan_l);
  399. /* Incoming channel handling */
  400. void channel_listener_process_incoming(channel_listener_t *listener);
  401. void channel_listener_queue_incoming(channel_listener_t *listener,
  402. channel_t *incoming);
  403. /* Incoming cell handling */
  404. void channel_process_cell(channel_t *chan, cell_t *cell);
  405. /* Request from lower layer for more cells if available */
  406. MOCK_DECL(ssize_t, channel_flush_some_cells,
  407. (channel_t *chan, ssize_t num_cells));
  408. /* Query if data available on this channel */
  409. MOCK_DECL(int, channel_more_to_flush, (channel_t *chan));
  410. /* Notify flushed outgoing for dirreq handling */
  411. void channel_notify_flushed(channel_t *chan);
  412. /* Handle stuff we need to do on open like notifying circuits */
  413. void channel_do_open_actions(channel_t *chan);
  414. #endif /* defined(TOR_CHANNEL_INTERNAL_) */
  415. /* Helper functions to perform operations on channels */
  416. int channel_send_destroy(circid_t circ_id, channel_t *chan,
  417. int reason);
  418. /*
  419. * Outside abstract interfaces that should eventually get turned into
  420. * something transport/address format independent.
  421. */
  422. channel_t * channel_connect(const tor_addr_t *addr, uint16_t port,
  423. const char *rsa_id_digest,
  424. const ed25519_public_key_t *ed_id);
  425. channel_t * channel_get_for_extend(const char *rsa_id_digest,
  426. const ed25519_public_key_t *ed_id,
  427. const tor_addr_t *target_addr,
  428. const char **msg_out,
  429. int *launch_out);
  430. /* Ask which of two channels is better for circuit-extension purposes */
  431. int channel_is_better(channel_t *a, channel_t *b);
  432. /** Channel lookups
  433. */
  434. channel_t * channel_find_by_global_id(uint64_t global_identifier);
  435. channel_t * channel_find_by_remote_identity(const char *rsa_id_digest,
  436. const ed25519_public_key_t *ed_id);
  437. /** For things returned by channel_find_by_remote_digest(), walk the list.
  438. * The RSA key will match for all returned elements; the Ed25519 key might not.
  439. */
  440. channel_t * channel_next_with_rsa_identity(channel_t *chan);
  441. /*
  442. * Helper macros to lookup state of given channel.
  443. */
  444. #define CHANNEL_IS_CLOSED(chan) (channel_is_in_state((chan), \
  445. CHANNEL_STATE_CLOSED))
  446. #define CHANNEL_IS_OPENING(chan) (channel_is_in_state((chan), \
  447. CHANNEL_STATE_OPENING))
  448. #define CHANNEL_IS_OPEN(chan) (channel_is_in_state((chan), \
  449. CHANNEL_STATE_OPEN))
  450. #define CHANNEL_IS_MAINT(chan) (channel_is_in_state((chan), \
  451. CHANNEL_STATE_MAINT))
  452. #define CHANNEL_IS_CLOSING(chan) (channel_is_in_state((chan), \
  453. CHANNEL_STATE_CLOSING))
  454. #define CHANNEL_IS_ERROR(chan) (channel_is_in_state((chan), \
  455. CHANNEL_STATE_ERROR))
  456. #define CHANNEL_FINISHED(chan) (CHANNEL_IS_CLOSED(chan) || \
  457. CHANNEL_IS_ERROR(chan))
  458. #define CHANNEL_CONDEMNED(chan) (CHANNEL_IS_CLOSING(chan) || \
  459. CHANNEL_FINISHED(chan))
  460. #define CHANNEL_CAN_HANDLE_CELLS(chan) (CHANNEL_IS_OPENING(chan) || \
  461. CHANNEL_IS_OPEN(chan) || \
  462. CHANNEL_IS_MAINT(chan))
  463. static inline int
  464. channel_is_in_state(channel_t *chan, channel_state_t state)
  465. {
  466. return chan->state == state;
  467. }
  468. /*
  469. * Metadata queries/updates
  470. */
  471. const char * channel_describe_transport(channel_t *chan);
  472. MOCK_DECL(void, channel_dump_statistics, (channel_t *chan, int severity));
  473. void channel_dump_transport_statistics(channel_t *chan, int severity);
  474. const char * channel_get_actual_remote_descr(channel_t *chan);
  475. const char * channel_get_actual_remote_address(channel_t *chan);
  476. int channel_get_addr_if_possible(channel_t *chan, tor_addr_t *addr_out);
  477. const char * channel_get_canonical_remote_descr(channel_t *chan);
  478. int channel_has_queued_writes(channel_t *chan);
  479. int channel_is_bad_for_new_circs(channel_t *chan);
  480. void channel_mark_bad_for_new_circs(channel_t *chan);
  481. int channel_is_canonical(channel_t *chan);
  482. int channel_is_canonical_is_reliable(channel_t *chan);
  483. int channel_is_client(const channel_t *chan);
  484. int channel_is_local(channel_t *chan);
  485. int channel_is_incoming(channel_t *chan);
  486. int channel_is_outgoing(channel_t *chan);
  487. void channel_mark_client(channel_t *chan);
  488. void channel_clear_client(channel_t *chan);
  489. int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info);
  490. int channel_matches_target_addr_for_extend(channel_t *chan,
  491. const tor_addr_t *target);
  492. unsigned int channel_num_circuits(channel_t *chan);
  493. MOCK_DECL(void,channel_set_circid_type,(channel_t *chan,
  494. crypto_pk_t *identity_rcvd,
  495. int consider_identity));
  496. void channel_timestamp_client(channel_t *chan);
  497. const char * channel_listener_describe_transport(channel_listener_t *chan_l);
  498. void channel_listener_dump_statistics(channel_listener_t *chan_l,
  499. int severity);
  500. void channel_listener_dump_transport_statistics(channel_listener_t *chan_l,
  501. int severity);
  502. void channel_check_for_duplicates(void);
  503. void channel_update_bad_for_new_circs(const char *digest, int force);
  504. /* Flow control queries */
  505. int channel_num_cells_writeable(channel_t *chan);
  506. /* Timestamp queries */
  507. time_t channel_when_created(channel_t *chan);
  508. time_t channel_when_last_client(channel_t *chan);
  509. time_t channel_when_last_xmit(channel_t *chan);
  510. /* Counter queries */
  511. int packed_cell_is_destroy(channel_t *chan,
  512. const packed_cell_t *packed_cell,
  513. circid_t *circid_out);
  514. /* Declare the handle helpers */
  515. HANDLE_DECL(channel, channel_s,)
  516. #endif /* !defined(TOR_CHANNEL_H) */