channel.h 23 KB

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