channel.h 23 KB

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