tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

or_circuit_st.h (4707B)


      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-2021, The Tor Project, Inc. */
      5 /* See LICENSE for licensing information */
      6 
      7 #ifndef OR_CIRCUIT_ST_H
      8 #define OR_CIRCUIT_ST_H
      9 
     10 #include "core/or/or.h"
     11 
     12 #include "core/or/circuit_st.h"
     13 #include "core/or/crypt_path_st.h"
     14 
     15 #include "lib/evloop/token_bucket.h"
     16 
     17 struct onion_queue_t;
     18 
     19 /** An or_circuit_t holds information needed to implement a circuit at an
     20 * OR. */
     21 struct or_circuit_t {
     22  circuit_t base_;
     23 
     24  /** Pointer to an entry on the onion queue, if this circuit is waiting for a
     25   * chance to give an onionskin to a cpuworker. Used only in onion.c */
     26  struct onion_queue_t *onionqueue_entry;
     27  /** Pointer to a workqueue entry, if this circuit has given an onionskin to
     28   * a cpuworker and is waiting for a response. Used to decide whether it is
     29   * safe to free a circuit or if it is still in use by a cpuworker. */
     30  struct workqueue_entry_t *workqueue_entry;
     31 
     32  /** The circuit_id used in the previous (backward) hop of this circuit. */
     33  circid_t p_circ_id;
     34  /** Queue of cells waiting to be transmitted on p_conn. */
     35  cell_queue_t p_chan_cells;
     36  /** The channel that is previous in this circuit. */
     37  channel_t *p_chan;
     38  /** Linked list of Exit streams associated with this circuit.
     39   *
     40   * Note that any updates to this pointer must be followed with
     41   * conflux_update_n_streams() to keep the other legs n_streams
     42   * in sync. */
     43  edge_connection_t *n_streams;
     44  /** Linked list of Exit streams associated with this circuit that are
     45   * still being resolved.
     46   *
     47   * Just like with n_streams, any updates to this pointer must
     48   * be followed with conflux_update_resolving_streams().
     49   */
     50  edge_connection_t *resolving_streams;
     51 
     52  /** Cryptographic state used for encrypting and authenticating relay
     53   * cells to and from this hop. */
     54  relay_crypto_t crypto;
     55 
     56  /** Points to spliced circuit if purpose is REND_ESTABLISHED, and circuit
     57   * is not marked for close. */
     58  struct or_circuit_t *rend_splice;
     59 
     60  /** Stores KH for the handshake. */
     61  char rend_circ_nonce[DIGEST_LEN];/* KH in tor-spec.txt */
     62 
     63  /** Number of cells which we have discarded because of having no next hop,
     64   * despite not recognizing the cell. */
     65  uint32_t n_cells_discarded_at_end;
     66 
     67  /** How many more relay_early cells can we send on this circuit, according
     68   * to the specification? */
     69  unsigned int remaining_relay_early_cells : 4;
     70 
     71  /* We have already received an INTRODUCE1 cell on this circuit. */
     72  unsigned int already_received_introduce1 : 1;
     73 
     74  /** If set, this circuit carries HS traffic. Consider it in any HS
     75   *  statistics. */
     76  unsigned int circuit_carries_hs_traffic_stats : 1;
     77 
     78  /** True iff this circuit was made with a CREATE_FAST cell, or a CREATE[2]
     79   * cell with a TAP handshake. If this is the case and this is a rend circuit,
     80   * this is a v2 circuit, otherwise if this is a rend circuit it's a v3
     81   * circuit. */
     82  bool used_legacy_circuit_handshake;
     83 
     84  /** True if we received a version 0 sendme on this circuit, and it came
     85   * on a legacy (CREATE_FAST) circuit so we allowed it. We track this
     86   * state so we can avoid counting those directory requests for geoip. */
     87  bool used_obsolete_sendme;
     88 
     89  /** Number of cells that were removed from circuit queue; reset every
     90   * time when writing buffer stats to disk. */
     91  uint32_t processed_cells;
     92 
     93  /** Total time in milliseconds that cells spent in both app-ward and
     94   * exit-ward queues of this circuit; reset every time when writing
     95   * buffer stats to disk. */
     96  uint64_t total_cell_waiting_time;
     97 
     98  /** If set, the DoS defenses are enabled on this circuit meaning that the
     99   * introduce2_bucket is initialized and used. */
    100  unsigned int introduce2_dos_defense_enabled : 1;
    101  /** If set, the DoS defenses were explicitly enabled through the
    102   * ESTABLISH_INTRO cell extension. If unset, the consensus is used to learn
    103   * if the defenses can be enabled or not. */
    104  unsigned int introduce2_dos_defense_explicit : 1;
    105 
    106  /** INTRODUCE2 cell bucket controlling how much can go on this circuit. Only
    107   * used if this is a service introduction circuit at the intro point
    108   * (purpose = CIRCUIT_PURPOSE_INTRO_POINT). */
    109  token_bucket_ctr_t introduce2_bucket;
    110 
    111  /** RELAY_BEGIN and RELAY_RESOLVE cell bucket controlling how much can go on
    112   * this circuit. Only used if this is the end of a circuit on an exit node.*/
    113  token_bucket_ctr_t stream_limiter;
    114 
    115  /** Format to use when exchanging relay cells with the client
    116   * who built this circuit. */
    117  relay_cell_fmt_t relay_cell_format;
    118 };
    119 
    120 #endif /* !defined(OR_CIRCUIT_ST_H) */