tor

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

edge_connection_st.h (5332B)


      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 /**
      8 * @file edge_connection_st.h
      9 * @brief Edge-connection structure.
     10 **/
     11 
     12 #ifndef EDGE_CONNECTION_ST_H
     13 #define EDGE_CONNECTION_ST_H
     14 
     15 #include "core/or/or.h"
     16 
     17 #include "core/or/connection_st.h"
     18 #include "lib/evloop/token_bucket.h"
     19 
     20 /** Subtype of connection_t for an "edge connection" -- that is, an entry (ap)
     21 * connection, or an exit. */
     22 struct edge_connection_t {
     23  connection_t base_;
     24 
     25  struct edge_connection_t *next_stream; /**< Points to the next stream at this
     26                                          * edge, if any */
     27  int package_window; /**< How many more relay cells can I send into the
     28                       * circuit? */
     29  int deliver_window; /**< How many more relay cells can end at me? */
     30 
     31  /** The circuit (if any) that this edge connection is using.
     32   * Note that edges that use conflux should use the helpers
     33   * in conflux_util.c instead of accessing this directly. */
     34  struct circuit_t *on_circuit;
     35 
     36  /** A pointer to which node in the circ this conn exits at.  Set for AP
     37   * connections and for hidden service exit connections.
     38   * Note that edges that use conflux should use the helpers
     39   * in conflux_util.c instead of accessing this directly. */
     40  struct crypt_path_t *cpath_layer;
     41 
     42  /* Hidden service connection identifier for edge connections. Used by the HS
     43   * client-side code to identify client SOCKS connections and by the
     44   * service-side code to match HS circuits with their streams. */
     45  struct hs_ident_edge_conn_t *hs_ident;
     46 
     47  uint32_t address_ttl; /**< TTL for address-to-addr mapping on exit
     48                         * connection.  Exit connections only. */
     49  uint32_t begincell_flags; /** Flags sent or received in the BEGIN cell
     50                             * for this connection */
     51 
     52  streamid_t stream_id; /**< The stream ID used for this edge connection on its
     53                         * circuit */
     54 
     55  /** The reason why this connection is closing; passed to the controller. */
     56  uint16_t end_reason;
     57 
     58  /** Bytes read since last call to control_event_stream_bandwidth_used() */
     59  uint32_t n_read;
     60 
     61  /** Bytes written since last call to control_event_stream_bandwidth_used() */
     62  uint32_t n_written;
     63 
     64  /** True iff this connection is for a DNS request only. */
     65  unsigned int is_dns_request:1;
     66  /** True iff this connection is for a PTR DNS request. (exit only) */
     67  unsigned int is_reverse_dns_lookup:1;
     68 
     69  unsigned int edge_has_sent_end:1; /**< For debugging; only used on edge
     70                         * connections.  Set once we've set the stream end,
     71                         * and check in connection_about_to_close_connection().
     72                         */
     73 
     74  /** Unique ID for directory requests; this used to be in connection_t, but
     75   * that's going away and being used on channels instead.  We still tag
     76   * edge connections with dirreq_id from circuits, so it's copied here. */
     77  uint64_t dirreq_id;
     78 
     79  /* The following are flow control fields */
     80 
     81  /** Used for rate limiting the read side of this edge connection when
     82   * congestion control is enabled on its circuit. The XON cell ewma_drain_rate
     83   * parameter is used to set the bucket limits. */
     84  token_bucket_rw_t bucket;
     85 
     86  /**
     87   * Monotime timestamp of the last time we sent a flow control message
     88   * for this edge, used to compute advisory rates */
     89  uint64_t drain_start_usec;
     90 
     91  /**
     92   * Monotime timestamp of when we started the XOFF grace period for this edge.
     93   *
     94   * See the comments on `XOFF_GRACE_PERIOD_USEC` for an explanation on how
     95   * this is used.
     96   *
     97   * A value of 0 is considered "unset". This isn't great, but we set this
     98   * field as the output from `monotime_absolute_usec()` which should only ever
     99   * be 0 within the first 1 microsecond of initializing the monotonic timer
    100   * subsystem. */
    101  uint64_t xoff_grace_period_start_usec;
    102 
    103  /**
    104   * Number of bytes written since we either emptied our buffers,
    105   * or sent an advisory drate rate. Can wrap, buf if so,
    106   * we must reset the usec timestamp above. (Or make this u64, idk).
    107   */
    108  uint32_t drained_bytes;
    109  uint32_t prev_drained_bytes;
    110 
    111  /**
    112   * N_EWMA of the drain rate of writes on this edge conn
    113   * while buffers were present.
    114   */
    115  uint32_t ewma_drain_rate;
    116 
    117  /**
    118   * The ewma drain rate the last time we sent an xon.
    119   */
    120  uint32_t ewma_rate_last_sent;
    121 
    122  /**
    123   * The following fields are used to count the total bytes sent on this
    124   * stream, and compare them to the number of XON and XOFFs received, so
    125   * that clients can check rate limits of XOFF/XON to prevent dropmark
    126   * attacks. */
    127  uint32_t total_bytes_xmit;
    128 
    129  /** Number of XOFFs received */
    130  uint8_t num_xoff_recv;
    131 
    132  /** Number of XONs received */
    133  uint8_t num_xon_recv;
    134 
    135  /**
    136   * Flag that tells us if an XOFF has been sent; cleared when we send an XON.
    137   * Used to avoid sending multiple */
    138  uint8_t xoff_sent : 1;
    139 
    140  /** Flag that tells us if an XOFF has been received; cleared when we get
    141   * an XON. Used to ensure that this edge keeps reads on its edge socket
    142   * disabled. */
    143  uint8_t xoff_received : 1;
    144 };
    145 
    146 #endif /* !defined(EDGE_CONNECTION_ST_H) */