Prop#324: Add fields to edge connection.
[tor.git] / src / core / or / edge_connection_st.h
blobdab32fc8d006f9a05e8350a6702c245cfcd719ce
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 */
7 /**
8 * @file edge_connection_st.h
9 * @brief Edge-connection structure.
10 **/
12 #ifndef EDGE_CONNECTION_ST_H
13 #define EDGE_CONNECTION_ST_H
15 #include "core/or/or.h"
17 #include "core/or/connection_st.h"
18 #include "lib/evloop/token_bucket.h"
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_;
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? */
31 struct circuit_t *on_circuit; /**< The circuit (if any) that this edge
32 * connection is using. */
34 /** A pointer to which node in the circ this conn exits at. Set for AP
35 * connections and for hidden service exit connections. */
36 struct crypt_path_t *cpath_layer;
38 /* Hidden service connection identifier for edge connections. Used by the HS
39 * client-side code to identify client SOCKS connections and by the
40 * service-side code to match HS circuits with their streams. */
41 struct hs_ident_edge_conn_t *hs_ident;
43 uint32_t address_ttl; /**< TTL for address-to-addr mapping on exit
44 * connection. Exit connections only. */
45 uint32_t begincell_flags; /** Flags sent or received in the BEGIN cell
46 * for this connection */
48 streamid_t stream_id; /**< The stream ID used for this edge connection on its
49 * circuit */
51 /** The reason why this connection is closing; passed to the controller. */
52 uint16_t end_reason;
54 /** Bytes read since last call to control_event_stream_bandwidth_used() */
55 uint32_t n_read;
57 /** Bytes written since last call to control_event_stream_bandwidth_used() */
58 uint32_t n_written;
60 /** True iff this connection is for a DNS request only. */
61 unsigned int is_dns_request:1;
62 /** True iff this connection is for a PTR DNS request. (exit only) */
63 unsigned int is_reverse_dns_lookup:1;
65 unsigned int edge_has_sent_end:1; /**< For debugging; only used on edge
66 * connections. Set once we've set the stream end,
67 * and check in connection_about_to_close_connection().
69 /** True iff we've blocked reading until the circuit has fewer queued
70 * cells. */
71 unsigned int edge_blocked_on_circ:1;
73 /** Unique ID for directory requests; this used to be in connection_t, but
74 * that's going away and being used on channels instead. We still tag
75 * edge connections with dirreq_id from circuits, so it's copied here. */
76 uint64_t dirreq_id;
78 /* The following are flow control fields */
80 /** Used for rate limiting the read side of this edge connection when
81 * congestion control is enabled on its circuit. The XON cell ewma_drain_rate
82 * parameter is used to set the bucket limits. */
83 token_bucket_rw_t bucket;
85 /**
86 * Monotime timestamp of the last time we sent a flow control message
87 * for this edge, used to compute advisory rates */
88 uint64_t drain_start_usec;
90 /**
91 * Number of bytes written since we either emptied our buffers,
92 * or sent an advisory drate rate. Can wrap, buf if so,
93 * we must reset the usec timestamp above. (Or make this u64, idk).
95 uint32_t drained_bytes;
96 uint32_t prev_drained_bytes;
98 /**
99 * N_EWMA of the drain rate of writes on this edge conn
100 * while buffers were present.
102 uint32_t ewma_drain_rate;
105 * The ewma drain rate the last time we sent an xon.
107 uint32_t ewma_rate_last_sent;
110 * The following fields are used to count the total bytes sent on this
111 * stream, and compare them to the number of XON and XOFFs recieved, so
112 * that clients can check rate limits of XOFF/XON to prevent dropmark
113 * attacks. */
114 uint32_t total_bytes_xmit;
116 /** Number of XOFFs received */
117 uint8_t num_xoff_recv;
119 /** Number of XONs received */
120 uint8_t num_xon_recv;
123 * Flag that tells us if an XOFF has been sent; cleared when we send an XON.
124 * Used to avoid sending multiple */
125 uint8_t xoff_sent : 1;
127 /** Flag that tells us if an XOFF has been received; cleared when we get
128 * an XON. Used to ensure that this edge keeps reads on its edge socket
129 * disabled. */
130 uint8_t xoff_received : 1;
133 #endif /* !defined(EDGE_CONNECTION_ST_H) */