origin_circuit_st.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. #ifndef ORIGIN_CIRCUIT_ST_H
  7. #define ORIGIN_CIRCUIT_ST_H
  8. #include "or.h"
  9. struct onion_queue_t;
  10. /** An origin_circuit_t holds data necessary to build and use a circuit.
  11. */
  12. struct origin_circuit_t {
  13. circuit_t base_;
  14. /** Linked list of AP streams (or EXIT streams if hidden service)
  15. * associated with this circuit. */
  16. edge_connection_t *p_streams;
  17. /** Bytes read on this circuit since last call to
  18. * control_event_circ_bandwidth_used(). Only used if we're configured
  19. * to emit CIRC_BW events. */
  20. uint32_t n_read_circ_bw;
  21. /** Bytes written to on this circuit since last call to
  22. * control_event_circ_bandwidth_used(). Only used if we're configured
  23. * to emit CIRC_BW events. */
  24. uint32_t n_written_circ_bw;
  25. /** Total known-valid relay cell bytes since last call to
  26. * control_event_circ_bandwidth_used(). Only used if we're configured
  27. * to emit CIRC_BW events. */
  28. uint32_t n_delivered_read_circ_bw;
  29. /** Total written relay cell bytes since last call to
  30. * control_event_circ_bandwidth_used(). Only used if we're configured
  31. * to emit CIRC_BW events. */
  32. uint32_t n_delivered_written_circ_bw;
  33. /** Total overhead data in all known-valid relay data cells since last
  34. * call to control_event_circ_bandwidth_used(). Only used if we're
  35. * configured to emit CIRC_BW events. */
  36. uint32_t n_overhead_read_circ_bw;
  37. /** Total written overhead data in all relay data cells since last call to
  38. * control_event_circ_bandwidth_used(). Only used if we're configured
  39. * to emit CIRC_BW events. */
  40. uint32_t n_overhead_written_circ_bw;
  41. /** Build state for this circuit. It includes the intended path
  42. * length, the chosen exit router, rendezvous information, etc.
  43. */
  44. cpath_build_state_t *build_state;
  45. /** The doubly-linked list of crypt_path_t entries, one per hop,
  46. * for this circuit. This includes ciphers for each hop,
  47. * integrity-checking digests for each hop, and package/delivery
  48. * windows for each hop.
  49. */
  50. crypt_path_t *cpath;
  51. /** Holds all rendezvous data on either client or service side. */
  52. rend_data_t *rend_data;
  53. /** Holds hidden service identifier on either client or service side. This
  54. * is for both introduction and rendezvous circuit. */
  55. struct hs_ident_circuit_t *hs_ident;
  56. /** Holds the data that the entry guard system uses to track the
  57. * status of the guard this circuit is using, and thereby to determine
  58. * whether this circuit can be used. */
  59. struct circuit_guard_state_t *guard_state;
  60. /** Index into global_origin_circuit_list for this circuit. -1 if not
  61. * present. */
  62. int global_origin_circuit_list_idx;
  63. /** How many more relay_early cells can we send on this circuit, according
  64. * to the specification? */
  65. unsigned int remaining_relay_early_cells : 4;
  66. /** Set if this circuit is insanely old and we already informed the user */
  67. unsigned int is_ancient : 1;
  68. /** Set if this circuit has already been opened. Used to detect
  69. * cannibalized circuits. */
  70. unsigned int has_opened : 1;
  71. /**
  72. * Path bias state machine. Used to ensure integrity of our
  73. * circuit building and usage accounting. See path_state_t
  74. * for more details.
  75. */
  76. path_state_bitfield_t path_state : 3;
  77. /* If this flag is set, we should not consider attaching any more
  78. * connections to this circuit. */
  79. unsigned int unusable_for_new_conns : 1;
  80. /**
  81. * Tristate variable to guard against pathbias miscounting
  82. * due to circuit purpose transitions changing the decision
  83. * of pathbias_should_count(). This variable is informational
  84. * only. The current results of pathbias_should_count() are
  85. * the official decision for pathbias accounting.
  86. */
  87. uint8_t pathbias_shouldcount;
  88. #define PATHBIAS_SHOULDCOUNT_UNDECIDED 0
  89. #define PATHBIAS_SHOULDCOUNT_IGNORED 1
  90. #define PATHBIAS_SHOULDCOUNT_COUNTED 2
  91. /** For path probing. Store the temporary probe stream ID
  92. * for response comparison */
  93. streamid_t pathbias_probe_id;
  94. /** For path probing. Store the temporary probe address nonce
  95. * (in host byte order) for response comparison. */
  96. uint32_t pathbias_probe_nonce;
  97. /** Set iff this is a hidden-service circuit which has timed out
  98. * according to our current circuit-build timeout, but which has
  99. * been kept around because it might still succeed in connecting to
  100. * its destination, and which is not a fully-connected rendezvous
  101. * circuit.
  102. *
  103. * (We clear this flag for client-side rendezvous circuits when they
  104. * are 'joined' to the other side's rendezvous circuit, so that
  105. * connection_ap_handshake_attach_circuit can put client streams on
  106. * the circuit. We also clear this flag for service-side rendezvous
  107. * circuits when they are 'joined' to a client's rend circ, but only
  108. * for symmetry with the client case. Client-side introduction
  109. * circuits are closed when we get a joined rend circ, and
  110. * service-side introduction circuits never have this flag set.) */
  111. unsigned int hs_circ_has_timed_out : 1;
  112. /** Set iff this circuit has been given a relaxed timeout because
  113. * no circuits have opened. Used to prevent spamming logs. */
  114. unsigned int relaxed_timeout : 1;
  115. /** Set iff this is a service-side rendezvous circuit for which a
  116. * new connection attempt has been launched. We consider launching
  117. * a new service-side rend circ to a client when the previous one
  118. * fails; now that we don't necessarily close a service-side rend
  119. * circ when we launch a new one to the same client, this flag keeps
  120. * us from launching two retries for the same failed rend circ. */
  121. unsigned int hs_service_side_rend_circ_has_been_relaunched : 1;
  122. /** What commands were sent over this circuit that decremented the
  123. * RELAY_EARLY counter? This is for debugging task 878. */
  124. uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT];
  125. /** How many RELAY_EARLY cells have been sent over this circuit? This is
  126. * for debugging task 878, too. */
  127. int relay_early_cells_sent;
  128. /** The next stream_id that will be tried when we're attempting to
  129. * construct a new AP stream originating at this circuit. */
  130. streamid_t next_stream_id;
  131. /* The intro key replaces the hidden service's public key if purpose is
  132. * S_ESTABLISH_INTRO or S_INTRO, provided that no unversioned rendezvous
  133. * descriptor is used. */
  134. crypto_pk_t *intro_key;
  135. /** Quasi-global identifier for this circuit; used for control.c */
  136. /* XXXX NM This can get re-used after 2**32 circuits. */
  137. uint32_t global_identifier;
  138. /** True if we have associated one stream to this circuit, thereby setting
  139. * the isolation parameters for this circuit. Note that this doesn't
  140. * necessarily mean that we've <em>attached</em> any streams to the circuit:
  141. * we may only have marked up this circuit during the launch process.
  142. */
  143. unsigned int isolation_values_set : 1;
  144. /** True iff any stream has <em>ever</em> been attached to this circuit.
  145. *
  146. * In a better world we could use timestamp_dirty for this, but
  147. * timestamp_dirty is far too overloaded at the moment.
  148. */
  149. unsigned int isolation_any_streams_attached : 1;
  150. /** A bitfield of ISO_* flags for every isolation field such that this
  151. * circuit has had streams with more than one value for that field
  152. * attached to it. */
  153. uint8_t isolation_flags_mixed;
  154. /** @name Isolation parameters
  155. *
  156. * If any streams have been associated with this circ (isolation_values_set
  157. * == 1), and all streams associated with the circuit have had the same
  158. * value for some field ((isolation_flags_mixed & ISO_FOO) == 0), then these
  159. * elements hold the value for that field.
  160. *
  161. * Note again that "associated" is not the same as "attached": we
  162. * preliminarily associate streams with a circuit while the circuit is being
  163. * launched, so that we can tell whether we need to launch more circuits.
  164. *
  165. * @{
  166. */
  167. uint8_t client_proto_type;
  168. uint8_t client_proto_socksver;
  169. uint16_t dest_port;
  170. tor_addr_t client_addr;
  171. char *dest_address;
  172. int session_group;
  173. unsigned nym_epoch;
  174. size_t socks_username_len;
  175. uint8_t socks_password_len;
  176. /* Note that the next two values are NOT NUL-terminated; see
  177. socks_username_len and socks_password_len for their lengths. */
  178. char *socks_username;
  179. char *socks_password;
  180. /** Global identifier for the first stream attached here; used by
  181. * ISO_STREAM. */
  182. uint64_t associated_isolated_stream_global_id;
  183. /**@}*/
  184. /** A list of addr_policy_t for this circuit in particular. Used by
  185. * adjust_exit_policy_from_exitpolicy_failure.
  186. */
  187. smartlist_t *prepend_policy;
  188. /** How long do we wait before closing this circuit if it remains
  189. * completely idle after it was built, in seconds? This value
  190. * is randomized on a per-circuit basis from CircuitsAvailableTimoeut
  191. * to 2*CircuitsAvailableTimoeut. */
  192. int circuit_idle_timeout;
  193. };
  194. #endif