channel.h 22 KB

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