[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Split dir_connection_t into its own header



commit 1416f54d1eb2651e6b82ccbe35585ce71378de8a
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Jun 15 10:31:21 2018 -0400

    Split dir_connection_t into its own header
---
 src/or/circuitlist.c           |  2 ++
 src/or/circuituse.c            |  2 ++
 src/or/connection.c            |  8 ++++++
 src/or/connection.h            | 11 ++------
 src/or/connection_edge.c       |  1 +
 src/or/dir_connection_st.h     | 64 ++++++++++++++++++++++++++++++++++++++++++
 src/or/directory.c             | 10 +++++++
 src/or/directory.h             |  1 +
 src/or/dirserv.c               |  2 ++
 src/or/hs_client.c             |  1 +
 src/or/hs_service.c            |  1 +
 src/or/include.am              |  1 +
 src/or/networkstatus.c         |  1 +
 src/or/or.h                    | 62 +---------------------------------------
 src/or/relay.c                 |  2 ++
 src/or/rendclient.c            |  1 +
 src/or/router.c                |  1 +
 src/or/routerlist.c            |  1 +
 src/test/fuzz/fuzz_http.c      |  2 ++
 src/test/test_connection.c     |  1 +
 src/test/test_dir_handle_get.c |  1 +
 src/test/test_entrynodes.c     |  2 ++
 src/test/test_hs_cache.c       |  2 ++
 src/test/test_hs_client.c      |  1 +
 src/test/test_oos.c            |  2 ++
 src/test/test_routerlist.c     |  3 ++
 26 files changed, 116 insertions(+), 70 deletions(-)

diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index e0ee28428..1a3f3a229 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -67,6 +67,7 @@
 #include "control.h"
 #include "crypto_rand.h"
 #include "crypto_util.h"
+#include "directory.h"
 #include "entrynodes.h"
 #include "main.h"
 #include "hs_circuit.h"
@@ -91,6 +92,7 @@
 
 #include "ht.h"
 
+#include "dir_connection_st.h"
 #include "edge_connection_st.h"
 
 /********* START VARIABLES **********/
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 5494bf94e..45eeff433 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -40,6 +40,7 @@
 #include "connection.h"
 #include "connection_edge.h"
 #include "control.h"
+#include "directory.h"
 #include "entrynodes.h"
 #include "hs_common.h"
 #include "hs_client.h"
@@ -56,6 +57,7 @@
 #include "router.h"
 #include "routerlist.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 static void circuit_expire_old_circuits_clientside(void);
diff --git a/src/or/connection.c b/src/or/connection.c
index 0042d3e0d..8c7341992 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -113,6 +113,7 @@
 #include <sys/un.h>
 #endif
 
+#include "dir_connection_st.h"
 #include "control_connection_st.h"
 #include "entry_connection_st.h"
 #include "port_cfg_st.h"
@@ -4112,6 +4113,13 @@ connection_write_to_buf_impl_,(const char *string, size_t len,
   connection_write_to_buf_commit(conn, written);
 }
 
+void
+connection_buf_add_compress(const char *string, size_t len,
+                            dir_connection_t *conn, int done)
+{
+  connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
+}
+
 /**
  * Add all bytes from <b>buf</b> to <b>conn</b>'s outbuf, draining them
  * from <b>buf</b>. (If the connection is marked and will soon be closed,
diff --git a/src/or/connection.h b/src/or/connection.h
index ad3129c9d..59720ce3b 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -150,20 +150,13 @@ MOCK_DECL(void, connection_write_to_buf_impl_,
 /* DOCDOC connection_write_to_buf */
 static void connection_buf_add(const char *string, size_t len,
                                     connection_t *conn);
-/* DOCDOC connection_write_to_buf_compress */
-static void connection_buf_add_compress(const char *string, size_t len,
-                                             dir_connection_t *conn, int done);
 static inline void
 connection_buf_add(const char *string, size_t len, connection_t *conn)
 {
   connection_write_to_buf_impl_(string, len, conn, 0);
 }
-static inline void
-connection_buf_add_compress(const char *string, size_t len,
-                                 dir_connection_t *conn, int done)
-{
-  connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
-}
+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 */
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 4bd50398b..1ba61609b 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -97,6 +97,7 @@
 #include "routerset.h"
 #include "circuitbuild.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 #ifdef HAVE_LINUX_TYPES_H
diff --git a/src/or/dir_connection_st.h b/src/or/dir_connection_st.h
new file mode 100644
index 000000000..df1e9b551
--- /dev/null
+++ b/src/or/dir_connection_st.h
@@ -0,0 +1,64 @@
+/* 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 DIR_CONNECTION_ST_H
+#define DIR_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 {
+  connection_t base_;
+
+ /** Which 'resource' did we ask the directory for? This is typically the part
+  * of the URL string that defines, relative to the directory conn purpose,
+  * what thing we want.  For example, in router descriptor downloads by
+  * descriptor digest, it contains "d/", then one or more +-separated
+  * fingerprints.
+  **/
+  char *requested_resource;
+  unsigned int dirconn_direct:1; /**< Is this dirconn direct, or via Tor? */
+
+  /** If we're fetching descriptors, what router purpose shall we assign
+   * to them? */
+  uint8_t router_purpose;
+
+  /** List of spooled_resource_t for objects that we're spooling. We use
+   * it from back to front. */
+  smartlist_t *spool;
+  /** The compression object doing on-the-fly compression for spooled data. */
+  tor_compress_state_t *compress_state;
+
+  /** What rendezvous service are we querying for? */
+  rend_data_t *rend_data;
+
+  /* Hidden service connection identifier for dir connections: Used by HS
+     client-side code to fetch HS descriptors, and by the service-side code to
+     upload descriptors. */
+  struct hs_ident_dir_conn_t *hs_ident;
+
+  /** If this is a one-hop connection, tracks the state of the directory guard
+   * for this connection (if any). */
+  struct circuit_guard_state_t *guard_state;
+
+  char identity_digest[DIGEST_LEN]; /**< Hash of the public RSA key for
+                                     * the directory server's signing key. */
+
+  /** Unique ID for directory requests; this used to be in connection_t, but
+   * that's going away and being used on channels instead.  The dirserver still
+   * needs this for the incoming side, so it's moved here. */
+  uint64_t dirreq_id;
+
+#ifdef MEASUREMENTS_21206
+  /** Number of RELAY_DATA cells received. */
+  uint32_t data_cells_received;
+
+  /** Number of RELAY_DATA cells sent. */
+  uint32_t data_cells_sent;
+#endif /* defined(MEASUREMENTS_21206) */
+};
+
+#endif
+
diff --git a/src/or/directory.c b/src/or/directory.c
index 7321a97fc..65aaaa38a 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -53,6 +53,7 @@
 #include "dirauth/mode.h"
 #include "dirauth/shared_random.h"
 
+#include "dir_connection_st.h"
 #include "dir_server_st.h"
 #include "entry_connection_st.h"
 
@@ -154,6 +155,15 @@ static void connection_dir_close_consensus_fetches(
 
 /********* END VARIABLES ************/
 
+/** Convert a connection_t* to a dir_connection_t*; assert if the cast is
+ * invalid. */
+dir_connection_t *
+TO_DIR_CONN(connection_t *c)
+{
+  tor_assert(c->magic == DIR_CONNECTION_MAGIC);
+  return DOWNCAST(dir_connection_t, c);
+}
+
 /** Return false if the directory purpose <b>dir_purpose</b>
  * does not require an anonymous (three-hop) connection.
  *
diff --git a/src/or/directory.h b/src/or/directory.h
index 5f5ff7eca..e94c02b6c 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -14,6 +14,7 @@
 
 #include "hs_ident.h"
 
+dir_connection_t *TO_DIR_CONN(connection_t *c);
 int directories_have_accepted_server_descriptor(void);
 void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
                                   dirinfo_type_t type, const char *payload,
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index c01234e0b..f2597aeae 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -36,6 +36,8 @@
 
 #include "dirauth/dirvote.h"
 
+#include "dir_connection_st.h"
+
 /**
  * \file dirserv.c
  * \brief Directory server core implementation. Manages directory
diff --git a/src/or/hs_client.c b/src/or/hs_client.c
index 8c04026a7..ff84296d0 100644
--- a/src/or/hs_client.c
+++ b/src/or/hs_client.c
@@ -35,6 +35,7 @@
 #include "router.h"
 #include "routerset.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 /* Return a human-readable string for the client fetch status code. */
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 44ee7bb66..9f12484eb 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -39,6 +39,7 @@
 #include "hs_service.h"
 #include "hs_stats.h"
 
+#include "dir_connection_st.h"
 #include "edge_connection_st.h"
 
 /* Trunnel */
diff --git a/src/or/include.am b/src/or/include.am
index cff38d0b6..5249f683d 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -207,6 +207,7 @@ ORHEADERS = \
 	src/or/cpuworker.h				\
 	src/or/directory.h				\
 	src/or/dirserv.h				\
+	src/or/dir_connection_st.h			\
 	src/or/dir_server_st.h				\
 	src/or/dns.h					\
 	src/or/dns_structs.h				\
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 3ed6e3d6c..3694da49d 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -74,6 +74,7 @@
 #include "dirauth/mode.h"
 #include "dirauth/shared_random.h"
 
+#include "dir_connection_st.h"
 #include "dir_server_st.h"
 
 /** Most recently received and validated v3 "ns"-flavored consensus network
diff --git a/src/or/or.h b/src/or/or.h
index 138c5a18d..d9e074d4c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1640,62 +1640,10 @@ typedef struct or_connection_t {
 } or_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;
 typedef struct entry_connection_t entry_connection_t;
 
-/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
- * connection to retrieve or serve directory material. */
-typedef struct dir_connection_t {
-  connection_t base_;
-
- /** Which 'resource' did we ask the directory for? This is typically the part
-  * of the URL string that defines, relative to the directory conn purpose,
-  * what thing we want.  For example, in router descriptor downloads by
-  * descriptor digest, it contains "d/", then one or more +-separated
-  * fingerprints.
-  **/
-  char *requested_resource;
-  unsigned int dirconn_direct:1; /**< Is this dirconn direct, or via Tor? */
-
-  /** If we're fetching descriptors, what router purpose shall we assign
-   * to them? */
-  uint8_t router_purpose;
-
-  /** List of spooled_resource_t for objects that we're spooling. We use
-   * it from back to front. */
-  smartlist_t *spool;
-  /** The compression object doing on-the-fly compression for spooled data. */
-  tor_compress_state_t *compress_state;
-
-  /** What rendezvous service are we querying for? */
-  rend_data_t *rend_data;
-
-  /* Hidden service connection identifier for dir connections: Used by HS
-     client-side code to fetch HS descriptors, and by the service-side code to
-     upload descriptors. */
-  struct hs_ident_dir_conn_t *hs_ident;
-
-  /** If this is a one-hop connection, tracks the state of the directory guard
-   * for this connection (if any). */
-  struct circuit_guard_state_t *guard_state;
-
-  char identity_digest[DIGEST_LEN]; /**< Hash of the public RSA key for
-                                     * the directory server's signing key. */
-
-  /** Unique ID for directory requests; this used to be in connection_t, but
-   * that's going away and being used on channels instead.  The dirserver still
-   * needs this for the incoming side, so it's moved here. */
-  uint64_t dirreq_id;
-
-#ifdef MEASUREMENTS_21206
-  /** Number of RELAY_DATA cells received. */
-  uint32_t data_cells_received;
-
-  /** Number of RELAY_DATA cells sent. */
-  uint32_t data_cells_sent;
-#endif /* defined(MEASUREMENTS_21206) */
-} dir_connection_t;
-
 /** Cast a connection_t subtype pointer to a connection_t **/
 #define TO_CONN(c) (&(((c)->base_)))
 
@@ -1705,9 +1653,6 @@ typedef struct dir_connection_t {
 /** Convert a connection_t* to an or_connection_t*; assert if the cast is
  * invalid. */
 static or_connection_t *TO_OR_CONN(connection_t *);
-/** Convert a connection_t* to a dir_connection_t*; assert if the cast is
- * invalid. */
-static dir_connection_t *TO_DIR_CONN(connection_t *);
 /** Convert a connection_t* to an listener_connection_t*; assert if the cast is
  * invalid. */
 static listener_connection_t *TO_LISTENER_CONN(connection_t *);
@@ -1717,11 +1662,6 @@ static inline or_connection_t *TO_OR_CONN(connection_t *c)
   tor_assert(c->magic == OR_CONNECTION_MAGIC);
   return DOWNCAST(or_connection_t, c);
 }
-static inline dir_connection_t *TO_DIR_CONN(connection_t *c)
-{
-  tor_assert(c->magic == DIR_CONNECTION_MAGIC);
-  return DOWNCAST(dir_connection_t, c);
-}
 static inline listener_connection_t *TO_LISTENER_CONN(connection_t *c)
 {
   tor_assert(c->magic == LISTENER_CONNECTION_MAGIC);
diff --git a/src/or/relay.c b/src/or/relay.c
index 757613e9d..dca31498f 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -63,6 +63,7 @@
 #include "control.h"
 #include "crypto_rand.h"
 #include "crypto_util.h"
+#include "directory.h"
 #include "geoip.h"
 #include "hs_cache.h"
 #include "main.h"
@@ -81,6 +82,7 @@
 #include "scheduler.h"
 #include "rephist.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 static edge_connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell,
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index c153862e6..c46b8c565 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -33,6 +33,7 @@
 #include "routerlist.h"
 #include "routerset.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 static extend_info_t *rend_client_get_random_intro_impl(
diff --git a/src/or/router.c b/src/or/router.c
index c361e21a5..f1fff6be2 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -39,6 +39,7 @@
 
 #include "dirauth/mode.h"
 
+#include "dir_connection_st.h"
 #include "dir_server_st.h"
 #include "port_cfg_st.h"
 
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 015b1012a..970eac8d3 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -125,6 +125,7 @@
 #include "dirauth/dirvote.h"
 #include "dirauth/mode.h"
 
+#include "dir_connection_st.h"
 #include "dir_server_st.h"
 
 // #define DEBUG_ROUTERLIST
diff --git a/src/test/fuzz/fuzz_http.c b/src/test/fuzz/fuzz_http.c
index 2ffeb6024..e93204ea3 100644
--- a/src/test/fuzz/fuzz_http.c
+++ b/src/test/fuzz/fuzz_http.c
@@ -14,6 +14,8 @@
 #include "directory.h"
 #include "torlog.h"
 
+#include "dir_connection_st.h"
+
 #include "fuzzing.h"
 
 static void
diff --git a/src/test/test_connection.c b/src/test/test_connection.c
index 05c4bb7f1..79c5e2dd8 100644
--- a/src/test/test_connection.c
+++ b/src/test/test_connection.c
@@ -24,6 +24,7 @@
 #include "test_connection.h"
 #include "test_helpers.h"
 
+#include "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 static void * test_conn_get_basic_setup(const struct testcase_t *tc);
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index 4338bba65..188735a54 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -34,6 +34,7 @@
 #include "log_test_helpers.h"
 #include "voting_schedule.h"
 
+#include "dir_connection_st.h"
 #include "dir_server_st.h"
 
 #ifdef _WIN32
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index cfcb88a66..d4939355d 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -30,6 +30,8 @@
 #include "statefile.h"
 #include "util.h"
 
+#include "dir_connection_st.h"
+
 #include "test_helpers.h"
 #include "log_test_helpers.h"
 
diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c
index 458ce1a92..b2f892c7f 100644
--- a/src/test/test_hs_cache.c
+++ b/src/test/test_hs_cache.c
@@ -18,6 +18,8 @@
 #include "connection.h"
 #include "proto_http.h"
 
+#include "dir_connection_st.h"
+
 #include "hs_test_helpers.h"
 #include "test_helpers.h"
 #include "test.h"
diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c
index 0828364e8..0420f70f8 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 "dir_connection_st.h"
 #include "entry_connection_st.h"
 
 static int
diff --git a/src/test/test_oos.c b/src/test/test_oos.c
index e72fcf5de..ddad5a08d 100644
--- a/src/test/test_oos.c
+++ b/src/test/test_oos.c
@@ -12,6 +12,8 @@
 #include "main.h"
 #include "test.h"
 
+#include "dir_connection_st.h"
+
 static or_options_t mock_options;
 
 static void
diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c
index 701227c1c..d66f8933d 100644
--- a/src/test/test_routerlist.c
+++ b/src/test/test_routerlist.c
@@ -33,6 +33,9 @@
 #include "routerparse.h"
 #include "dirauth/shared_random.h"
 #include "statefile.h"
+
+#include "dir_connection_st.h"
+
 #include "test.h"
 #include "test_dir_common.h"
 #include "log_test_helpers.h"



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits