[tor-commits] [tor/master] Extract crypt_path_t and relay_crypto_t into their own headers

nickm at torproject.org nickm at torproject.org
Mon Jun 18 18:18:42 UTC 2018


commit b3f2c682b721eac104455b09bd2f0d481f17d750
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Jun 15 11:52:32 2018 -0400

    Extract crypt_path_t and relay_crypto_t into their own headers
---
 src/or/circpathbias.c        |  1 +
 src/or/circuitstats.c        |  1 +
 src/or/crypt_path_st.h       | 56 +++++++++++++++++++++++++++++++++++++++++
 src/or/hs_circuit.c          |  1 +
 src/or/include.am            |  2 ++
 src/or/or.h                  | 60 ++------------------------------------------
 src/or/or_circuit_st.h       |  1 +
 src/or/relay_crypto_st.h     | 27 ++++++++++++++++++++
 src/or/rendclient.c          |  1 +
 src/or/rendcommon.c          |  1 +
 src/or/rendservice.c         |  1 +
 src/or/router.c              |  1 +
 src/test/test_circuitstats.c |  1 +
 src/test/test_entrynodes.c   |  3 ++-
 src/test/test_hs_client.c    |  1 +
 src/test/test_hs_service.c   |  1 +
 src/test/test_relaycell.c    |  1 +
 17 files changed, 101 insertions(+), 59 deletions(-)

diff --git a/src/or/circpathbias.c b/src/or/circpathbias.c
index f139c6d7e..d1bdaedc3 100644
--- a/src/or/circpathbias.c
+++ b/src/or/circpathbias.c
@@ -35,6 +35,7 @@
 #include "networkstatus.h"
 #include "relay.h"
 
+#include "crypt_path_st.h"
 #include "origin_circuit_st.h"
 
 static void pathbias_count_successful_close(origin_circuit_t *circ);
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c
index bff553a02..f1660090f 100644
--- a/src/or/circuitstats.c
+++ b/src/or/circuitstats.c
@@ -41,6 +41,7 @@
 #include "circuitlist.h"
 #include "circuituse.h"
 
+#include "crypt_path_st.h"
 #include "origin_circuit_st.h"
 
 #undef log
diff --git a/src/or/crypt_path_st.h b/src/or/crypt_path_st.h
new file mode 100644
index 000000000..ebad87217
--- /dev/null
+++ b/src/or/crypt_path_st.h
@@ -0,0 +1,56 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CRYPT_PATH_ST_H
+#define CRYPT_PATH_ST_H
+
+#include "relay_crypto_st.h"
+
+/** Holds accounting information for a single step in the layered encryption
+ * performed by a circuit.  Used only at the client edge of a circuit. */
+struct crypt_path_t {
+  uint32_t magic;
+
+  /** Cryptographic state used for encrypting and authenticating relay
+   * cells to and from this hop. */
+  relay_crypto_t crypto;
+
+  /** Current state of the handshake as performed with the OR at this
+   * step. */
+  onion_handshake_state_t handshake_state;
+  /** Diffie-hellman handshake state for performing an introduction
+   * operations */
+  crypto_dh_t *rend_dh_handshake_state;
+
+  /** Negotiated key material shared with the OR at this step. */
+  char rend_circ_nonce[DIGEST_LEN];/* KH in tor-spec.txt */
+
+  /** Information to extend to the OR at this step. */
+  extend_info_t *extend_info;
+
+  /** Is the circuit built to this step?  Must be one of:
+   *    - CPATH_STATE_CLOSED (The circuit has not been extended to this step)
+   *    - CPATH_STATE_AWAITING_KEYS (We have sent an EXTEND/CREATE to this step
+   *      and not received an EXTENDED/CREATED)
+   *    - CPATH_STATE_OPEN (The circuit has been extended to this step) */
+  uint8_t state;
+#define CPATH_STATE_CLOSED 0
+#define CPATH_STATE_AWAITING_KEYS 1
+#define CPATH_STATE_OPEN 2
+  struct crypt_path_t *next; /**< Link to next crypt_path_t in the circuit.
+                              * (The list is circular, so the last node
+                              * links to the first.) */
+  struct crypt_path_t *prev; /**< Link to previous crypt_path_t in the
+                              * circuit. */
+
+  int package_window; /**< How many cells are we allowed to originate ending
+                       * at this step? */
+  int deliver_window; /**< How many cells are we willing to deliver originating
+                       * at this step? */
+};
+
+#endif
+
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index 189ebdc1b..56ae4a152 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 "crypt_path_st.h"
 #include "origin_circuit_st.h"
 
 /* A circuit is about to become an e2e rendezvous circuit. Check
diff --git a/src/or/include.am b/src/or/include.am
index 83dee5a77..0a58796e0 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/crypt_path_st.h				\
 	src/or/cpuworker.h				\
 	src/or/directory.h				\
 	src/or/dirserv.h				\
@@ -270,6 +271,7 @@ ORHEADERS = \
 	src/or/reasons.h				\
 	src/or/relay.h					\
 	src/or/relay_crypto.h				\
+	src/or/relay_crypto_st.h			\
 	src/or/rendcache.h				\
 	src/or/rendclient.h				\
 	src/or/rendcommon.h				\
diff --git a/src/or/or.h b/src/or/or.h
index b9608d152..df232604e 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2278,64 +2278,8 @@ typedef struct {
   } u;
 } onion_handshake_state_t;
 
-typedef struct relay_crypto_t {
-  /* crypto environments */
-  /** Encryption key and counter for cells heading towards the OR at this
-   * step. */
-  crypto_cipher_t *f_crypto;
-  /** Encryption key and counter for cells heading back from the OR at this
-   * step. */
-  crypto_cipher_t *b_crypto;
-
-  /** Digest state for cells heading towards the OR at this step. */
-  crypto_digest_t *f_digest; /* for integrity checking */
-  /** Digest state for cells heading away from the OR at this step. */
-  crypto_digest_t *b_digest;
-
-} relay_crypto_t;
-
-/** Holds accounting information for a single step in the layered encryption
- * performed by a circuit.  Used only at the client edge of a circuit. */
-typedef struct crypt_path_t {
-  uint32_t magic;
-
-  /** Cryptographic state used for encrypting and authenticating relay
-   * cells to and from this hop. */
-  relay_crypto_t crypto;
-
-  /** Current state of the handshake as performed with the OR at this
-   * step. */
-  onion_handshake_state_t handshake_state;
-  /** Diffie-hellman handshake state for performing an introduction
-   * operations */
-  crypto_dh_t *rend_dh_handshake_state;
-
-  /** Negotiated key material shared with the OR at this step. */
-  char rend_circ_nonce[DIGEST_LEN];/* KH in tor-spec.txt */
-
-  /** Information to extend to the OR at this step. */
-  extend_info_t *extend_info;
-
-  /** Is the circuit built to this step?  Must be one of:
-   *    - CPATH_STATE_CLOSED (The circuit has not been extended to this step)
-   *    - CPATH_STATE_AWAITING_KEYS (We have sent an EXTEND/CREATE to this step
-   *      and not received an EXTENDED/CREATED)
-   *    - CPATH_STATE_OPEN (The circuit has been extended to this step) */
-  uint8_t state;
-#define CPATH_STATE_CLOSED 0
-#define CPATH_STATE_AWAITING_KEYS 1
-#define CPATH_STATE_OPEN 2
-  struct crypt_path_t *next; /**< Link to next crypt_path_t in the circuit.
-                              * (The list is circular, so the last node
-                              * links to the first.) */
-  struct crypt_path_t *prev; /**< Link to previous crypt_path_t in the
-                              * circuit. */
-
-  int package_window; /**< How many cells are we allowed to originate ending
-                       * at this step? */
-  int deliver_window; /**< How many cells are we willing to deliver originating
-                       * at this step? */
-} crypt_path_t;
+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
diff --git a/src/or/or_circuit_st.h b/src/or/or_circuit_st.h
index f76737fbd..07022272a 100644
--- a/src/or/or_circuit_st.h
+++ b/src/or/or_circuit_st.h
@@ -10,6 +10,7 @@
 #include "or.h"
 
 #include "circuit_st.h"
+#include "crypt_path_st.h"
 
 struct onion_queue_t;
 
diff --git a/src/or/relay_crypto_st.h b/src/or/relay_crypto_st.h
new file mode 100644
index 000000000..4e23f4e40
--- /dev/null
+++ b/src/or/relay_crypto_st.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef RELAY_CRYPTO_ST_H
+#define RELAY_CRYPTO_ST_H
+
+struct relay_crypto_t {
+  /* crypto environments */
+  /** Encryption key and counter for cells heading towards the OR at this
+   * step. */
+  crypto_cipher_t *f_crypto;
+  /** Encryption key and counter for cells heading back from the OR at this
+   * step. */
+  crypto_cipher_t *b_crypto;
+
+  /** Digest state for cells heading towards the OR at this step. */
+  crypto_digest_t *f_digest; /* for integrity checking */
+  /** Digest state for cells heading away from the OR at this step. */
+  crypto_digest_t *b_digest;
+
+};
+
+#endif
+
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 6762bbfb0..8e621562a 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -33,6 +33,7 @@
 #include "routerlist.h"
 #include "routerset.h"
 
+#include "crypt_path_st.h"
 #include "dir_connection_st.h"
 #include "entry_connection_st.h"
 #include "origin_circuit_st.h"
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 308b91878..116ca730f 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -31,6 +31,7 @@
 #include "routerlist.h"
 #include "routerparse.h"
 
+#include "crypt_path_st.h"
 #include "origin_circuit_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 d1e6f8a8e..09a52ea07 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -36,6 +36,7 @@
 #include "routerparse.h"
 #include "routerset.h"
 
+#include "crypt_path_st.h"
 #include "edge_connection_st.h"
 #include "origin_circuit_st.h"
 
diff --git a/src/or/router.c b/src/or/router.c
index 11ee2e6ab..2d0305889 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -39,6 +39,7 @@
 
 #include "dirauth/mode.h"
 
+#include "crypt_path_st.h"
 #include "dir_connection_st.h"
 #include "dir_server_st.h"
 #include "origin_circuit_st.h"
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index c03164954..8efde6f84 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -17,6 +17,7 @@
 #include "circuituse.h"
 #include "channel.h"
 
+#include "crypt_path_st.h"
 #include "origin_circuit_st.h"
 
 void test_circuitstats_timeout(void *arg);
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 19a32aa8a..83a3ecbfc 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -30,11 +30,12 @@
 #include "statefile.h"
 #include "util.h"
 
+#include "crypt_path_st.h"
 #include "dir_connection_st.h"
+#include "origin_circuit_st.h"
 
 #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_hs_client.c b/src/test/test_hs_client.c
index bf0d56f8a..4443bd922 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 "crypt_path_st.h"
 #include "dir_connection_st.h"
 #include "entry_connection_st.h"
 #include "origin_circuit_st.h"
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 06df50740..947243e67 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 "crypt_path_st.h"
 #include "origin_circuit_st.h"
 
 /* Trunnel */
diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c
index e6a673403..0d78f97d8 100644
--- a/src/test/test_relaycell.c
+++ b/src/test/test_relaycell.c
@@ -16,6 +16,7 @@
 #include "relay.h"
 #include "test.h"
 
+#include "crypt_path_st.h"
 #include "entry_connection_st.h"
 #include "origin_circuit_st.h"
 





More information about the tor-commits mailing list