Tor  0.4.8.0-alpha-dev
edge_connection_st.h
Go to the documentation of this file.
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"
19 
20 /** Subtype of connection_t for an "edge connection" -- that is, an entry (ap)
21  * connection, or an exit. */
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  struct circuit_t *on_circuit; /**< The circuit (if any) that this edge
32  * connection is using. */
33 
34  /** A pointer to which node in the circ this conn exits at. Set for AP
35  * connections and for hidden service exit connections. */
37 
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;
42 
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 */
47 
48  streamid_t stream_id; /**< The stream ID used for this edge connection on its
49  * circuit */
50 
51  /** The reason why this connection is closing; passed to the controller. */
52  uint16_t end_reason;
53 
54  /** Bytes read since last call to control_event_stream_bandwidth_used() */
55  uint32_t n_read;
56 
57  /** Bytes written since last call to control_event_stream_bandwidth_used() */
58  uint32_t n_written;
59 
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;
64 
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().
68  */
69  /** True iff we've blocked reading until the circuit has fewer queued
70  * cells. */
71  unsigned int edge_blocked_on_circ:1;
72 
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;
77 
78  /* The following are flow control fields */
79 
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. */
84 
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;
89 
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).
94  */
95  uint32_t drained_bytes;
96  uint32_t prev_drained_bytes;
97 
98  /**
99  * N_EWMA of the drain rate of writes on this edge conn
100  * while buffers were present.
101  */
102  uint32_t ewma_drain_rate;
103 
104  /**
105  * The ewma drain rate the last time we sent an xon.
106  */
108 
109  /**
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 received, so
112  * that clients can check rate limits of XOFF/XON to prevent dropmark
113  * attacks. */
115 
116  /** Number of XOFFs received */
117  uint8_t num_xoff_recv;
118 
119  /** Number of XONs received */
120  uint8_t num_xon_recv;
121 
122  /**
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;
126 
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;
131 };
132 
133 #endif /* !defined(EDGE_CONNECTION_ST_H) */
Base connection structure.
Master header file for Tor-specific functionality.
uint16_t streamid_t
Definition: or.h:490
unsigned int is_reverse_dns_lookup
struct crypt_path_t * cpath_layer
token_bucket_rw_t bucket
struct edge_connection_t * next_stream
unsigned int is_dns_request
unsigned int edge_has_sent_end
unsigned int edge_blocked_on_circ
struct circuit_t * on_circuit
Headers for token_bucket.c.