tor-commits
Threads by month
- ----- 2025 -----
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
June 2018
- 16 participants
- 2190 discussions

18 Jun '18
commit bba998af65c9a414c56824f5779d2c47cf5a6b44
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 11:05:56 2018 -0400
Extract connection_t into its own header.
Now the entire connection_t hierarchy is extracted from or.h
---
src/or/config.c | 1 +
src/or/connection.c | 26 ++++++++
src/or/connection.h | 34 +----------
src/or/connection_st.h | 132 ++++++++++++++++++++++++++++++++++++++++
src/or/control_connection_st.h | 1 +
src/or/dir_connection_st.h | 2 +
src/or/edge_connection_st.h | 2 +
src/or/include.am | 1 +
src/or/listener_connection_st.h | 2 +
src/or/or.h | 122 +------------------------------------
src/or/or_connection_st.h | 2 +
src/test/test_helpers.c | 2 +
12 files changed, 175 insertions(+), 152 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 51ecca431..ca495aa97 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -116,6 +116,7 @@
#include "dirauth/dirvote.h"
#include "dirauth/mode.h"
+#include "connection_st.h"
#include "port_cfg_st.h"
#ifdef HAVE_SYSTEMD
diff --git a/src/or/connection.c b/src/or/connection.c
index 3c5330154..867c4d72d 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -183,6 +183,18 @@ TO_LISTENER_CONN(connection_t *c)
return DOWNCAST(listener_connection_t, c);
}
+size_t
+connection_get_inbuf_len(connection_t *conn)
+{
+ return conn->inbuf ? buf_datalen(conn->inbuf) : 0;
+}
+
+size_t
+connection_get_outbuf_len(connection_t *conn)
+{
+ return conn->outbuf ? buf_datalen(conn->outbuf) : 0;
+}
+
/**
* Return the human-readable name for the connection type <b>type</b>
*/
@@ -4835,6 +4847,20 @@ kill_conn_list_for_oos, (smartlist_t *conns))
smartlist_len(conns));
}
+/** Check if a connection is on the way out so the OOS handler doesn't try
+ * to kill more than it needs. */
+int
+connection_is_moribund(connection_t *conn)
+{
+ if (conn != NULL &&
+ (conn->conn_array_index < 0 ||
+ conn->marked_for_close)) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
/** Out-of-Sockets handler; n_socks is the current number of open
* sockets, and failed is non-zero if a socket exhaustion related
* error immediately preceded this call. This is where to do
diff --git a/src/or/connection.h b/src/or/connection.h
index df3388239..0ab8962b4 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -161,23 +161,8 @@ void connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done);
void connection_buf_add_buf(connection_t *conn, buf_t *buf);
-/* DOCDOC connection_get_inbuf_len */
-static size_t connection_get_inbuf_len(connection_t *conn);
-/* DOCDOC connection_get_outbuf_len */
-static size_t connection_get_outbuf_len(connection_t *conn);
-
-static inline size_t
-connection_get_inbuf_len(connection_t *conn)
-{
- return conn->inbuf ? buf_datalen(conn->inbuf) : 0;
-}
-
-static inline size_t
-connection_get_outbuf_len(connection_t *conn)
-{
- return conn->outbuf ? buf_datalen(conn->outbuf) : 0;
-}
-
+size_t connection_get_inbuf_len(connection_t *conn);
+size_t connection_get_outbuf_len(connection_t *conn);
connection_t *connection_get_by_global_id(uint64_t id);
connection_t *connection_get_by_type(int type);
@@ -254,20 +239,7 @@ MOCK_DECL(void, clock_skew_warning,
log_domain_mask_t domain, const char *received,
const char *source));
-/** Check if a connection is on the way out so the OOS handler doesn't try
- * to kill more than it needs. */
-static inline int
-connection_is_moribund(connection_t *conn)
-{
- if (conn != NULL &&
- (conn->conn_array_index < 0 ||
- conn->marked_for_close)) {
- return 1;
- } else {
- return 0;
- }
-}
-
+int connection_is_moribund(connection_t *conn);
void connection_check_oos(int n_socks, int failed);
#ifdef CONNECTION_PRIVATE
diff --git a/src/or/connection_st.h b/src/or/connection_st.h
new file mode 100644
index 000000000..b65238693
--- /dev/null
+++ b/src/or/connection_st.h
@@ -0,0 +1,132 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CONNECTION_ST_H
+#define CONNECTION_ST_H
+
+struct buf_t;
+
+/** Description of a connection to another host or process, and associated
+ * data.
+ *
+ * A connection is named based on what it's connected to -- an "OR
+ * connection" has a Tor node on the other end, an "exit
+ * connection" has a website or other server on the other end, and an
+ * "AP connection" has an application proxy (and thus a user) on the
+ * other end.
+ *
+ * Every connection has a type and a state. Connections never change
+ * their type, but can go through many state changes in their lifetime.
+ *
+ * Every connection has two associated input and output buffers.
+ * Listeners don't use them. For non-listener connections, incoming
+ * data is appended to conn->inbuf, and outgoing data is taken from
+ * conn->outbuf. Connections differ primarily in the functions called
+ * to fill and drain these buffers.
+ */
+typedef struct connection_t {
+ uint32_t magic; /**< For memory debugging: must equal one of
+ * *_CONNECTION_MAGIC. */
+
+ uint8_t state; /**< Current state of this connection. */
+ unsigned int type:5; /**< What kind of connection is this? */
+ unsigned int purpose:5; /**< Only used for DIR and EXIT types currently. */
+
+ /* The next fields are all one-bit booleans. Some are only applicable to
+ * connection subtypes, but we hold them here anyway, to save space.
+ */
+ unsigned int read_blocked_on_bw:1; /**< Boolean: should we start reading
+ * again once the bandwidth throttler allows it? */
+ unsigned int write_blocked_on_bw:1; /**< Boolean: should we start writing
+ * again once the bandwidth throttler allows
+ * writes? */
+ unsigned int hold_open_until_flushed:1; /**< Despite this connection's being
+ * marked for close, do we flush it
+ * before closing it? */
+ unsigned int inbuf_reached_eof:1; /**< Boolean: did read() return 0 on this
+ * conn? */
+ /** Set to 1 when we're inside connection_flushed_some to keep us from
+ * calling connection_handle_write() recursively. */
+ unsigned int in_flushed_some:1;
+ /** True if connection_handle_write is currently running on this connection.
+ */
+ unsigned int in_connection_handle_write:1;
+
+ /* For linked connections:
+ */
+ unsigned int linked:1; /**< True if there is, or has been, a linked_conn. */
+ /** True iff we'd like to be notified about read events from the
+ * linked conn. */
+ unsigned int reading_from_linked_conn:1;
+ /** True iff we're willing to write to the linked conn. */
+ unsigned int writing_to_linked_conn:1;
+ /** True iff we're currently able to read on the linked conn, and our
+ * read_event should be made active with libevent. */
+ unsigned int active_on_link:1;
+ /** True iff we've called connection_close_immediate() on this linked
+ * connection. */
+ unsigned int linked_conn_is_closed:1;
+
+ /** CONNECT/SOCKS proxy client handshake state (for outgoing connections). */
+ unsigned int proxy_state:4;
+
+ /** Our socket; set to TOR_INVALID_SOCKET if this connection is closed,
+ * or has no socket. */
+ tor_socket_t s;
+ int conn_array_index; /**< Index into the global connection array. */
+
+ struct event *read_event; /**< Libevent event structure. */
+ struct event *write_event; /**< Libevent event structure. */
+ struct buf_t *inbuf; /**< Buffer holding data read over this connection. */
+ struct buf_t *outbuf; /**< Buffer holding data to write over this
+ * connection. */
+ size_t outbuf_flushlen; /**< How much data should we try to flush from the
+ * outbuf? */
+ time_t timestamp_last_read_allowed; /**< When was the last time libevent said
+ * we could read? */
+ time_t timestamp_last_write_allowed; /**< When was the last time libevent
+ * said we could write? */
+
+ time_t timestamp_created; /**< When was this connection_t created? */
+
+ int socket_family; /**< Address family of this connection's socket. Usually
+ * AF_INET, but it can also be AF_UNIX, or AF_INET6 */
+ tor_addr_t addr; /**< IP that socket "s" is directly connected to;
+ * may be the IP address for a proxy or pluggable transport,
+ * see "address" for the address of the final destination.
+ */
+ uint16_t port; /**< If non-zero, port that socket "s" is directly connected
+ * to; may be the port for a proxy or pluggable transport,
+ * see "address" for the port at the final destination. */
+ uint16_t marked_for_close; /**< Should we close this conn on the next
+ * iteration of the main loop? (If true, holds
+ * the line number where this connection was
+ * marked.) */
+ const char *marked_for_close_file; /**< For debugging: in which file were
+ * we marked for close? */
+ char *address; /**< FQDN (or IP) and port of the final destination for this
+ * connection; this is always the remote address, it is
+ * passed to a proxy or pluggable transport if one in use.
+ * See "addr" and "port" for the address that socket "s" is
+ * directly connected to.
+ * strdup into this, because free_connection() frees it. */
+ /** Another connection that's connected to this one in lieu of a socket. */
+ struct connection_t *linked_conn;
+
+ /** Unique identifier for this connection on this Tor instance. */
+ uint64_t global_identifier;
+
+ /** Bytes read since last call to control_event_conn_bandwidth_used().
+ * Only used if we're configured to emit CONN_BW events. */
+ uint32_t n_read_conn_bw;
+
+ /** Bytes written since last call to control_event_conn_bandwidth_used().
+ * Only used if we're configured to emit CONN_BW events. */
+ uint32_t n_written_conn_bw;
+} connection_t;
+
+#endif
+
diff --git a/src/or/control_connection_st.h b/src/or/control_connection_st.h
index 2d8efec1f..7770b54d5 100644
--- a/src/or/control_connection_st.h
+++ b/src/or/control_connection_st.h
@@ -8,6 +8,7 @@
#define CONTROL_CONNECTION_ST_H
#include "or.h"
+#include "connection_st.h"
/** Subtype of connection_t for an connection to a controller. */
struct control_connection_t {
diff --git a/src/or/dir_connection_st.h b/src/or/dir_connection_st.h
index df1e9b551..379f787df 100644
--- a/src/or/dir_connection_st.h
+++ b/src/or/dir_connection_st.h
@@ -7,6 +7,8 @@
#ifndef DIR_CONNECTION_ST_H
#define DIR_CONNECTION_ST_H
+#include "connection_st.h"
+
/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
* connection to retrieve or serve directory material. */
struct dir_connection_t {
diff --git a/src/or/edge_connection_st.h b/src/or/edge_connection_st.h
index 3cffdea32..7ef56bf06 100644
--- a/src/or/edge_connection_st.h
+++ b/src/or/edge_connection_st.h
@@ -9,6 +9,8 @@
#include "or.h"
+#include "connection_st.h"
+
/** Subtype of connection_t for an "edge connection" -- that is, an entry (ap)
* connection, or an exit. */
struct edge_connection_t {
diff --git a/src/or/include.am b/src/or/include.am
index f3bbaa11c..de263e9b8 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -197,6 +197,7 @@ ORHEADERS = \
src/or/config.h \
src/or/confparse.h \
src/or/connection.h \
+ src/or/connection_st.h \
src/or/connection_edge.h \
src/or/connection_or.h \
src/or/conscache.h \
diff --git a/src/or/listener_connection_st.h b/src/or/listener_connection_st.h
index 67718c5a3..63588c99a 100644
--- a/src/or/listener_connection_st.h
+++ b/src/or/listener_connection_st.h
@@ -7,6 +7,8 @@
#ifndef LISTENER_CONNECTION_ST_H
#define LISTENER_CONNECTION_ST_H
+#include "connection_st.h"
+
/** Subtype of connection_t; used for a listener socket. */
struct listener_connection_t {
connection_t base_;
diff --git a/src/or/or.h b/src/or/or.h
index 990f7f94e..c3506d3ff 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1260,127 +1260,6 @@ typedef struct server_port_cfg_t server_port_cfg_t;
#define CONTROL_CONNECTION_MAGIC 0x8abc765du
#define LISTENER_CONNECTION_MAGIC 0x1a1ac741u
-struct buf_t;
-
-/** Description of a connection to another host or process, and associated
- * data.
- *
- * A connection is named based on what it's connected to -- an "OR
- * connection" has a Tor node on the other end, an "exit
- * connection" has a website or other server on the other end, and an
- * "AP connection" has an application proxy (and thus a user) on the
- * other end.
- *
- * Every connection has a type and a state. Connections never change
- * their type, but can go through many state changes in their lifetime.
- *
- * Every connection has two associated input and output buffers.
- * Listeners don't use them. For non-listener connections, incoming
- * data is appended to conn->inbuf, and outgoing data is taken from
- * conn->outbuf. Connections differ primarily in the functions called
- * to fill and drain these buffers.
- */
-typedef struct connection_t {
- uint32_t magic; /**< For memory debugging: must equal one of
- * *_CONNECTION_MAGIC. */
-
- uint8_t state; /**< Current state of this connection. */
- unsigned int type:5; /**< What kind of connection is this? */
- unsigned int purpose:5; /**< Only used for DIR and EXIT types currently. */
-
- /* The next fields are all one-bit booleans. Some are only applicable to
- * connection subtypes, but we hold them here anyway, to save space.
- */
- unsigned int read_blocked_on_bw:1; /**< Boolean: should we start reading
- * again once the bandwidth throttler allows it? */
- unsigned int write_blocked_on_bw:1; /**< Boolean: should we start writing
- * again once the bandwidth throttler allows
- * writes? */
- unsigned int hold_open_until_flushed:1; /**< Despite this connection's being
- * marked for close, do we flush it
- * before closing it? */
- unsigned int inbuf_reached_eof:1; /**< Boolean: did read() return 0 on this
- * conn? */
- /** Set to 1 when we're inside connection_flushed_some to keep us from
- * calling connection_handle_write() recursively. */
- unsigned int in_flushed_some:1;
- /** True if connection_handle_write is currently running on this connection.
- */
- unsigned int in_connection_handle_write:1;
-
- /* For linked connections:
- */
- unsigned int linked:1; /**< True if there is, or has been, a linked_conn. */
- /** True iff we'd like to be notified about read events from the
- * linked conn. */
- unsigned int reading_from_linked_conn:1;
- /** True iff we're willing to write to the linked conn. */
- unsigned int writing_to_linked_conn:1;
- /** True iff we're currently able to read on the linked conn, and our
- * read_event should be made active with libevent. */
- unsigned int active_on_link:1;
- /** True iff we've called connection_close_immediate() on this linked
- * connection. */
- unsigned int linked_conn_is_closed:1;
-
- /** CONNECT/SOCKS proxy client handshake state (for outgoing connections). */
- unsigned int proxy_state:4;
-
- /** Our socket; set to TOR_INVALID_SOCKET if this connection is closed,
- * or has no socket. */
- tor_socket_t s;
- int conn_array_index; /**< Index into the global connection array. */
-
- struct event *read_event; /**< Libevent event structure. */
- struct event *write_event; /**< Libevent event structure. */
- struct buf_t *inbuf; /**< Buffer holding data read over this connection. */
- struct buf_t *outbuf; /**< Buffer holding data to write over this
- * connection. */
- size_t outbuf_flushlen; /**< How much data should we try to flush from the
- * outbuf? */
- time_t timestamp_last_read_allowed; /**< When was the last time libevent said
- * we could read? */
- time_t timestamp_last_write_allowed; /**< When was the last time libevent
- * said we could write? */
-
- time_t timestamp_created; /**< When was this connection_t created? */
-
- int socket_family; /**< Address family of this connection's socket. Usually
- * AF_INET, but it can also be AF_UNIX, or AF_INET6 */
- tor_addr_t addr; /**< IP that socket "s" is directly connected to;
- * may be the IP address for a proxy or pluggable transport,
- * see "address" for the address of the final destination.
- */
- uint16_t port; /**< If non-zero, port that socket "s" is directly connected
- * to; may be the port for a proxy or pluggable transport,
- * see "address" for the port at the final destination. */
- uint16_t marked_for_close; /**< Should we close this conn on the next
- * iteration of the main loop? (If true, holds
- * the line number where this connection was
- * marked.) */
- const char *marked_for_close_file; /**< For debugging: in which file were
- * we marked for close? */
- char *address; /**< FQDN (or IP) and port of the final destination for this
- * connection; this is always the remote address, it is
- * passed to a proxy or pluggable transport if one in use.
- * See "addr" and "port" for the address that socket "s" is
- * directly connected to.
- * strdup into this, because free_connection() frees it. */
- /** Another connection that's connected to this one in lieu of a socket. */
- struct connection_t *linked_conn;
-
- /** Unique identifier for this connection on this Tor instance. */
- uint64_t global_identifier;
-
- /** Bytes read since last call to control_event_conn_bandwidth_used().
- * Only used if we're configured to emit CONN_BW events. */
- uint32_t n_read_conn_bw;
-
- /** Bytes written since last call to control_event_conn_bandwidth_used().
- * Only used if we're configured to emit CONN_BW events. */
- uint32_t n_written_conn_bw;
-} connection_t;
-
/** Minimum length of the random part of an AUTH_CHALLENGE cell. */
#define OR_AUTH_CHALLENGE_LEN 32
@@ -1458,6 +1337,7 @@ typedef struct or_handshake_state_t or_handshake_state_t;
* drops below this size. */
#define OR_CONN_LOWWATER (16*1024)
+typedef struct connection_t connection_t;
typedef struct control_connection_t control_connection_t;
typedef struct dir_connection_t dir_connection_t;
typedef struct edge_connection_t edge_connection_t;
diff --git a/src/or/or_connection_st.h b/src/or/or_connection_st.h
index bccfd18f6..dd775bc8a 100644
--- a/src/or/or_connection_st.h
+++ b/src/or/or_connection_st.h
@@ -7,6 +7,8 @@
#ifndef OR_CONNECTION_ST_H
#define OR_CONNECTION_ST_H
+#include "connection_st.h"
+
/** Subtype of connection_t for an "OR connection" -- that is, one that speaks
* cells over TLS. */
struct or_connection_t {
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index 1db5e9064..86aeabb7c 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -24,6 +24,8 @@
#include "relay.h"
#include "routerlist.h"
+#include "connection_st.h"
+
#include "test.h"
#include "test_helpers.h"
#include "test_connection.h"
1
0

[tor/master] Extract {or, origin}_circuit_t into their own headers
by nickm@torproject.org 18 Jun '18
by nickm@torproject.org 18 Jun '18
18 Jun '18
commit a0bc164af57a3e5828cfc4fdefb9b2191af79ce9
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 11:34:33 2018 -0400
Extract {or,origin}_circuit_t into their own headers
---
src/or/circpathbias.c | 2 +
src/or/circuitbuild.c | 2 +
src/or/circuitlist.c | 27 ++++
src/or/circuitlist.h | 9 ++
src/or/circuitmux.c | 2 +
src/or/circuitstats.c | 2 +
src/or/circuituse.c | 2 +
src/or/command.c | 3 +
src/or/connection_edge.c | 2 +
src/or/control.c | 2 +
src/or/cpuworker.c | 2 +
src/or/directory.h | 1 +
src/or/dns.c | 1 +
src/or/entrynodes.c | 2 +
src/or/hs_cell.c | 2 +
src/or/hs_circuit.c | 2 +
src/or/hs_circuitmap.c | 3 +
src/or/hs_client.c | 1 +
src/or/hs_common.c | 1 +
src/or/hs_intropoint.c | 2 +
src/or/hs_service.c | 1 +
src/or/include.am | 2 +
src/or/onion.c | 2 +
src/or/or.h | 316 +-------------------------------------
src/or/or_circuit_st.h | 77 ++++++++++
src/or/origin_circuit_st.h | 233 ++++++++++++++++++++++++++++
src/or/relay.c | 2 +
src/or/relay_crypto.c | 4 +
src/or/rendclient.c | 1 +
src/or/rendcommon.c | 3 +
src/or/rendmid.c | 2 +
src/or/rendservice.c | 1 +
src/or/rephist.c | 2 +
src/or/router.c | 1 +
src/test/bench.c | 2 +
src/test/test.c | 2 +
src/test/test_cell_queue.c | 3 +
src/test/test_channel.c | 2 +
src/test/test_circuitlist.c | 3 +
src/test/test_circuitstats.c | 2 +
src/test/test_circuituse.c | 2 +
src/test/test_controller_events.c | 3 +
src/test/test_dns.c | 1 +
src/test/test_entrynodes.c | 1 +
src/test/test_helpers.c | 1 +
src/test/test_hs_client.c | 1 +
src/test/test_hs_intropoint.c | 2 +
src/test/test_hs_service.c | 2 +
src/test/test_oom.c | 2 +
src/test/test_relay.c | 2 +
src/test/test_relaycell.c | 1 +
src/test/test_relaycrypt.c | 4 +
src/test/test_status.c | 3 +
53 files changed, 443 insertions(+), 313 deletions(-)
diff --git a/src/or/circpathbias.c b/src/or/circpathbias.c
index ff42bf91e..f139c6d7e 100644
--- a/src/or/circpathbias.c
+++ b/src/or/circpathbias.c
@@ -35,6 +35,8 @@
#include "networkstatus.h"
#include "relay.h"
+#include "origin_circuit_st.h"
+
static void pathbias_count_successful_close(origin_circuit_t *circ);
static void pathbias_count_collapse(origin_circuit_t *circ);
static void pathbias_count_use_failed(origin_circuit_t *circ);
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 883f93074..c5d1c65f5 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -66,6 +66,8 @@
#include "transports.h"
#include "entry_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
static channel_t * channel_connect_for_circuit(const tor_addr_t *addr,
uint16_t port,
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 1a3f3a229..7601bc613 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -94,6 +94,8 @@
#include "dir_connection_st.h"
#include "edge_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
/********* START VARIABLES **********/
@@ -130,6 +132,31 @@ static int any_opened_circs_cached_val = 0;
/********* END VARIABLES ************/
+or_circuit_t *
+TO_OR_CIRCUIT(circuit_t *x)
+{
+ tor_assert(x->magic == OR_CIRCUIT_MAGIC);
+ return DOWNCAST(or_circuit_t, x);
+}
+const or_circuit_t *
+CONST_TO_OR_CIRCUIT(const circuit_t *x)
+{
+ tor_assert(x->magic == OR_CIRCUIT_MAGIC);
+ return DOWNCAST(or_circuit_t, x);
+}
+origin_circuit_t *
+TO_ORIGIN_CIRCUIT(circuit_t *x)
+{
+ tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
+ return DOWNCAST(origin_circuit_t, x);
+}
+const origin_circuit_t *
+CONST_TO_ORIGIN_CIRCUIT(const circuit_t *x)
+{
+ tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
+ return DOWNCAST(origin_circuit_t, x);
+}
+
/** A map from channel and circuit ID to circuit. (Lookup performance is
* very important here, since we need to do it every time a cell arrives.) */
typedef struct chan_circid_circuit_map_t {
diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h
index 246f0c881..8eb6fefbf 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -15,6 +15,15 @@
#include "testsupport.h"
#include "hs_ident.h"
+/** Convert a circuit_t* to a pointer to the enclosing or_circuit_t. Assert
+ * if the cast is impossible. */
+or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
+const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
+/** Convert a circuit_t* to a pointer to the enclosing origin_circuit_t.
+ * Assert if the cast is impossible. */
+origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *);
+const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
+
MOCK_DECL(smartlist_t *, circuit_get_global_list, (void));
smartlist_t *circuit_get_global_origin_circuit_list(void);
int circuit_any_opened_circuits(void);
diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index f9f5faa05..5f7f002f4 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -75,6 +75,8 @@
#include "circuitmux.h"
#include "relay.h"
+#include "or_circuit_st.h"
+
/*
* Private typedefs for circuitmux.c
*/
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c
index 94f75c590..bff553a02 100644
--- a/src/or/circuitstats.c
+++ b/src/or/circuitstats.c
@@ -41,6 +41,8 @@
#include "circuitlist.h"
#include "circuituse.h"
+#include "origin_circuit_st.h"
+
#undef log
#include <math.h>
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 45eeff433..3a18c3403 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -59,6 +59,8 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
static void circuit_expire_old_circuits_clientside(void);
static void circuit_increment_failure_count(void);
diff --git a/src/or/command.c b/src/or/command.c
index 39950f41b..148578a26 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -56,6 +56,9 @@
#include "router.h"
#include "routerlist.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
/** How many CELL_CREATE cells have we received, ever? */
uint64_t stats_n_create_cells_processed = 0;
/** How many CELL_CREATED cells have we received, ever? */
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 1ba61609b..b972724a8 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -99,6 +99,8 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
#ifdef HAVE_LINUX_TYPES_H
#include <linux/types.h>
diff --git a/src/or/control.c b/src/or/control.c
index 45914f0c1..183778801 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -84,6 +84,8 @@
#include "control_connection_st.h"
#include "entry_connection_st.h"
#include "or_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
#ifndef _WIN32
#include <pwd.h>
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 15ef6869c..ad66268c3 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -32,6 +32,8 @@
#include "router.h"
#include "workqueue.h"
+#include "or_circuit_st.h"
+
static void queue_pending_tasks(void);
typedef struct worker_state_s {
diff --git a/src/or/directory.h b/src/or/directory.h
index e94c02b6c..8823de4d9 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -61,6 +61,7 @@ void directory_request_set_dir_addr_port(directory_request_t *req,
const tor_addr_port_t *p);
void directory_request_set_directory_id_digest(directory_request_t *req,
const char *digest);
+struct circuit_guard_state_t;
void directory_request_set_guard_state(directory_request_t *req,
struct circuit_guard_state_t *state);
void directory_request_set_router_purpose(directory_request_t *req,
diff --git a/src/or/dns.c b/src/or/dns.c
index 422751553..defc86bc9 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -66,6 +66,7 @@
#include "sandbox.h"
#include "edge_connection_st.h"
+#include "or_circuit_st.h"
#include <event2/event.h>
#include <event2/dns.h>
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 27d760f1a..8aac07451 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -139,6 +139,8 @@
#include "transports.h"
#include "statefile.h"
+#include "origin_circuit_st.h"
+
/** A list of existing guard selection contexts. */
static smartlist_t *guard_contexts = NULL;
/** The currently enabled guard selection context. */
diff --git a/src/or/hs_cell.c b/src/or/hs_cell.c
index 03273a44f..f5ed3df57 100644
--- a/src/or/hs_cell.c
+++ b/src/or/hs_cell.c
@@ -16,6 +16,8 @@
#include "hs_cell.h"
#include "hs_ntor.h"
+#include "origin_circuit_st.h"
+
/* Trunnel. */
#include "ed25519_cert.h"
#include "hs/cell_common.h"
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index a35d2af8b..189ebdc1b 100644
--- a/src/or/hs_circuit.c
+++ b/src/or/hs_circuit.c
@@ -33,6 +33,8 @@
#include "hs/cell_common.h"
#include "hs/cell_establish_intro.h"
+#include "origin_circuit_st.h"
+
/* A circuit is about to become an e2e rendezvous circuit. Check
* <b>circ_purpose</b> and ensure that it's properly set. Return true iff
* circuit purpose is properly set, otherwise return false. */
diff --git a/src/or/hs_circuitmap.c b/src/or/hs_circuitmap.c
index 112c8bdce..fd0a01f8b 100644
--- a/src/or/hs_circuitmap.c
+++ b/src/or/hs_circuitmap.c
@@ -18,6 +18,9 @@
#include "circuitlist.h"
#include "hs_circuitmap.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
/************************** HS circuitmap code *******************************/
/* This is the hidden service circuitmap. It's a hash table that maps
diff --git a/src/or/hs_client.c b/src/or/hs_client.c
index ff84296d0..c4db60e52 100644
--- a/src/or/hs_client.c
+++ b/src/or/hs_client.c
@@ -37,6 +37,7 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "origin_circuit_st.h"
/* Return a human-readable string for the client fetch status code. */
static const char *
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 33c09b53f..afe80467a 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -34,6 +34,7 @@
#include "dirauth/shared_random_state.h"
#include "edge_connection_st.h"
+#include "origin_circuit_st.h"
/* Trunnel */
#include "ed25519_cert.h"
diff --git a/src/or/hs_intropoint.c b/src/or/hs_intropoint.c
index 3274e8e9c..58416fbe9 100644
--- a/src/or/hs_intropoint.c
+++ b/src/or/hs_intropoint.c
@@ -27,6 +27,8 @@
#include "hs_intropoint.h"
#include "hs_common.h"
+#include "or_circuit_st.h"
+
/** Extract the authentication key from an ESTABLISH_INTRO or INTRODUCE1 using
* the given <b>cell_type</b> from <b>cell</b> and place it in
* <b>auth_key_out</b>. */
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 9f12484eb..6c2c16734 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -41,6 +41,7 @@
#include "dir_connection_st.h"
#include "edge_connection_st.h"
+#include "origin_circuit_st.h"
/* Trunnel */
#include "ed25519_cert.h"
diff --git a/src/or/include.am b/src/or/include.am
index de263e9b8..eb8b52e93 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -250,9 +250,11 @@ ORHEADERS = \
src/or/onion_ntor.h \
src/or/onion_tap.h \
src/or/or.h \
+ src/or/or_circuit_st.h \
src/or/or_connection_st.h \
src/or/or_handshake_certs_st.h \
src/or/or_handshake_state_st.h \
+ src/or/origin_circuit_st.h \
src/or/transports.h \
src/or/parsecommon.h \
src/or/periodic.h \
diff --git a/src/or/onion.c b/src/or/onion.c
index 829be12ba..813ad265e 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -77,6 +77,8 @@
#include "rephist.h"
#include "router.h"
+#include "or_circuit_st.h"
+
// trunnel
#include "ed25519_cert.h"
diff --git a/src/or/or.h b/src/or/or.h
index c3506d3ff..61987d825 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2561,6 +2561,9 @@ typedef struct circuit_t {
HT_ENTRY(circuit_t) hs_circuitmap_node;
} circuit_t;
+typedef struct origin_circuit_t origin_circuit_t;
+typedef struct or_circuit_t or_circuit_t;
+
/** Largest number of relay_early cells that we can send on a given
* circuit. */
#define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT 8
@@ -2622,288 +2625,6 @@ typedef enum {
} path_state_t;
#define path_state_bitfield_t ENUM_BF(path_state_t)
-/** An origin_circuit_t holds data necessary to build and use a circuit.
- */
-typedef struct origin_circuit_t {
- circuit_t base_;
-
- /** Linked list of AP streams (or EXIT streams if hidden service)
- * associated with this circuit. */
- edge_connection_t *p_streams;
-
- /** Bytes read on this circuit since last call to
- * control_event_circ_bandwidth_used(). Only used if we're configured
- * to emit CIRC_BW events. */
- uint32_t n_read_circ_bw;
-
- /** Bytes written to on this circuit since last call to
- * control_event_circ_bandwidth_used(). Only used if we're configured
- * to emit CIRC_BW events. */
- uint32_t n_written_circ_bw;
-
- /** Total known-valid relay cell bytes since last call to
- * control_event_circ_bandwidth_used(). Only used if we're configured
- * to emit CIRC_BW events. */
- uint32_t n_delivered_read_circ_bw;
-
- /** Total written relay cell bytes since last call to
- * control_event_circ_bandwidth_used(). Only used if we're configured
- * to emit CIRC_BW events. */
- uint32_t n_delivered_written_circ_bw;
-
- /** Total overhead data in all known-valid relay data cells since last
- * call to control_event_circ_bandwidth_used(). Only used if we're
- * configured to emit CIRC_BW events. */
- uint32_t n_overhead_read_circ_bw;
-
- /** Total written overhead data in all relay data cells since last call to
- * control_event_circ_bandwidth_used(). Only used if we're configured
- * to emit CIRC_BW events. */
- uint32_t n_overhead_written_circ_bw;
-
- /** Build state for this circuit. It includes the intended path
- * length, the chosen exit router, rendezvous information, etc.
- */
- cpath_build_state_t *build_state;
- /** The doubly-linked list of crypt_path_t entries, one per hop,
- * for this circuit. This includes ciphers for each hop,
- * integrity-checking digests for each hop, and package/delivery
- * windows for each hop.
- */
- crypt_path_t *cpath;
-
- /** Holds all rendezvous data on either client or service side. */
- rend_data_t *rend_data;
-
- /** Holds hidden service identifier on either client or service side. This
- * is for both introduction and rendezvous circuit. */
- struct hs_ident_circuit_t *hs_ident;
-
- /** Holds the data that the entry guard system uses to track the
- * status of the guard this circuit is using, and thereby to determine
- * whether this circuit can be used. */
- struct circuit_guard_state_t *guard_state;
-
- /** Index into global_origin_circuit_list for this circuit. -1 if not
- * present. */
- int global_origin_circuit_list_idx;
-
- /** How many more relay_early cells can we send on this circuit, according
- * to the specification? */
- unsigned int remaining_relay_early_cells : 4;
-
- /** Set if this circuit is insanely old and we already informed the user */
- unsigned int is_ancient : 1;
-
- /** Set if this circuit has already been opened. Used to detect
- * cannibalized circuits. */
- unsigned int has_opened : 1;
-
- /**
- * Path bias state machine. Used to ensure integrity of our
- * circuit building and usage accounting. See path_state_t
- * for more details.
- */
- path_state_bitfield_t path_state : 3;
-
- /* If this flag is set, we should not consider attaching any more
- * connections to this circuit. */
- unsigned int unusable_for_new_conns : 1;
-
- /**
- * Tristate variable to guard against pathbias miscounting
- * due to circuit purpose transitions changing the decision
- * of pathbias_should_count(). This variable is informational
- * only. The current results of pathbias_should_count() are
- * the official decision for pathbias accounting.
- */
- uint8_t pathbias_shouldcount;
-#define PATHBIAS_SHOULDCOUNT_UNDECIDED 0
-#define PATHBIAS_SHOULDCOUNT_IGNORED 1
-#define PATHBIAS_SHOULDCOUNT_COUNTED 2
-
- /** For path probing. Store the temporary probe stream ID
- * for response comparison */
- streamid_t pathbias_probe_id;
-
- /** For path probing. Store the temporary probe address nonce
- * (in host byte order) for response comparison. */
- uint32_t pathbias_probe_nonce;
-
- /** Set iff this is a hidden-service circuit which has timed out
- * according to our current circuit-build timeout, but which has
- * been kept around because it might still succeed in connecting to
- * its destination, and which is not a fully-connected rendezvous
- * circuit.
- *
- * (We clear this flag for client-side rendezvous circuits when they
- * are 'joined' to the other side's rendezvous circuit, so that
- * connection_ap_handshake_attach_circuit can put client streams on
- * the circuit. We also clear this flag for service-side rendezvous
- * circuits when they are 'joined' to a client's rend circ, but only
- * for symmetry with the client case. Client-side introduction
- * circuits are closed when we get a joined rend circ, and
- * service-side introduction circuits never have this flag set.) */
- unsigned int hs_circ_has_timed_out : 1;
-
- /** Set iff this circuit has been given a relaxed timeout because
- * no circuits have opened. Used to prevent spamming logs. */
- unsigned int relaxed_timeout : 1;
-
- /** Set iff this is a service-side rendezvous circuit for which a
- * new connection attempt has been launched. We consider launching
- * a new service-side rend circ to a client when the previous one
- * fails; now that we don't necessarily close a service-side rend
- * circ when we launch a new one to the same client, this flag keeps
- * us from launching two retries for the same failed rend circ. */
- unsigned int hs_service_side_rend_circ_has_been_relaunched : 1;
-
- /** What commands were sent over this circuit that decremented the
- * RELAY_EARLY counter? This is for debugging task 878. */
- uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT];
-
- /** How many RELAY_EARLY cells have been sent over this circuit? This is
- * for debugging task 878, too. */
- int relay_early_cells_sent;
-
- /** The next stream_id that will be tried when we're attempting to
- * construct a new AP stream originating at this circuit. */
- streamid_t next_stream_id;
-
- /* The intro key replaces the hidden service's public key if purpose is
- * S_ESTABLISH_INTRO or S_INTRO, provided that no unversioned rendezvous
- * descriptor is used. */
- crypto_pk_t *intro_key;
-
- /** Quasi-global identifier for this circuit; used for control.c */
- /* XXXX NM This can get re-used after 2**32 circuits. */
- uint32_t global_identifier;
-
- /** True if we have associated one stream to this circuit, thereby setting
- * the isolation parameters for this circuit. Note that this doesn't
- * necessarily mean that we've <em>attached</em> any streams to the circuit:
- * we may only have marked up this circuit during the launch process.
- */
- unsigned int isolation_values_set : 1;
- /** True iff any stream has <em>ever</em> been attached to this circuit.
- *
- * In a better world we could use timestamp_dirty for this, but
- * timestamp_dirty is far too overloaded at the moment.
- */
- unsigned int isolation_any_streams_attached : 1;
-
- /** A bitfield of ISO_* flags for every isolation field such that this
- * circuit has had streams with more than one value for that field
- * attached to it. */
- uint8_t isolation_flags_mixed;
-
- /** @name Isolation parameters
- *
- * If any streams have been associated with this circ (isolation_values_set
- * == 1), and all streams associated with the circuit have had the same
- * value for some field ((isolation_flags_mixed & ISO_FOO) == 0), then these
- * elements hold the value for that field.
- *
- * Note again that "associated" is not the same as "attached": we
- * preliminarily associate streams with a circuit while the circuit is being
- * launched, so that we can tell whether we need to launch more circuits.
- *
- * @{
- */
- uint8_t client_proto_type;
- uint8_t client_proto_socksver;
- uint16_t dest_port;
- tor_addr_t client_addr;
- char *dest_address;
- int session_group;
- unsigned nym_epoch;
- size_t socks_username_len;
- uint8_t socks_password_len;
- /* Note that the next two values are NOT NUL-terminated; see
- socks_username_len and socks_password_len for their lengths. */
- char *socks_username;
- char *socks_password;
- /** Global identifier for the first stream attached here; used by
- * ISO_STREAM. */
- uint64_t associated_isolated_stream_global_id;
- /**@}*/
- /** A list of addr_policy_t for this circuit in particular. Used by
- * adjust_exit_policy_from_exitpolicy_failure.
- */
- smartlist_t *prepend_policy;
-
- /** How long do we wait before closing this circuit if it remains
- * completely idle after it was built, in seconds? This value
- * is randomized on a per-circuit basis from CircuitsAvailableTimoeut
- * to 2*CircuitsAvailableTimoeut. */
- int circuit_idle_timeout;
-
-} origin_circuit_t;
-
-struct onion_queue_t;
-
-/** An or_circuit_t holds information needed to implement a circuit at an
- * OR. */
-typedef struct or_circuit_t {
- circuit_t base_;
-
- /** Pointer to an entry on the onion queue, if this circuit is waiting for a
- * chance to give an onionskin to a cpuworker. Used only in onion.c */
- struct onion_queue_t *onionqueue_entry;
- /** Pointer to a workqueue entry, if this circuit has given an onionskin to
- * a cpuworker and is waiting for a response. Used to decide whether it is
- * safe to free a circuit or if it is still in use by a cpuworker. */
- struct workqueue_entry_s *workqueue_entry;
-
- /** The circuit_id used in the previous (backward) hop of this circuit. */
- circid_t p_circ_id;
- /** Queue of cells waiting to be transmitted on p_conn. */
- cell_queue_t p_chan_cells;
- /** The channel that is previous in this circuit. */
- channel_t *p_chan;
- /**
- * Circuit mux associated with p_chan to which this circuit is attached;
- * NULL if we have no p_chan.
- */
- circuitmux_t *p_mux;
- /** Linked list of Exit streams associated with this circuit. */
- edge_connection_t *n_streams;
- /** Linked list of Exit streams associated with this circuit that are
- * still being resolved. */
- edge_connection_t *resolving_streams;
-
- /** Cryptographic state used for encrypting and authenticating relay
- * cells to and from this hop. */
- relay_crypto_t crypto;
-
- /** Points to spliced circuit if purpose is REND_ESTABLISHED, and circuit
- * is not marked for close. */
- struct or_circuit_t *rend_splice;
-
- /** Stores KH for the handshake. */
- char rend_circ_nonce[DIGEST_LEN];/* KH in tor-spec.txt */
-
- /** How many more relay_early cells can we send on this circuit, according
- * to the specification? */
- unsigned int remaining_relay_early_cells : 4;
-
- /* We have already received an INTRODUCE1 cell on this circuit. */
- unsigned int already_received_introduce1 : 1;
-
- /** If set, this circuit carries HS traffic. Consider it in any HS
- * statistics. */
- unsigned int circuit_carries_hs_traffic_stats : 1;
-
- /** Number of cells that were removed from circuit queue; reset every
- * time when writing buffer stats to disk. */
- uint32_t processed_cells;
-
- /** Total time in milliseconds that cells spent in both app-ward and
- * exit-ward queues of this circuit; reset every time when writing
- * buffer stats to disk. */
- uint64_t total_cell_waiting_time;
-} or_circuit_t;
-
#if REND_COOKIE_LEN != DIGEST_LEN
#error "The REND_TOKEN_LEN macro assumes REND_COOKIE_LEN == DIGEST_LEN"
#endif
@@ -2912,15 +2633,6 @@ typedef struct or_circuit_t {
/** Convert a circuit subtype to a circuit_t. */
#define TO_CIRCUIT(x) (&((x)->base_))
-/** Convert a circuit_t* to a pointer to the enclosing or_circuit_t. Assert
- * if the cast is impossible. */
-static or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
-static const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
-/** Convert a circuit_t* to a pointer to the enclosing origin_circuit_t.
- * Assert if the cast is impossible. */
-static origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *);
-static const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
-
/** Return 1 iff <b>node</b> has Exit flag and no BadExit flag.
* Otherwise, return 0.
*/
@@ -2929,28 +2641,6 @@ static inline int node_is_good_exit(const node_t *node)
return node->is_exit && ! node->is_bad_exit;
}
-static inline or_circuit_t *TO_OR_CIRCUIT(circuit_t *x)
-{
- tor_assert(x->magic == OR_CIRCUIT_MAGIC);
- return DOWNCAST(or_circuit_t, x);
-}
-static inline const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *x)
-{
- tor_assert(x->magic == OR_CIRCUIT_MAGIC);
- return DOWNCAST(or_circuit_t, x);
-}
-static inline origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *x)
-{
- tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
- return DOWNCAST(origin_circuit_t, x);
-}
-static inline const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(
- const circuit_t *x)
-{
- tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
- return DOWNCAST(origin_circuit_t, x);
-}
-
/* limits for TCP send and recv buffer size used for constrained sockets */
#define MIN_CONSTRAINED_TCP_BUFFER 2048
#define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */
diff --git a/src/or/or_circuit_st.h b/src/or/or_circuit_st.h
new file mode 100644
index 000000000..19c39f8e6
--- /dev/null
+++ b/src/or/or_circuit_st.h
@@ -0,0 +1,77 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef OR_CIRCUIT_ST_H
+#define OR_CIRCUIT_ST_H
+
+#include "or.h"
+
+struct onion_queue_t;
+
+/** An or_circuit_t holds information needed to implement a circuit at an
+ * OR. */
+struct or_circuit_t {
+ circuit_t base_;
+
+ /** Pointer to an entry on the onion queue, if this circuit is waiting for a
+ * chance to give an onionskin to a cpuworker. Used only in onion.c */
+ struct onion_queue_t *onionqueue_entry;
+ /** Pointer to a workqueue entry, if this circuit has given an onionskin to
+ * a cpuworker and is waiting for a response. Used to decide whether it is
+ * safe to free a circuit or if it is still in use by a cpuworker. */
+ struct workqueue_entry_s *workqueue_entry;
+
+ /** The circuit_id used in the previous (backward) hop of this circuit. */
+ circid_t p_circ_id;
+ /** Queue of cells waiting to be transmitted on p_conn. */
+ cell_queue_t p_chan_cells;
+ /** The channel that is previous in this circuit. */
+ channel_t *p_chan;
+ /**
+ * Circuit mux associated with p_chan to which this circuit is attached;
+ * NULL if we have no p_chan.
+ */
+ circuitmux_t *p_mux;
+ /** Linked list of Exit streams associated with this circuit. */
+ edge_connection_t *n_streams;
+ /** Linked list of Exit streams associated with this circuit that are
+ * still being resolved. */
+ edge_connection_t *resolving_streams;
+
+ /** Cryptographic state used for encrypting and authenticating relay
+ * cells to and from this hop. */
+ relay_crypto_t crypto;
+
+ /** Points to spliced circuit if purpose is REND_ESTABLISHED, and circuit
+ * is not marked for close. */
+ struct or_circuit_t *rend_splice;
+
+ /** Stores KH for the handshake. */
+ char rend_circ_nonce[DIGEST_LEN];/* KH in tor-spec.txt */
+
+ /** How many more relay_early cells can we send on this circuit, according
+ * to the specification? */
+ unsigned int remaining_relay_early_cells : 4;
+
+ /* We have already received an INTRODUCE1 cell on this circuit. */
+ unsigned int already_received_introduce1 : 1;
+
+ /** If set, this circuit carries HS traffic. Consider it in any HS
+ * statistics. */
+ unsigned int circuit_carries_hs_traffic_stats : 1;
+
+ /** Number of cells that were removed from circuit queue; reset every
+ * time when writing buffer stats to disk. */
+ uint32_t processed_cells;
+
+ /** Total time in milliseconds that cells spent in both app-ward and
+ * exit-ward queues of this circuit; reset every time when writing
+ * buffer stats to disk. */
+ uint64_t total_cell_waiting_time;
+};
+
+#endif
+
diff --git a/src/or/origin_circuit_st.h b/src/or/origin_circuit_st.h
new file mode 100644
index 000000000..e995776c2
--- /dev/null
+++ b/src/or/origin_circuit_st.h
@@ -0,0 +1,233 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef ORIGIN_CIRCUIT_ST_H
+#define ORIGIN_CIRCUIT_ST_H
+
+#include "or.h"
+
+struct onion_queue_t;
+
+/** An origin_circuit_t holds data necessary to build and use a circuit.
+ */
+struct origin_circuit_t {
+ circuit_t base_;
+
+ /** Linked list of AP streams (or EXIT streams if hidden service)
+ * associated with this circuit. */
+ edge_connection_t *p_streams;
+
+ /** Bytes read on this circuit since last call to
+ * control_event_circ_bandwidth_used(). Only used if we're configured
+ * to emit CIRC_BW events. */
+ uint32_t n_read_circ_bw;
+
+ /** Bytes written to on this circuit since last call to
+ * control_event_circ_bandwidth_used(). Only used if we're configured
+ * to emit CIRC_BW events. */
+ uint32_t n_written_circ_bw;
+
+ /** Total known-valid relay cell bytes since last call to
+ * control_event_circ_bandwidth_used(). Only used if we're configured
+ * to emit CIRC_BW events. */
+ uint32_t n_delivered_read_circ_bw;
+
+ /** Total written relay cell bytes since last call to
+ * control_event_circ_bandwidth_used(). Only used if we're configured
+ * to emit CIRC_BW events. */
+ uint32_t n_delivered_written_circ_bw;
+
+ /** Total overhead data in all known-valid relay data cells since last
+ * call to control_event_circ_bandwidth_used(). Only used if we're
+ * configured to emit CIRC_BW events. */
+ uint32_t n_overhead_read_circ_bw;
+
+ /** Total written overhead data in all relay data cells since last call to
+ * control_event_circ_bandwidth_used(). Only used if we're configured
+ * to emit CIRC_BW events. */
+ uint32_t n_overhead_written_circ_bw;
+
+ /** Build state for this circuit. It includes the intended path
+ * length, the chosen exit router, rendezvous information, etc.
+ */
+ cpath_build_state_t *build_state;
+ /** The doubly-linked list of crypt_path_t entries, one per hop,
+ * for this circuit. This includes ciphers for each hop,
+ * integrity-checking digests for each hop, and package/delivery
+ * windows for each hop.
+ */
+ crypt_path_t *cpath;
+
+ /** Holds all rendezvous data on either client or service side. */
+ rend_data_t *rend_data;
+
+ /** Holds hidden service identifier on either client or service side. This
+ * is for both introduction and rendezvous circuit. */
+ struct hs_ident_circuit_t *hs_ident;
+
+ /** Holds the data that the entry guard system uses to track the
+ * status of the guard this circuit is using, and thereby to determine
+ * whether this circuit can be used. */
+ struct circuit_guard_state_t *guard_state;
+
+ /** Index into global_origin_circuit_list for this circuit. -1 if not
+ * present. */
+ int global_origin_circuit_list_idx;
+
+ /** How many more relay_early cells can we send on this circuit, according
+ * to the specification? */
+ unsigned int remaining_relay_early_cells : 4;
+
+ /** Set if this circuit is insanely old and we already informed the user */
+ unsigned int is_ancient : 1;
+
+ /** Set if this circuit has already been opened. Used to detect
+ * cannibalized circuits. */
+ unsigned int has_opened : 1;
+
+ /**
+ * Path bias state machine. Used to ensure integrity of our
+ * circuit building and usage accounting. See path_state_t
+ * for more details.
+ */
+ path_state_bitfield_t path_state : 3;
+
+ /* If this flag is set, we should not consider attaching any more
+ * connections to this circuit. */
+ unsigned int unusable_for_new_conns : 1;
+
+ /**
+ * Tristate variable to guard against pathbias miscounting
+ * due to circuit purpose transitions changing the decision
+ * of pathbias_should_count(). This variable is informational
+ * only. The current results of pathbias_should_count() are
+ * the official decision for pathbias accounting.
+ */
+ uint8_t pathbias_shouldcount;
+#define PATHBIAS_SHOULDCOUNT_UNDECIDED 0
+#define PATHBIAS_SHOULDCOUNT_IGNORED 1
+#define PATHBIAS_SHOULDCOUNT_COUNTED 2
+
+ /** For path probing. Store the temporary probe stream ID
+ * for response comparison */
+ streamid_t pathbias_probe_id;
+
+ /** For path probing. Store the temporary probe address nonce
+ * (in host byte order) for response comparison. */
+ uint32_t pathbias_probe_nonce;
+
+ /** Set iff this is a hidden-service circuit which has timed out
+ * according to our current circuit-build timeout, but which has
+ * been kept around because it might still succeed in connecting to
+ * its destination, and which is not a fully-connected rendezvous
+ * circuit.
+ *
+ * (We clear this flag for client-side rendezvous circuits when they
+ * are 'joined' to the other side's rendezvous circuit, so that
+ * connection_ap_handshake_attach_circuit can put client streams on
+ * the circuit. We also clear this flag for service-side rendezvous
+ * circuits when they are 'joined' to a client's rend circ, but only
+ * for symmetry with the client case. Client-side introduction
+ * circuits are closed when we get a joined rend circ, and
+ * service-side introduction circuits never have this flag set.) */
+ unsigned int hs_circ_has_timed_out : 1;
+
+ /** Set iff this circuit has been given a relaxed timeout because
+ * no circuits have opened. Used to prevent spamming logs. */
+ unsigned int relaxed_timeout : 1;
+
+ /** Set iff this is a service-side rendezvous circuit for which a
+ * new connection attempt has been launched. We consider launching
+ * a new service-side rend circ to a client when the previous one
+ * fails; now that we don't necessarily close a service-side rend
+ * circ when we launch a new one to the same client, this flag keeps
+ * us from launching two retries for the same failed rend circ. */
+ unsigned int hs_service_side_rend_circ_has_been_relaunched : 1;
+
+ /** What commands were sent over this circuit that decremented the
+ * RELAY_EARLY counter? This is for debugging task 878. */
+ uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT];
+
+ /** How many RELAY_EARLY cells have been sent over this circuit? This is
+ * for debugging task 878, too. */
+ int relay_early_cells_sent;
+
+ /** The next stream_id that will be tried when we're attempting to
+ * construct a new AP stream originating at this circuit. */
+ streamid_t next_stream_id;
+
+ /* The intro key replaces the hidden service's public key if purpose is
+ * S_ESTABLISH_INTRO or S_INTRO, provided that no unversioned rendezvous
+ * descriptor is used. */
+ crypto_pk_t *intro_key;
+
+ /** Quasi-global identifier for this circuit; used for control.c */
+ /* XXXX NM This can get re-used after 2**32 circuits. */
+ uint32_t global_identifier;
+
+ /** True if we have associated one stream to this circuit, thereby setting
+ * the isolation parameters for this circuit. Note that this doesn't
+ * necessarily mean that we've <em>attached</em> any streams to the circuit:
+ * we may only have marked up this circuit during the launch process.
+ */
+ unsigned int isolation_values_set : 1;
+ /** True iff any stream has <em>ever</em> been attached to this circuit.
+ *
+ * In a better world we could use timestamp_dirty for this, but
+ * timestamp_dirty is far too overloaded at the moment.
+ */
+ unsigned int isolation_any_streams_attached : 1;
+
+ /** A bitfield of ISO_* flags for every isolation field such that this
+ * circuit has had streams with more than one value for that field
+ * attached to it. */
+ uint8_t isolation_flags_mixed;
+
+ /** @name Isolation parameters
+ *
+ * If any streams have been associated with this circ (isolation_values_set
+ * == 1), and all streams associated with the circuit have had the same
+ * value for some field ((isolation_flags_mixed & ISO_FOO) == 0), then these
+ * elements hold the value for that field.
+ *
+ * Note again that "associated" is not the same as "attached": we
+ * preliminarily associate streams with a circuit while the circuit is being
+ * launched, so that we can tell whether we need to launch more circuits.
+ *
+ * @{
+ */
+ uint8_t client_proto_type;
+ uint8_t client_proto_socksver;
+ uint16_t dest_port;
+ tor_addr_t client_addr;
+ char *dest_address;
+ int session_group;
+ unsigned nym_epoch;
+ size_t socks_username_len;
+ uint8_t socks_password_len;
+ /* Note that the next two values are NOT NUL-terminated; see
+ socks_username_len and socks_password_len for their lengths. */
+ char *socks_username;
+ char *socks_password;
+ /** Global identifier for the first stream attached here; used by
+ * ISO_STREAM. */
+ uint64_t associated_isolated_stream_global_id;
+ /**@}*/
+ /** A list of addr_policy_t for this circuit in particular. Used by
+ * adjust_exit_policy_from_exitpolicy_failure.
+ */
+ smartlist_t *prepend_policy;
+
+ /** How long do we wait before closing this circuit if it remains
+ * completely idle after it was built, in seconds? This value
+ * is randomized on a per-circuit basis from CircuitsAvailableTimoeut
+ * to 2*CircuitsAvailableTimoeut. */
+ int circuit_idle_timeout;
+
+};
+
+#endif
+
diff --git a/src/or/relay.c b/src/or/relay.c
index dca31498f..55c2abd12 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -84,6 +84,8 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
static edge_connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell,
cell_direction_t cell_direction,
diff --git a/src/or/relay_crypto.c b/src/or/relay_crypto.c
index 530c8e582..7603d3b4e 100644
--- a/src/or/relay_crypto.c
+++ b/src/or/relay_crypto.c
@@ -5,12 +5,16 @@
/* See LICENSE for licensing information */
#include "or.h"
+#include "circuitlist.h"
#include "config.h"
#include "crypto_util.h"
#include "hs_ntor.h" // for HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN
#include "relay.h"
#include "relay_crypto.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
/** Update digest from the payload of cell. Assign integrity part to
* cell.
*/
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index c46b8c565..6762bbfb0 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -35,6 +35,7 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "origin_circuit_st.h"
static extend_info_t *rend_client_get_random_intro_impl(
const rend_cache_entry_t *rend_query,
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index f3fa2f64d..308b91878 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -12,6 +12,7 @@
#include "or.h"
#include "circuitbuild.h"
+#include "circuitlist.h"
#include "circuituse.h"
#include "config.h"
#include "control.h"
@@ -30,6 +31,8 @@
#include "routerlist.h"
#include "routerparse.h"
+#include "origin_circuit_st.h"
+
/** Return 0 if one and two are the same service ids, else -1 or 1 */
int
rend_cmp_service_ids(const char *one, const char *two)
diff --git a/src/or/rendmid.c b/src/or/rendmid.c
index c4a34ca62..8afc73067 100644
--- a/src/or/rendmid.c
+++ b/src/or/rendmid.c
@@ -20,6 +20,8 @@
#include "hs_circuitmap.h"
#include "hs_intropoint.h"
+#include "or_circuit_st.h"
+
/** Respond to an ESTABLISH_INTRO cell by checking the signed data and
* setting the circuit's purpose and service pk digest.
*/
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 4d9309e49..d1e6f8a8e 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -37,6 +37,7 @@
#include "routerset.h"
#include "edge_connection_st.h"
+#include "origin_circuit_st.h"
struct rend_service_t;
static origin_circuit_t *find_intro_circuit(rend_intro_point_t *intro,
diff --git a/src/or/rephist.c b/src/or/rephist.c
index c7117bad6..909cd043b 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -89,6 +89,8 @@
#include "connection_or.h"
#include "statefile.h"
+#include "or_circuit_st.h"
+
static void bw_arrays_init(void);
static void predicted_ports_alloc(void);
diff --git a/src/or/router.c b/src/or/router.c
index f1fff6be2..11ee2e6ab 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -41,6 +41,7 @@
#include "dir_connection_st.h"
#include "dir_server_st.h"
+#include "origin_circuit_st.h"
#include "port_cfg_st.h"
/**
diff --git a/src/test/bench.c b/src/test/bench.c
index 9ab23c992..784bcf326 100644
--- a/src/test/bench.c
+++ b/src/test/bench.c
@@ -26,6 +26,8 @@
#include "crypto_rand.h"
#include "consdiff.h"
+#include "or_circuit_st.h"
+
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
static uint64_t nanostart;
static inline uint64_t
diff --git a/src/test/test.c b/src/test/test.c
index f0e8b9b72..b92dd3c8a 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -62,6 +62,8 @@ double fabs(double x);
#include "statefile.h"
#include "crypto_curve25519.h"
+#include "or_circuit_st.h"
+
/** Run unit tests for the onion handshake code. */
static void
test_onion_handshake(void *arg)
diff --git a/src/test/test_cell_queue.c b/src/test/test_cell_queue.c
index df987f82c..b41f7ac38 100644
--- a/src/test/test_cell_queue.c
+++ b/src/test/test_cell_queue.c
@@ -8,6 +8,9 @@
#include "relay.h"
#include "test.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
static void
test_cq_manip(void *arg)
{
diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index 76124a6e7..c41afff5d 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -20,6 +20,8 @@
#include "scheduler.h"
#include "networkstatus.h"
+#include "origin_circuit_st.h"
+
/* Test suite stuff */
#include "log_test_helpers.h"
#include "test.h"
diff --git a/src/test/test_circuitlist.c b/src/test/test_circuitlist.c
index 3794ffc2c..86e78c331 100644
--- a/src/test/test_circuitlist.c
+++ b/src/test/test_circuitlist.c
@@ -14,6 +14,9 @@
#include "test.h"
#include "log_test_helpers.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
static channel_t *
new_fake_channel(void)
{
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index 8ebef659c..c03164954 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -17,6 +17,8 @@
#include "circuituse.h"
#include "channel.h"
+#include "origin_circuit_st.h"
+
void test_circuitstats_timeout(void *arg);
void test_circuitstats_hoplen(void *arg);
origin_circuit_t *subtest_fourhop_circuit(struct timeval, int);
diff --git a/src/test/test_circuituse.c b/src/test/test_circuituse.c
index df1b43807..7d1b1d9b0 100644
--- a/src/test/test_circuituse.c
+++ b/src/test/test_circuituse.c
@@ -14,6 +14,8 @@
#include "circuitbuild.h"
#include "nodelist.h"
+#include "origin_circuit_st.h"
+
static void
test_circuit_is_available_for_use_ret_false_when_marked_for_close(void *arg)
{
diff --git a/src/test/test_controller_events.c b/src/test/test_controller_events.c
index e81aea8d6..70ce1a696 100644
--- a/src/test/test_controller_events.c
+++ b/src/test/test_controller_events.c
@@ -11,6 +11,9 @@
#include "control.h"
#include "test.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
static void
add_testing_cell_stats_entry(circuit_t *circ, uint8_t command,
unsigned int waiting_time,
diff --git a/src/test/test_dns.c b/src/test/test_dns.c
index c472b9790..ffc6fb451 100644
--- a/src/test/test_dns.c
+++ b/src/test/test_dns.c
@@ -11,6 +11,7 @@
#include "router.h"
#include "edge_connection_st.h"
+#include "or_circuit_st.h"
#define NS_MODULE dns
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index d4939355d..19a32aa8a 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -34,6 +34,7 @@
#include "test_helpers.h"
#include "log_test_helpers.h"
+#include "origin_circuit_st.h"
/* TODO:
* choose_random_entry() test with state set.
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index 86aeabb7c..91cc7d4d2 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -25,6 +25,7 @@
#include "routerlist.h"
#include "connection_st.h"
+#include "origin_circuit_st.h"
#include "test.h"
#include "test_helpers.h"
diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c
index 0420f70f8..bf0d56f8a 100644
--- a/src/test/test_hs_client.c
+++ b/src/test/test_hs_client.c
@@ -39,6 +39,7 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
+#include "origin_circuit_st.h"
static int
mock_connection_ap_handshake_send_begin(entry_connection_t *ap_conn)
diff --git a/src/test/test_hs_intropoint.c b/src/test/test_hs_intropoint.c
index 4253c9a38..b8462d294 100644
--- a/src/test/test_hs_intropoint.c
+++ b/src/test/test_hs_intropoint.c
@@ -28,6 +28,8 @@
#include "hs_intropoint.h"
#include "hs_service.h"
+#include "or_circuit_st.h"
+
/* Trunnel. */
#include "hs/cell_establish_intro.h"
#include "hs/cell_introduce1.h"
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 33b5e9607..06df50740 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -53,6 +53,8 @@
#include "dirauth/shared_random_state.h"
#include "voting_schedule.h"
+#include "origin_circuit_st.h"
+
/* Trunnel */
#include "hs/cell_establish_intro.h"
diff --git a/src/test/test_oom.c b/src/test/test_oom.c
index 98935fe45..fcee7cc73 100644
--- a/src/test/test_oom.c
+++ b/src/test/test_oom.c
@@ -19,6 +19,8 @@
#include "test_helpers.h"
#include "entry_connection_st.h"
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
/* small replacement mock for circuit_mark_for_close_ to avoid doing all
* the other bookkeeping that comes with marking circuits. */
diff --git a/src/test/test_relay.c b/src/test/test_relay.c
index 73c0ed558..4a526671b 100644
--- a/src/test/test_relay.c
+++ b/src/test/test_relay.c
@@ -9,6 +9,8 @@
/* For init/free stuff */
#include "scheduler.h"
+#include "or_circuit_st.h"
+
/* Test suite stuff */
#include "test.h"
#include "fakechans.h"
diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c
index b4cb9d4bb..e6a673403 100644
--- a/src/test/test_relaycell.c
+++ b/src/test/test_relaycell.c
@@ -17,6 +17,7 @@
#include "test.h"
#include "entry_connection_st.h"
+#include "origin_circuit_st.h"
static int srm_ncalls;
static entry_connection_t *srm_conn;
diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c
index 60bd47971..62bcedabc 100644
--- a/src/test/test_relaycrypt.c
+++ b/src/test/test_relaycrypt.c
@@ -10,6 +10,10 @@
#include "crypto_rand.h"
#include "relay.h"
#include "relay_crypto.h"
+
+#include "or_circuit_st.h"
+#include "origin_circuit_st.h"
+
#include "test.h"
static const char KEY_MATERIAL[3][CPATH_KEY_MATERIAL_LEN] = {
diff --git a/src/test/test_status.c b/src/test/test_status.c
index b4ca17891..062a28f73 100644
--- a/src/test/test_status.c
+++ b/src/test/test_status.c
@@ -24,6 +24,9 @@
#include "main.h"
#include "nodelist.h"
#include "statefile.h"
+
+#include "origin_circuit_st.h"
+
#include "test.h"
#define NS_MODULE status
1
0

[tor/master] Extract rend_service_descriptor_t into its own header.
by nickm@torproject.org 18 Jun '18
by nickm@torproject.org 18 Jun '18
18 Jun '18
commit 22e9c647387509b44ff75e232aede360e3f87070
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:18:17 2018 -0400
Extract rend_service_descriptor_t into its own header.
---
src/or/control.c | 1 +
src/or/directory.c | 1 +
src/or/include.am | 1 +
src/or/or.h | 23 +----------------------
src/or/rend_service_descriptor_st.h | 34 ++++++++++++++++++++++++++++++++++
src/or/rendcache.c | 2 ++
src/or/rendclient.c | 1 +
src/or/rendcommon.c | 1 +
src/or/rendservice.c | 1 +
src/or/routerparse.c | 7 ++++---
src/test/fuzz/fuzz_iptsv2.c | 3 +++
src/test/rend_test_helpers.c | 2 ++
src/test/test.c | 1 +
src/test/test_rendcache.c | 3 +++
14 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/src/or/control.c b/src/or/control.c
index 972462e38..401135ca8 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -87,6 +87,7 @@
#include "or_connection_st.h"
#include "or_circuit_st.h"
#include "origin_circuit_st.h"
+#include "rend_service_descriptor_st.h"
#ifndef _WIN32
#include <pwd.h>
diff --git a/src/or/directory.c b/src/or/directory.c
index 65aaaa38a..720ef975b 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -56,6 +56,7 @@
#include "dir_connection_st.h"
#include "dir_server_st.h"
#include "entry_connection_st.h"
+#include "rend_service_descriptor_st.h"
/**
* \file directory.c
diff --git a/src/or/include.am b/src/or/include.am
index 618ffacd0..883366fc1 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -279,6 +279,7 @@ ORHEADERS = \
src/or/rendcommon.h \
src/or/rendmid.h \
src/or/rendservice.h \
+ src/or/rend_service_descriptor_st.h \
src/or/rephist.h \
src/or/replaycache.h \
src/or/router.h \
diff --git a/src/or/or.h b/src/or/or.h
index b67896d2a..e66bad5ab 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -4145,28 +4145,7 @@ typedef struct rend_intro_point_t {
unsigned int circuit_established:1;
} rend_intro_point_t;
-#define REND_PROTOCOL_VERSION_BITMASK_WIDTH 16
-
-/** Information used to connect to a hidden service. Used on both the
- * service side and the client side. */
-typedef struct rend_service_descriptor_t {
- crypto_pk_t *pk; /**< This service's public key. */
- int version; /**< Version of the descriptor format: 0 or 2. */
- time_t timestamp; /**< Time when the descriptor was generated. */
- /** Bitmask: which introduce/rendezvous protocols are supported?
- * (We allow bits '0', '1', '2' and '3' to be set.) */
- unsigned protocols : REND_PROTOCOL_VERSION_BITMASK_WIDTH;
- /** List of the service's introduction points. Elements are removed if
- * introduction attempts fail. */
- smartlist_t *intro_nodes;
- /** Has descriptor been uploaded to all hidden service directories? */
- int all_uploads_performed;
- /** List of hidden service directories to which an upload request for
- * this descriptor could be sent. Smartlist exists only when at least one
- * of the previous upload requests failed (otherwise it's not important
- * to know which uploads succeeded and which not). */
- smartlist_t *successful_uploads;
-} rend_service_descriptor_t;
+typedef struct rend_service_descriptor_t rend_service_descriptor_t;
/********************************* routerlist.c ***************************/
diff --git a/src/or/rend_service_descriptor_st.h b/src/or/rend_service_descriptor_st.h
new file mode 100644
index 000000000..bd6d55b6a
--- /dev/null
+++ b/src/or/rend_service_descriptor_st.h
@@ -0,0 +1,34 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef REND_SERVICE_DESCRIPTOR_ST_H
+#define REND_SERVICE_DESCRIPTOR_ST_H
+
+#define REND_PROTOCOL_VERSION_BITMASK_WIDTH 16
+
+/** Information used to connect to a hidden service. Used on both the
+ * service side and the client side. */
+struct rend_service_descriptor_t {
+ crypto_pk_t *pk; /**< This service's public key. */
+ int version; /**< Version of the descriptor format: 0 or 2. */
+ time_t timestamp; /**< Time when the descriptor was generated. */
+ /** Bitmask: which introduce/rendezvous protocols are supported?
+ * (We allow bits '0', '1', '2' and '3' to be set.) */
+ unsigned protocols : REND_PROTOCOL_VERSION_BITMASK_WIDTH;
+ /** List of the service's introduction points. Elements are removed if
+ * introduction attempts fail. */
+ smartlist_t *intro_nodes;
+ /** Has descriptor been uploaded to all hidden service directories? */
+ int all_uploads_performed;
+ /** List of hidden service directories to which an upload request for
+ * this descriptor could be sent. Smartlist exists only when at least one
+ * of the previous upload requests failed (otherwise it's not important
+ * to know which uploads succeeded and which not). */
+ smartlist_t *successful_uploads;
+};
+
+#endif
+
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index d27e1c293..6dd49ee9c 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -15,6 +15,8 @@
#include "routerparse.h"
#include "rendcommon.h"
+#include "rend_service_descriptor_st.h"
+
/** Map from service id (as generated by rend_get_service_id) to
* rend_cache_entry_t. */
STATIC strmap_t *rend_cache = NULL;
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index c55f63c33..1d12e1829 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -38,6 +38,7 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "origin_circuit_st.h"
+#include "rend_service_descriptor_st.h"
static extend_info_t *rend_client_get_random_intro_impl(
const rend_cache_entry_t *rend_query,
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 719a1537c..b2d4b0949 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -34,6 +34,7 @@
#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
+#include "rend_service_descriptor_st.h"
/** Return 0 if one and two are the same service ids, else -1 or 1 */
int
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index ef46ff6ce..e27e8c4fb 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -41,6 +41,7 @@
#include "crypt_path_reference_st.h"
#include "edge_connection_st.h"
#include "origin_circuit_st.h"
+#include "rend_service_descriptor_st.h"
struct rend_service_t;
static origin_circuit_t *find_intro_circuit(rend_intro_point_t *intro,
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 06a37904d..af11bc3d5 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -79,13 +79,14 @@
#include "torcert.h"
#include "voting_schedule.h"
-#undef log
-#include <math.h>
-
#include "dirauth/dirvote.h"
+#include "rend_service_descriptor_st.h"
#include "tor_version_st.h"
+#undef log
+#include <math.h>
+
/****************************************************************************/
/** List of tokens recognized in router descriptors */
diff --git a/src/test/fuzz/fuzz_iptsv2.c b/src/test/fuzz/fuzz_iptsv2.c
index 4abde0c16..db99f62dc 100644
--- a/src/test/fuzz/fuzz_iptsv2.c
+++ b/src/test/fuzz/fuzz_iptsv2.c
@@ -4,6 +4,9 @@
#include "or.h"
#include "routerparse.h"
#include "rendcommon.h"
+
+#include "rend_service_descriptor_st.h"
+
#include "fuzzing.h"
static void
diff --git a/src/test/rend_test_helpers.c b/src/test/rend_test_helpers.c
index 9ac3894b0..177935edf 100644
--- a/src/test/rend_test_helpers.c
+++ b/src/test/rend_test_helpers.c
@@ -7,6 +7,8 @@
#include "rendcommon.h"
#include "rend_test_helpers.h"
+#include "rend_service_descriptor_st.h"
+
void
generate_desc(int time_diff, rend_encoded_v2_service_descriptor_t **desc,
char **service_id, int intro_points)
diff --git a/src/test/test.c b/src/test/test.c
index b92dd3c8a..040861560 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -63,6 +63,7 @@ double fabs(double x);
#include "crypto_curve25519.h"
#include "or_circuit_st.h"
+#include "rend_service_descriptor_st.h"
/** Run unit tests for the onion handshake code. */
static void
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index 9f6cfc4a2..f1e94eb02 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -11,6 +11,9 @@
#include "routerlist.h"
#include "config.h"
#include "hs_common.h"
+
+#include "rend_service_descriptor_st.h"
+
#include "rend_test_helpers.h"
#include "log_test_helpers.h"
1
0

18 Jun '18
commit d51de7731107ee6911c0c849260705ba9b1c3673
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:07:20 2018 -0400
Extract cpath_build_state into its own header.
More modules use this than I had expected!
---
src/or/circpathbias.c | 1 +
src/or/circuitbuild.c | 1 +
src/or/circuitlist.c | 1 +
src/or/circuituse.c | 1 +
src/or/connection_edge.c | 1 +
src/or/control.c | 1 +
src/or/cpath_build_state_st.h | 38 ++++++++++++++++++++++++++++++++++++++
src/or/hs_circuit.c | 1 +
src/or/hs_client.c | 1 +
src/or/include.am | 1 +
src/or/or.h | 27 +--------------------------
src/or/relay.c | 1 +
src/or/rendclient.c | 1 +
src/or/rendcommon.c | 1 +
src/or/rendservice.c | 1 +
src/test/test_circuitstats.c | 1 +
src/test/test_circuituse.c | 1 +
src/test/test_entrynodes.c | 1 +
src/test/test_hs_client.c | 1 +
src/test/test_hs_service.c | 1 +
20 files changed, 57 insertions(+), 26 deletions(-)
diff --git a/src/or/circpathbias.c b/src/or/circpathbias.c
index d1bdaedc3..9ca45df27 100644
--- a/src/or/circpathbias.c
+++ b/src/or/circpathbias.c
@@ -35,6 +35,7 @@
#include "networkstatus.h"
#include "relay.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index c5d1c65f5..0df616a5a 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -65,6 +65,7 @@
#include "routerset.h"
#include "transports.h"
+#include "cpath_build_state_st.h"
#include "entry_connection_st.h"
#include "or_circuit_st.h"
#include "origin_circuit_st.h"
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 3f03ae2f4..46974aea4 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -92,6 +92,7 @@
#include "ht.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_reference_st.h"
#include "dir_connection_st.h"
#include "edge_connection_st.h"
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 3a18c3403..626aff7bb 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -57,6 +57,7 @@
#include "router.h"
#include "routerlist.h"
+#include "cpath_build_state_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "or_circuit_st.h"
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index b972724a8..27ee0ea27 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -97,6 +97,7 @@
#include "routerset.h"
#include "circuitbuild.h"
+#include "cpath_build_state_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "or_circuit_st.h"
diff --git a/src/or/control.c b/src/or/control.c
index 183778801..972462e38 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -82,6 +82,7 @@
#include "shared_random_client.h"
#include "control_connection_st.h"
+#include "cpath_build_state_st.h"
#include "entry_connection_st.h"
#include "or_connection_st.h"
#include "or_circuit_st.h"
diff --git a/src/or/cpath_build_state_st.h b/src/or/cpath_build_state_st.h
new file mode 100644
index 000000000..504f638db
--- /dev/null
+++ b/src/or/cpath_build_state_st.h
@@ -0,0 +1,38 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CIRCUIT_BUILD_STATE_ST_ST_H
+#define CIRCUIT_BUILD_STATE_ST_ST_H
+
+/** Information used to build a circuit. */
+struct cpath_build_state_t {
+ /** Intended length of the final circuit. */
+ int desired_path_len;
+ /** How to extend to the planned exit node. */
+ extend_info_t *chosen_exit;
+ /** Whether every node in the circ must have adequate uptime. */
+ unsigned int need_uptime : 1;
+ /** Whether every node in the circ must have adequate capacity. */
+ unsigned int need_capacity : 1;
+ /** Whether the last hop was picked with exiting in mind. */
+ unsigned int is_internal : 1;
+ /** Did we pick this as a one-hop tunnel (not safe for other streams)?
+ * These are for encrypted dir conns that exit to this router, not
+ * for arbitrary exits from the circuit. */
+ unsigned int onehop_tunnel : 1;
+ /** The crypt_path_t to append after rendezvous: used for rendezvous. */
+ crypt_path_t *pending_final_cpath;
+ /** A ref-counted reference to the crypt_path_t to append after
+ * rendezvous; used on the service side. */
+ crypt_path_reference_t *service_pending_final_cpath_ref;
+ /** How many times has building a circuit for this task failed? */
+ int failure_count;
+ /** At what time should we give up on this task? */
+ time_t expiry_time;
+};
+
+#endif
+
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index 56ae4a152..b5ac7184a 100644
--- a/src/or/hs_circuit.c
+++ b/src/or/hs_circuit.c
@@ -33,6 +33,7 @@
#include "hs/cell_common.h"
#include "hs/cell_establish_intro.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
diff --git a/src/or/hs_client.c b/src/or/hs_client.c
index c4db60e52..18276bfb8 100644
--- a/src/or/hs_client.c
+++ b/src/or/hs_client.c
@@ -35,6 +35,7 @@
#include "router.h"
#include "routerset.h"
+#include "cpath_build_state_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "origin_circuit_st.h"
diff --git a/src/or/include.am b/src/or/include.am
index e15b58c38..e38013f02 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -206,6 +206,7 @@ ORHEADERS = \
src/or/consdiffmgr.h \
src/or/control_connection_st.h \
src/or/control.h \
+ src/or/cpath_build_state_st.h \
src/or/crypt_path_st.h \
src/or/crypt_path_reference_st.h \
src/or/cpuworker.h \
diff --git a/src/or/or.h b/src/or/or.h
index 5c8267cf5..4403aae83 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2286,32 +2286,7 @@ typedef struct crypt_path_reference_t crypt_path_reference_t;
#define DH_KEY_LEN DH_BYTES
-/** Information used to build a circuit. */
-typedef struct {
- /** Intended length of the final circuit. */
- int desired_path_len;
- /** How to extend to the planned exit node. */
- extend_info_t *chosen_exit;
- /** Whether every node in the circ must have adequate uptime. */
- unsigned int need_uptime : 1;
- /** Whether every node in the circ must have adequate capacity. */
- unsigned int need_capacity : 1;
- /** Whether the last hop was picked with exiting in mind. */
- unsigned int is_internal : 1;
- /** Did we pick this as a one-hop tunnel (not safe for other streams)?
- * These are for encrypted dir conns that exit to this router, not
- * for arbitrary exits from the circuit. */
- unsigned int onehop_tunnel : 1;
- /** The crypt_path_t to append after rendezvous: used for rendezvous. */
- crypt_path_t *pending_final_cpath;
- /** A ref-counted reference to the crypt_path_t to append after
- * rendezvous; used on the service side. */
- crypt_path_reference_t *service_pending_final_cpath_ref;
- /** How many times has building a circuit for this task failed? */
- int failure_count;
- /** At what time should we give up on this task? */
- time_t expiry_time;
-} cpath_build_state_t;
+typedef struct cpath_build_state_t cpath_build_state_t;
/** "magic" value for an origin_circuit_t */
#define ORIGIN_CIRCUIT_MAGIC 0x35315243u
diff --git a/src/or/relay.c b/src/or/relay.c
index 55c2abd12..127609a2b 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -82,6 +82,7 @@
#include "scheduler.h"
#include "rephist.h"
+#include "cpath_build_state_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "or_circuit_st.h"
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 8e621562a..c55f63c33 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -33,6 +33,7 @@
#include "routerlist.h"
#include "routerset.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 116ca730f..719a1537c 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -31,6 +31,7 @@
#include "routerlist.h"
#include "routerparse.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 20a4288af..ef46ff6ce 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -36,6 +36,7 @@
#include "routerparse.h"
#include "routerset.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "crypt_path_reference_st.h"
#include "edge_connection_st.h"
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index 8efde6f84..9f6f4626d 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -17,6 +17,7 @@
#include "circuituse.h"
#include "channel.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
diff --git a/src/test/test_circuituse.c b/src/test/test_circuituse.c
index 7d1b1d9b0..16ae84380 100644
--- a/src/test/test_circuituse.c
+++ b/src/test/test_circuituse.c
@@ -14,6 +14,7 @@
#include "circuitbuild.h"
#include "nodelist.h"
+#include "cpath_build_state_st.h"
#include "origin_circuit_st.h"
static void
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 83a3ecbfc..bff6a40bd 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -30,6 +30,7 @@
#include "statefile.h"
#include "util.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "dir_connection_st.h"
#include "origin_circuit_st.h"
diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c
index 4443bd922..98e95be09 100644
--- a/src/test/test_hs_client.c
+++ b/src/test/test_hs_client.c
@@ -37,6 +37,7 @@
#include "connection_edge.h"
#include "networkstatus.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 947243e67..348778550 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -53,6 +53,7 @@
#include "dirauth/shared_random_state.h"
#include "voting_schedule.h"
+#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
1
0

18 Jun '18
commit c846b0e486786f228a51f39d32b83d83f15bd3cd
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 11:57:48 2018 -0400
Extract crypt_path_reference_t into its own header.
---
src/or/circuitlist.c | 1 +
src/or/crypt_path_reference_st.h | 23 +++++++++++++++++++++++
src/or/include.am | 1 +
src/or/or.h | 13 +------------
src/or/rendservice.c | 1 +
5 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 7601bc613..3f03ae2f4 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -92,6 +92,7 @@
#include "ht.h"
+#include "crypt_path_reference_st.h"
#include "dir_connection_st.h"
#include "edge_connection_st.h"
#include "or_circuit_st.h"
diff --git a/src/or/crypt_path_reference_st.h b/src/or/crypt_path_reference_st.h
new file mode 100644
index 000000000..2758a281c
--- /dev/null
+++ b/src/or/crypt_path_reference_st.h
@@ -0,0 +1,23 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CRYPT_PATH_REFERENCE_ST_H
+#define CRYPT_PATH_REFERENCE_ST_H
+
+/** A reference-counted pointer to a crypt_path_t, used only to share
+ * the final rendezvous cpath to be used on a service-side rendezvous
+ * circuit among multiple circuits built in parallel to the same
+ * destination rendezvous point. */
+struct crypt_path_reference_t {
+ /** The reference count. */
+ unsigned int refcount;
+ /** The pointer. Set to NULL when the crypt_path_t is put into use
+ * on an opened rendezvous circuit. */
+ crypt_path_t *cpath;
+};
+
+#endif
+
diff --git a/src/or/include.am b/src/or/include.am
index 0a58796e0..e15b58c38 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -207,6 +207,7 @@ ORHEADERS = \
src/or/control_connection_st.h \
src/or/control.h \
src/or/crypt_path_st.h \
+ src/or/crypt_path_reference_st.h \
src/or/cpuworker.h \
src/or/directory.h \
src/or/dirserv.h \
diff --git a/src/or/or.h b/src/or/or.h
index df232604e..5c8267cf5 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2280,18 +2280,7 @@ typedef struct {
typedef struct relay_crypto_t relay_crypto_t;
typedef struct crypt_path_t crypt_path_t;
-
-/** A reference-counted pointer to a crypt_path_t, used only to share
- * the final rendezvous cpath to be used on a service-side rendezvous
- * circuit among multiple circuits built in parallel to the same
- * destination rendezvous point. */
-typedef struct {
- /** The reference count. */
- unsigned int refcount;
- /** The pointer. Set to NULL when the crypt_path_t is put into use
- * on an opened rendezvous circuit. */
- crypt_path_t *cpath;
-} crypt_path_reference_t;
+typedef struct crypt_path_reference_t crypt_path_reference_t;
#define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 09a52ea07..20a4288af 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -37,6 +37,7 @@
#include "routerset.h"
#include "crypt_path_st.h"
+#include "crypt_path_reference_st.h"
#include "edge_connection_st.h"
#include "origin_circuit_st.h"
1
0
commit f8794b0b36ad400a228fa3cfd96d7a250632dd29
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:50:07 2018 -0400
Move vote_schedule into its own header.
---
src/or/dirauth/dirvote.c | 1 +
src/or/include.am | 1 +
src/or/or.h | 13 +------------
src/or/vote_timing_st.h | 24 ++++++++++++++++++++++++
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/or/dirauth/dirvote.c b/src/or/dirauth/dirvote.c
index 3a2df5ee6..ae2de57a8 100644
--- a/src/or/dirauth/dirvote.c
+++ b/src/or/dirauth/dirvote.c
@@ -29,6 +29,7 @@
#include "dirauth/shared_random_state.h"
#include "dir_server_st.h"
+#include "vote_timing_st.h"
/**
* \file dirvote.c
diff --git a/src/or/include.am b/src/or/include.am
index 353d52ea2..87a353828 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -299,6 +299,7 @@ ORHEADERS = \
src/or/torcert.h \
src/or/tor_api_internal.h \
src/or/tor_version_st.h \
+ src/or/vote_timing_st.h \
src/or/voting_schedule.h
# We add the headers of the modules even though they are disabled so we can
diff --git a/src/or/or.h b/src/or/or.h
index d390c47bf..dd46bfd05 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3913,18 +3913,7 @@ typedef struct measured_bw_line_t {
/********************************* dirvote.c ************************/
-/** Describes the schedule by which votes should be generated. */
-typedef struct vote_timing_t {
- /** Length in seconds between one consensus becoming valid and the next
- * becoming valid. */
- int vote_interval;
- /** For how many intervals is a consensus valid? */
- int n_intervals_valid;
- /** Time in seconds allowed to propagate votes */
- int vote_delay;
- /** Time in seconds allowed to propagate signatures */
- int dist_delay;
-} vote_timing_t;
+typedef struct vote_timing_t vote_timing_t;
/********************************* geoip.c **************************/
diff --git a/src/or/vote_timing_st.h b/src/or/vote_timing_st.h
new file mode 100644
index 000000000..3bf361907
--- /dev/null
+++ b/src/or/vote_timing_st.h
@@ -0,0 +1,24 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef VOTE_TIMING_ST_H
+#define VOTE_TIMING_ST_H
+
+/** Describes the schedule by which votes should be generated. */
+struct vote_timing_t {
+ /** Length in seconds between one consensus becoming valid and the next
+ * becoming valid. */
+ int vote_interval;
+ /** For how many intervals is a consensus valid? */
+ int n_intervals_valid;
+ /** Time in seconds allowed to propagate votes */
+ int vote_delay;
+ /** Time in seconds allowed to propagate signatures */
+ int dist_delay;
+};
+
+#endif
+
1
0
commit c9e4ebf96a9d5fe8d6ae74be96ea00f8c5d493ac
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:52:22 2018 -0400
Move fp_pair_t declaration to fp_pair.h.
---
src/or/directory.c | 1 +
src/or/fp_pair.h | 6 ++++++
src/or/or.h | 8 --------
src/test/test_dir.c | 1 +
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/or/directory.c b/src/or/directory.c
index 720ef975b..00605c054 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -23,6 +23,7 @@
#include "directory.h"
#include "dirserv.h"
#include "entrynodes.h"
+#include "fp_pair.h"
#include "geoip.h"
#include "hs_cache.h"
#include "hs_common.h"
diff --git a/src/or/fp_pair.h b/src/or/fp_pair.h
index 4498a1610..3c5c33bcb 100644
--- a/src/or/fp_pair.h
+++ b/src/or/fp_pair.h
@@ -9,6 +9,12 @@
#ifndef _TOR_FP_PAIR_H
#define _TOR_FP_PAIR_H
+/** A pair of digests created by dir_split_resource_info_fingerprint_pairs() */
+typedef struct {
+ char first[DIGEST_LEN];
+ char second[DIGEST_LEN];
+} fp_pair_t;
+
/*
* Declare fp_pair_map_t functions and structs
*/
diff --git a/src/or/or.h b/src/or/or.h
index dd46bfd05..5b7d4344c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3877,14 +3877,6 @@ typedef enum {
BOOTSTRAP_STATUS_DONE=100
} bootstrap_status_t;
-/********************************* directory.c ***************************/
-
-/** A pair of digests created by dir_split_resource_info_fingerprint_pairs() */
-typedef struct {
- char first[DIGEST_LEN];
- char second[DIGEST_LEN];
-} fp_pair_t;
-
/********************************* dirserv.c ***************************/
/** An enum to describe what format we're generating a routerstatus line in.
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 5bcbc80e8..43fc5c5fb 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -28,6 +28,7 @@
#include "dirserv.h"
#include "dirauth/dirvote.h"
#include "entrynodes.h"
+#include "fp_pair.h"
#include "hibernate.h"
#include "memarea.h"
#include "networkstatus.h"
1
0

18 Jun '18
commit 990184da4976f98365ca7d98762e91a66f1d3009
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:23:06 2018 -0400
Extract rend_intro_point_t into its own header.
---
src/or/include.am | 1 +
src/or/or.h | 64 +-------------------------------------
src/or/rend_intro_point_st.h | 74 ++++++++++++++++++++++++++++++++++++++++++++
src/or/rendcache.c | 1 +
src/or/rendclient.c | 1 +
src/or/rendcommon.c | 1 +
src/or/rendservice.c | 1 +
src/or/routerparse.c | 1 +
src/test/rend_test_helpers.c | 1 +
src/test/test.c | 1 +
src/test/test_hs.c | 3 ++
src/test/test_rendcache.c | 1 +
12 files changed, 87 insertions(+), 63 deletions(-)
diff --git a/src/or/include.am b/src/or/include.am
index 883366fc1..ede01c79e 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -279,6 +279,7 @@ ORHEADERS = \
src/or/rendcommon.h \
src/or/rendmid.h \
src/or/rendservice.h \
+ src/or/rend_intro_point_st.h \
src/or/rend_service_descriptor_st.h \
src/or/rephist.h \
src/or/replaycache.h \
diff --git a/src/or/or.h b/src/or/or.h
index e66bad5ab..41953806a 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -4082,69 +4082,7 @@ typedef struct rend_encoded_v2_service_descriptor_t {
* lifetime so this is a hard limit on the amount of time we do that. */
#define MAX_INTRO_POINT_CIRCUIT_RETRIES 3
-/** Introduction point information. Used both in rend_service_t (on
- * the service side) and in rend_service_descriptor_t (on both the
- * client and service side). */
-typedef struct rend_intro_point_t {
- extend_info_t *extend_info; /**< Extend info for connecting to this
- * introduction point via a multi-hop path. */
- crypto_pk_t *intro_key; /**< Introduction key that replaces the service
- * key, if this descriptor is V2. */
-
- /** (Client side only) Flag indicating that a timeout has occurred
- * after sending an INTRODUCE cell to this intro point. After a
- * timeout, an intro point should not be tried again during the same
- * hidden service connection attempt, but it may be tried again
- * during a future connection attempt. */
- unsigned int timed_out : 1;
-
- /** (Client side only) The number of times we have failed to build a
- * circuit to this intro point for some reason other than our
- * circuit-build timeout. See also MAX_INTRO_POINT_REACHABILITY_FAILURES. */
- unsigned int unreachable_count : 3;
-
- /** (Service side only) Flag indicating that this intro point was
- * included in the last HS descriptor we generated. */
- unsigned int listed_in_last_desc : 1;
-
- /** (Service side only) A replay cache recording the RSA-encrypted parts
- * of INTRODUCE2 cells this intro point's circuit has received. This is
- * used to prevent replay attacks. */
- replaycache_t *accepted_intro_rsa_parts;
-
- /** (Service side only) Count of INTRODUCE2 cells accepted from this
- * intro point.
- */
- int accepted_introduce2_count;
-
- /** (Service side only) Maximum number of INTRODUCE2 cells that this IP
- * will accept. This is a random value between
- * INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS and
- * INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS. */
- int max_introductions;
-
- /** (Service side only) The time at which this intro point was first
- * published, or -1 if this intro point has not yet been
- * published. */
- time_t time_published;
-
- /** (Service side only) The time at which this intro point should
- * (start to) expire, or -1 if we haven't decided when this intro
- * point should expire. */
- time_t time_to_expire;
-
- /** (Service side only) The amount of circuit creation we've made to this
- * intro point. This is incremented every time we do a circuit relaunch on
- * this object which is triggered when the circuit dies but the node is
- * still in the consensus. After MAX_INTRO_POINT_CIRCUIT_RETRIES, we give
- * up on it. */
- unsigned int circuit_retries;
-
- /** (Service side only) Set if this intro point has an established circuit
- * and unset if it doesn't. */
- unsigned int circuit_established:1;
-} rend_intro_point_t;
-
+typedef struct rend_intro_point_t rend_intro_point_t;
typedef struct rend_service_descriptor_t rend_service_descriptor_t;
/********************************* routerlist.c ***************************/
diff --git a/src/or/rend_intro_point_st.h b/src/or/rend_intro_point_st.h
new file mode 100644
index 000000000..934b6ea82
--- /dev/null
+++ b/src/or/rend_intro_point_st.h
@@ -0,0 +1,74 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef REND_INTRO_POINT_ST_H
+#define REND_INTRO_POINT_ST_H
+
+/** Introduction point information. Used both in rend_service_t (on
+ * the service side) and in rend_service_descriptor_t (on both the
+ * client and service side). */
+struct rend_intro_point_t {
+ extend_info_t *extend_info; /**< Extend info for connecting to this
+ * introduction point via a multi-hop path. */
+ crypto_pk_t *intro_key; /**< Introduction key that replaces the service
+ * key, if this descriptor is V2. */
+
+ /** (Client side only) Flag indicating that a timeout has occurred
+ * after sending an INTRODUCE cell to this intro point. After a
+ * timeout, an intro point should not be tried again during the same
+ * hidden service connection attempt, but it may be tried again
+ * during a future connection attempt. */
+ unsigned int timed_out : 1;
+
+ /** (Client side only) The number of times we have failed to build a
+ * circuit to this intro point for some reason other than our
+ * circuit-build timeout. See also MAX_INTRO_POINT_REACHABILITY_FAILURES. */
+ unsigned int unreachable_count : 3;
+
+ /** (Service side only) Flag indicating that this intro point was
+ * included in the last HS descriptor we generated. */
+ unsigned int listed_in_last_desc : 1;
+
+ /** (Service side only) A replay cache recording the RSA-encrypted parts
+ * of INTRODUCE2 cells this intro point's circuit has received. This is
+ * used to prevent replay attacks. */
+ replaycache_t *accepted_intro_rsa_parts;
+
+ /** (Service side only) Count of INTRODUCE2 cells accepted from this
+ * intro point.
+ */
+ int accepted_introduce2_count;
+
+ /** (Service side only) Maximum number of INTRODUCE2 cells that this IP
+ * will accept. This is a random value between
+ * INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS and
+ * INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS. */
+ int max_introductions;
+
+ /** (Service side only) The time at which this intro point was first
+ * published, or -1 if this intro point has not yet been
+ * published. */
+ time_t time_published;
+
+ /** (Service side only) The time at which this intro point should
+ * (start to) expire, or -1 if we haven't decided when this intro
+ * point should expire. */
+ time_t time_to_expire;
+
+ /** (Service side only) The amount of circuit creation we've made to this
+ * intro point. This is incremented every time we do a circuit relaunch on
+ * this object which is triggered when the circuit dies but the node is
+ * still in the consensus. After MAX_INTRO_POINT_CIRCUIT_RETRIES, we give
+ * up on it. */
+ unsigned int circuit_retries;
+
+ /** (Service side only) Set if this intro point has an established circuit
+ * and unset if it doesn't. */
+ unsigned int circuit_established:1;
+};
+
+#endif
+
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index 6dd49ee9c..093cbe7ce 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -15,6 +15,7 @@
#include "routerparse.h"
#include "rendcommon.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
/** Map from service id (as generated by rend_get_service_id) to
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 1d12e1829..a48f83fa9 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -38,6 +38,7 @@
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#include "origin_circuit_st.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
static extend_info_t *rend_client_get_random_intro_impl(
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index b2d4b0949..2494311cb 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -34,6 +34,7 @@
#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
/** Return 0 if one and two are the same service ids, else -1 or 1 */
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index e27e8c4fb..d82ea4789 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -41,6 +41,7 @@
#include "crypt_path_reference_st.h"
#include "edge_connection_st.h"
#include "origin_circuit_st.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
struct rend_service_t;
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index af11bc3d5..20a6f85a4 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -81,6 +81,7 @@
#include "dirauth/dirvote.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
#include "tor_version_st.h"
diff --git a/src/test/rend_test_helpers.c b/src/test/rend_test_helpers.c
index 177935edf..fb2e4cf50 100644
--- a/src/test/rend_test_helpers.c
+++ b/src/test/rend_test_helpers.c
@@ -7,6 +7,7 @@
#include "rendcommon.h"
#include "rend_test_helpers.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
void
diff --git a/src/test/test.c b/src/test/test.c
index 040861560..4476319a4 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -63,6 +63,7 @@ double fabs(double x);
#include "crypto_curve25519.h"
#include "or_circuit_st.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
/** Run unit tests for the onion handshake code. */
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index 64448de51..0505285f3 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -21,6 +21,9 @@
#include "rendservice.h"
#include "routerset.h"
#include "circuitbuild.h"
+
+#include "rend_intro_point_st.h"
+
#include "test_helpers.h"
/* mock ID digest and longname for node that's in nodelist */
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index f1e94eb02..b4b76df88 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -12,6 +12,7 @@
#include "config.h"
#include "hs_common.h"
+#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
#include "rend_test_helpers.h"
1
0
commit e0830ff7bfd2c30c98b46f766d8ec59bd7ec4101
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 11:38:36 2018 -0400
Extract circuit_t into its own header
---
src/or/circuit_st.h | 170 +++++++++++++++++++++++++++++++++++++++++++++
src/or/include.am | 1 +
src/or/or.h | 158 +----------------------------------------
src/or/or_circuit_st.h | 2 +
src/or/origin_circuit_st.h | 2 +
5 files changed, 176 insertions(+), 157 deletions(-)
diff --git a/src/or/circuit_st.h b/src/or/circuit_st.h
new file mode 100644
index 000000000..2c4f72a72
--- /dev/null
+++ b/src/or/circuit_st.h
@@ -0,0 +1,170 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CIRCUIT_ST_H
+#define CIRCUIT_ST_H
+
+#include "or.h"
+
+/**
+ * A circuit is a path over the onion routing
+ * network. Applications can connect to one end of the circuit, and can
+ * create exit connections at the other end of the circuit. AP and exit
+ * connections have only one circuit associated with them (and thus these
+ * connection types are closed when the circuit is closed), whereas
+ * OR connections multiplex many circuits at once, and stay standing even
+ * when there are no circuits running over them.
+ *
+ * A circuit_t structure can fill one of two roles. First, a or_circuit_t
+ * links two connections together: either an edge connection and an OR
+ * connection, or two OR connections. (When joined to an OR connection, a
+ * circuit_t affects only cells sent to a particular circID on that
+ * connection. When joined to an edge connection, a circuit_t affects all
+ * data.)
+
+ * Second, an origin_circuit_t holds the cipher keys and state for sending data
+ * along a given circuit. At the OP, it has a sequence of ciphers, each
+ * of which is shared with a single OR along the circuit. Separate
+ * ciphers are used for data going "forward" (away from the OP) and
+ * "backward" (towards the OP). At the OR, a circuit has only two stream
+ * ciphers: one for data going forward, and one for data going backward.
+ */
+struct circuit_t {
+ uint32_t magic; /**< For memory and type debugging: must equal
+ * ORIGIN_CIRCUIT_MAGIC or OR_CIRCUIT_MAGIC. */
+
+ /** The channel that is next in this circuit. */
+ channel_t *n_chan;
+
+ /**
+ * The circuit_id used in the next (forward) hop of this circuit;
+ * this is unique to n_chan, but this ordered pair is globally
+ * unique:
+ *
+ * (n_chan->global_identifier, n_circ_id)
+ */
+ circid_t n_circ_id;
+
+ /**
+ * Circuit mux associated with n_chan to which this circuit is attached;
+ * NULL if we have no n_chan.
+ */
+ circuitmux_t *n_mux;
+
+ /** Queue of cells waiting to be transmitted on n_chan */
+ cell_queue_t n_chan_cells;
+
+ /**
+ * The hop to which we want to extend this circuit. Should be NULL if
+ * the circuit has attached to a channel.
+ */
+ extend_info_t *n_hop;
+
+ /** True iff we are waiting for n_chan_cells to become less full before
+ * allowing p_streams to add any more cells. (Origin circuit only.) */
+ unsigned int streams_blocked_on_n_chan : 1;
+ /** True iff we are waiting for p_chan_cells to become less full before
+ * allowing n_streams to add any more cells. (OR circuit only.) */
+ unsigned int streams_blocked_on_p_chan : 1;
+
+ /** True iff we have queued a delete backwards on this circuit, but not put
+ * it on the output buffer. */
+ unsigned int p_delete_pending : 1;
+ /** True iff we have queued a delete forwards on this circuit, but not put
+ * it on the output buffer. */
+ unsigned int n_delete_pending : 1;
+
+ /** True iff this circuit has received a DESTROY cell in either direction */
+ unsigned int received_destroy : 1;
+
+ uint8_t state; /**< Current status of this circuit. */
+ uint8_t purpose; /**< Why are we creating this circuit? */
+
+ /** How many relay data cells can we package (read from edge streams)
+ * on this circuit before we receive a circuit-level sendme cell asking
+ * for more? */
+ int package_window;
+ /** How many relay data cells will we deliver (write to edge streams)
+ * on this circuit? When deliver_window gets low, we send some
+ * circuit-level sendme cells to indicate that we're willing to accept
+ * more. */
+ int deliver_window;
+
+ /** Temporary field used during circuits_handle_oom. */
+ uint32_t age_tmp;
+
+ /** For storage while n_chan is pending (state CIRCUIT_STATE_CHAN_WAIT). */
+ struct create_cell_t *n_chan_create_cell;
+
+ /** When did circuit construction actually begin (ie send the
+ * CREATE cell or begin cannibalization).
+ *
+ * Note: This timer will get reset if we decide to cannibalize
+ * a circuit. It may also get reset during certain phases of hidden
+ * service circuit use.
+ *
+ * We keep this timestamp with a higher resolution than most so that the
+ * circuit-build-time tracking code can get millisecond resolution.
+ */
+ struct timeval timestamp_began;
+
+ /** This timestamp marks when the init_circuit_base constructor ran. */
+ struct timeval timestamp_created;
+
+ /** When the circuit was first used, or 0 if the circuit is clean.
+ *
+ * XXXX Note that some code will artificially adjust this value backward
+ * in time in order to indicate that a circuit shouldn't be used for new
+ * streams, but that it can stay alive as long as it has streams on it.
+ * That's a kludge we should fix.
+ *
+ * XXX The CBT code uses this field to record when HS-related
+ * circuits entered certain states. This usage probably won't
+ * interfere with this field's primary purpose, but we should
+ * document it more thoroughly to make sure of that.
+ *
+ * XXX The SocksPort option KeepaliveIsolateSOCKSAuth will artificially
+ * adjust this value forward each time a suitable stream is attached to an
+ * already constructed circuit, potentially keeping the circuit alive
+ * indefinitely.
+ */
+ time_t timestamp_dirty;
+
+ uint16_t marked_for_close; /**< Should we close this circuit at the end of
+ * the main loop? (If true, holds the line number
+ * where this circuit was marked.) */
+ const char *marked_for_close_file; /**< For debugging: in which file was this
+ * circuit marked for close? */
+ /** For what reason (See END_CIRC_REASON...) is this circuit being closed?
+ * This field is set in circuit_mark_for_close and used later in
+ * circuit_about_to_free. */
+ int marked_for_close_reason;
+ /** As marked_for_close_reason, but reflects the underlying reason for
+ * closing this circuit.
+ */
+ int marked_for_close_orig_reason;
+
+ /** Unique ID for measuring tunneled network status requests. */
+ uint64_t dirreq_id;
+
+ /** Index in smartlist of all circuits (global_circuitlist). */
+ int global_circuitlist_idx;
+
+ /** Various statistics about cells being added to or removed from this
+ * circuit's queues; used only if CELL_STATS events are enabled and
+ * cleared after being sent to control port. */
+ smartlist_t *testing_cell_stats;
+
+ /** If set, points to an HS token that this circuit might be carrying.
+ * Used by the HS circuitmap. */
+ hs_token_t *hs_token;
+ /** Hashtable node: used to look up the circuit by its HS token using the HS
+ circuitmap. */
+ HT_ENTRY(circuit_t) hs_circuitmap_node;
+};
+
+#endif
+
diff --git a/src/or/include.am b/src/or/include.am
index eb8b52e93..83dee5a77 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -193,6 +193,7 @@ ORHEADERS = \
src/or/circuitmux_ewma.h \
src/or/circuitstats.h \
src/or/circuituse.h \
+ src/or/circuit_st.h \
src/or/command.h \
src/or/config.h \
src/or/confparse.h \
diff --git a/src/or/or.h b/src/or/or.h
index 61987d825..b9608d152 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2404,163 +2404,7 @@ typedef struct testing_cell_stats_entry_t {
unsigned int exitward:1; /**< 0 for app-ward, 1 for exit-ward. */
} testing_cell_stats_entry_t;
-/**
- * A circuit is a path over the onion routing
- * network. Applications can connect to one end of the circuit, and can
- * create exit connections at the other end of the circuit. AP and exit
- * connections have only one circuit associated with them (and thus these
- * connection types are closed when the circuit is closed), whereas
- * OR connections multiplex many circuits at once, and stay standing even
- * when there are no circuits running over them.
- *
- * A circuit_t structure can fill one of two roles. First, a or_circuit_t
- * links two connections together: either an edge connection and an OR
- * connection, or two OR connections. (When joined to an OR connection, a
- * circuit_t affects only cells sent to a particular circID on that
- * connection. When joined to an edge connection, a circuit_t affects all
- * data.)
-
- * Second, an origin_circuit_t holds the cipher keys and state for sending data
- * along a given circuit. At the OP, it has a sequence of ciphers, each
- * of which is shared with a single OR along the circuit. Separate
- * ciphers are used for data going "forward" (away from the OP) and
- * "backward" (towards the OP). At the OR, a circuit has only two stream
- * ciphers: one for data going forward, and one for data going backward.
- */
-typedef struct circuit_t {
- uint32_t magic; /**< For memory and type debugging: must equal
- * ORIGIN_CIRCUIT_MAGIC or OR_CIRCUIT_MAGIC. */
-
- /** The channel that is next in this circuit. */
- channel_t *n_chan;
-
- /**
- * The circuit_id used in the next (forward) hop of this circuit;
- * this is unique to n_chan, but this ordered pair is globally
- * unique:
- *
- * (n_chan->global_identifier, n_circ_id)
- */
- circid_t n_circ_id;
-
- /**
- * Circuit mux associated with n_chan to which this circuit is attached;
- * NULL if we have no n_chan.
- */
- circuitmux_t *n_mux;
-
- /** Queue of cells waiting to be transmitted on n_chan */
- cell_queue_t n_chan_cells;
-
- /**
- * The hop to which we want to extend this circuit. Should be NULL if
- * the circuit has attached to a channel.
- */
- extend_info_t *n_hop;
-
- /** True iff we are waiting for n_chan_cells to become less full before
- * allowing p_streams to add any more cells. (Origin circuit only.) */
- unsigned int streams_blocked_on_n_chan : 1;
- /** True iff we are waiting for p_chan_cells to become less full before
- * allowing n_streams to add any more cells. (OR circuit only.) */
- unsigned int streams_blocked_on_p_chan : 1;
-
- /** True iff we have queued a delete backwards on this circuit, but not put
- * it on the output buffer. */
- unsigned int p_delete_pending : 1;
- /** True iff we have queued a delete forwards on this circuit, but not put
- * it on the output buffer. */
- unsigned int n_delete_pending : 1;
-
- /** True iff this circuit has received a DESTROY cell in either direction */
- unsigned int received_destroy : 1;
-
- uint8_t state; /**< Current status of this circuit. */
- uint8_t purpose; /**< Why are we creating this circuit? */
-
- /** How many relay data cells can we package (read from edge streams)
- * on this circuit before we receive a circuit-level sendme cell asking
- * for more? */
- int package_window;
- /** How many relay data cells will we deliver (write to edge streams)
- * on this circuit? When deliver_window gets low, we send some
- * circuit-level sendme cells to indicate that we're willing to accept
- * more. */
- int deliver_window;
-
- /** Temporary field used during circuits_handle_oom. */
- uint32_t age_tmp;
-
- /** For storage while n_chan is pending (state CIRCUIT_STATE_CHAN_WAIT). */
- struct create_cell_t *n_chan_create_cell;
-
- /** When did circuit construction actually begin (ie send the
- * CREATE cell or begin cannibalization).
- *
- * Note: This timer will get reset if we decide to cannibalize
- * a circuit. It may also get reset during certain phases of hidden
- * service circuit use.
- *
- * We keep this timestamp with a higher resolution than most so that the
- * circuit-build-time tracking code can get millisecond resolution.
- */
- struct timeval timestamp_began;
-
- /** This timestamp marks when the init_circuit_base constructor ran. */
- struct timeval timestamp_created;
-
- /** When the circuit was first used, or 0 if the circuit is clean.
- *
- * XXXX Note that some code will artificially adjust this value backward
- * in time in order to indicate that a circuit shouldn't be used for new
- * streams, but that it can stay alive as long as it has streams on it.
- * That's a kludge we should fix.
- *
- * XXX The CBT code uses this field to record when HS-related
- * circuits entered certain states. This usage probably won't
- * interfere with this field's primary purpose, but we should
- * document it more thoroughly to make sure of that.
- *
- * XXX The SocksPort option KeepaliveIsolateSOCKSAuth will artificially
- * adjust this value forward each time a suitable stream is attached to an
- * already constructed circuit, potentially keeping the circuit alive
- * indefinitely.
- */
- time_t timestamp_dirty;
-
- uint16_t marked_for_close; /**< Should we close this circuit at the end of
- * the main loop? (If true, holds the line number
- * where this circuit was marked.) */
- const char *marked_for_close_file; /**< For debugging: in which file was this
- * circuit marked for close? */
- /** For what reason (See END_CIRC_REASON...) is this circuit being closed?
- * This field is set in circuit_mark_for_close and used later in
- * circuit_about_to_free. */
- int marked_for_close_reason;
- /** As marked_for_close_reason, but reflects the underlying reason for
- * closing this circuit.
- */
- int marked_for_close_orig_reason;
-
- /** Unique ID for measuring tunneled network status requests. */
- uint64_t dirreq_id;
-
- /** Index in smartlist of all circuits (global_circuitlist). */
- int global_circuitlist_idx;
-
- /** Various statistics about cells being added to or removed from this
- * circuit's queues; used only if CELL_STATS events are enabled and
- * cleared after being sent to control port. */
- smartlist_t *testing_cell_stats;
-
- /** If set, points to an HS token that this circuit might be carrying.
- * Used by the HS circuitmap. */
- hs_token_t *hs_token;
- /** Hashtable node: used to look up the circuit by its HS token using the HS
- circuitmap. */
- HT_ENTRY(circuit_t) hs_circuitmap_node;
-} circuit_t;
-
+typedef struct circuit_t circuit_t;
typedef struct origin_circuit_t origin_circuit_t;
typedef struct or_circuit_t or_circuit_t;
diff --git a/src/or/or_circuit_st.h b/src/or/or_circuit_st.h
index 19c39f8e6..f76737fbd 100644
--- a/src/or/or_circuit_st.h
+++ b/src/or/or_circuit_st.h
@@ -9,6 +9,8 @@
#include "or.h"
+#include "circuit_st.h"
+
struct onion_queue_t;
/** An or_circuit_t holds information needed to implement a circuit at an
diff --git a/src/or/origin_circuit_st.h b/src/or/origin_circuit_st.h
index e995776c2..1ea9926db 100644
--- a/src/or/origin_circuit_st.h
+++ b/src/or/origin_circuit_st.h
@@ -9,6 +9,8 @@
#include "or.h"
+#include "circuit_st.h"
+
struct onion_queue_t;
/** An origin_circuit_t holds data necessary to build and use a circuit.
1
0

[tor/master] Split rend_authorized_client_t and encoded_.._t into their own headers
by nickm@torproject.org 18 Jun '18
by nickm@torproject.org 18 Jun '18
18 Jun '18
commit 5cdc2343302f8fec9d71a6f1e7ec28befb7379cf
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Jun 15 12:36:59 2018 -0400
Split rend_authorized_client_t and encoded_.._t into their own headers
---
src/or/control.c | 2 ++
src/or/include.am | 2 ++
src/or/or.h | 15 +++------------
src/or/rend_authorized_client_st.h | 18 ++++++++++++++++++
src/or/rend_encoded_v2_service_descriptor_st.h | 17 +++++++++++++++++
src/or/rendcommon.c | 1 +
src/or/rendservice.c | 2 ++
src/or/routerparse.c | 1 +
src/test/test.c | 1 +
src/test/test_dir_handle_get.c | 1 +
src/test/test_hs.c | 1 +
src/test/test_rendcache.c | 1 +
12 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/src/or/control.c b/src/or/control.c
index 401135ca8..966ddfa8c 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -87,6 +87,8 @@
#include "or_connection_st.h"
#include "or_circuit_st.h"
#include "origin_circuit_st.h"
+#include "rend_authorized_client_st.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_service_descriptor_st.h"
#ifndef _WIN32
diff --git a/src/or/include.am b/src/or/include.am
index ede01c79e..353d52ea2 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -279,6 +279,8 @@ ORHEADERS = \
src/or/rendcommon.h \
src/or/rendmid.h \
src/or/rendservice.h \
+ src/or/rend_authorized_client_st.h \
+ src/or/rend_encoded_v2_service_descriptor_st.h \
src/or/rend_intro_point_st.h \
src/or/rend_service_descriptor_st.h \
src/or/rephist.h \
diff --git a/src/or/or.h b/src/or/or.h
index 41953806a..d390c47bf 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -4038,18 +4038,9 @@ typedef enum {
/********************************* rendcommon.c ***************************/
-/** Hidden-service side configuration of client authorization. */
-typedef struct rend_authorized_client_t {
- char *client_name;
- uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
- crypto_pk_t *client_key;
-} rend_authorized_client_t;
-
-/** ASCII-encoded v2 hidden service descriptor. */
-typedef struct rend_encoded_v2_service_descriptor_t {
- char desc_id[DIGEST_LEN]; /**< Descriptor ID. */
- char *desc_str; /**< Descriptor string. */
-} rend_encoded_v2_service_descriptor_t;
+typedef struct rend_authorized_client_t rend_authorized_client_t;
+typedef struct rend_encoded_v2_service_descriptor_t
+ rend_encoded_v2_service_descriptor_t;
/** The maximum number of non-circuit-build-timeout failures a hidden
* service client will tolerate while trying to build a circuit to an
diff --git a/src/or/rend_authorized_client_st.h b/src/or/rend_authorized_client_st.h
new file mode 100644
index 000000000..e06620fb8
--- /dev/null
+++ b/src/or/rend_authorized_client_st.h
@@ -0,0 +1,18 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef REND_AUTHORIZED_CLIENT_ST_H
+#define REND_AUTHORIZED_CLIENT_ST_H
+
+/** Hidden-service side configuration of client authorization. */
+struct rend_authorized_client_t {
+ char *client_name;
+ uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
+ crypto_pk_t *client_key;
+};
+
+#endif
+
diff --git a/src/or/rend_encoded_v2_service_descriptor_st.h b/src/or/rend_encoded_v2_service_descriptor_st.h
new file mode 100644
index 000000000..05176eb01
--- /dev/null
+++ b/src/or/rend_encoded_v2_service_descriptor_st.h
@@ -0,0 +1,17 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef REND_ENCODED_V2_SERVICE_DESCRIPTOR_ST_H
+#define REND_ENCODED_V2_SERVICE_DESCRIPTOR_ST_H
+
+/** ASCII-encoded v2 hidden service descriptor. */
+struct rend_encoded_v2_service_descriptor_t {
+ char desc_id[DIGEST_LEN]; /**< Descriptor ID. */
+ char *desc_str; /**< Descriptor string. */
+};
+
+#endif
+
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 2494311cb..0ab42fb42 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -34,6 +34,7 @@
#include "cpath_build_state_st.h"
#include "crypt_path_st.h"
#include "origin_circuit_st.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index d82ea4789..4a8b7a0e1 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -41,6 +41,8 @@
#include "crypt_path_reference_st.h"
#include "edge_connection_st.h"
#include "origin_circuit_st.h"
+#include "rend_authorized_client_st.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 20a6f85a4..e75dc2ee9 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -81,6 +81,7 @@
#include "dirauth/dirvote.h"
+#include "rend_authorized_client_st.h"
#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
#include "tor_version_st.h"
diff --git a/src/test/test.c b/src/test/test.c
index 4476319a4..871498aa0 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -63,6 +63,7 @@ double fabs(double x);
#include "crypto_curve25519.h"
#include "or_circuit_st.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index 188735a54..ff9740b91 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -36,6 +36,7 @@
#include "dir_connection_st.h"
#include "dir_server_st.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#ifdef _WIN32
/* For mkdir() */
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index 0505285f3..9343d131f 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -22,6 +22,7 @@
#include "routerset.h"
#include "circuitbuild.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h"
#include "test_helpers.h"
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index b4b76df88..e5d531617 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -12,6 +12,7 @@
#include "config.h"
#include "hs_common.h"
+#include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h"
1
0