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

[tor-commits] [tor/master] Refactor channel_connect_for_circuit() to take an extend_info_t.



commit 1e97f968882f12edad20874ada99c2bd8542119d
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Jul 1 14:42:55 2020 -0400

    Refactor channel_connect_for_circuit() to take an extend_info_t.
---
 src/core/or/circuitbuild.c             | 15 +++++++--------
 src/core/or/circuitbuild.h             |  8 +-------
 src/feature/relay/circuitbuild_relay.c |  6 +-----
 src/test/test_circuitbuild.c           | 10 ++--------
 4 files changed, 11 insertions(+), 28 deletions(-)

diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index 1f9b5050e..d1f097c25 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -94,12 +94,15 @@ static const node_t *choose_good_middle_server(uint8_t purpose,
  * callbacks.
  */
 MOCK_IMPL(channel_t *,
-channel_connect_for_circuit,(const tor_addr_t *addr, uint16_t port,
-                             const char *id_digest,
-                             const struct ed25519_public_key_t *ed_id))
+channel_connect_for_circuit,(const extend_info_t *ei))
 {
   channel_t *chan;
 
+  const tor_addr_t *addr = &ei->addr;
+  uint16_t port = ei->port;
+  const char *id_digest = ei->identity_digest;
+  const ed25519_public_key_t *ed_id = &ei->ed_identity;
+
   chan = channel_connect(addr, port, id_digest, ed_id);
   if (chan) command_setup_channel(chan);
 
@@ -581,11 +584,7 @@ circuit_handle_first_hop(origin_circuit_t *circ)
     circ->base_.n_hop = extend_info_dup(firsthop->extend_info);
 
     if (should_launch) {
-      n_chan = channel_connect_for_circuit(
-          &firsthop->extend_info->addr,
-          firsthop->extend_info->port,
-          firsthop->extend_info->identity_digest,
-          &firsthop->extend_info->ed_identity);
+      n_chan = channel_connect_for_circuit(firsthop->extend_info);
       if (!n_chan) { /* connect failed, forget the whole thing */
         log_info(LD_CIRC,"connect to firsthop failed. Closing.");
         return -END_CIRC_REASON_CONNECTFAILED;
diff --git a/src/core/or/circuitbuild.h b/src/core/or/circuitbuild.h
index bbb78eada..0cd1eb4f4 100644
--- a/src/core/or/circuitbuild.h
+++ b/src/core/or/circuitbuild.h
@@ -56,13 +56,7 @@ const node_t *choose_good_entry_server(uint8_t purpose,
                            struct circuit_guard_state_t **guard_state_out);
 void circuit_upgrade_circuits_from_guard_wait(void);
 
-struct ed25519_public_key_t;
-
-MOCK_DECL(channel_t *,
-channel_connect_for_circuit,(const tor_addr_t *addr,
-                             uint16_t port,
-                             const char *id_digest,
-                             const struct ed25519_public_key_t *ed_id));
+MOCK_DECL(channel_t *, channel_connect_for_circuit,(const extend_info_t *ei));
 
 struct create_cell_t;
 MOCK_DECL(int,
diff --git a/src/feature/relay/circuitbuild_relay.c b/src/feature/relay/circuitbuild_relay.c
index 36e64d9b3..881cbd51b 100644
--- a/src/feature/relay/circuitbuild_relay.c
+++ b/src/feature/relay/circuitbuild_relay.c
@@ -401,11 +401,7 @@ circuit_open_connection_for_extend(const struct extend_cell_t *ec,
 
   if (should_launch) {
     /* we should try to open a connection */
-    channel_t *n_chan = channel_connect_for_circuit(
-                                                &circ->n_hop->addr,
-                                                circ->n_hop->port,
-                                                circ->n_hop->identity_digest,
-                                                &circ->n_hop->ed_identity);
+    channel_t *n_chan = channel_connect_for_circuit(circ->n_hop);
     if (!n_chan) {
       log_info(LD_CIRC,"Launching n_chan failed. Closing circuit.");
       circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
diff --git a/src/test/test_circuitbuild.c b/src/test/test_circuitbuild.c
index e1fbd333d..f7a27146b 100644
--- a/src/test/test_circuitbuild.c
+++ b/src/test/test_circuitbuild.c
@@ -1001,15 +1001,9 @@ mock_circuit_mark_for_close_(circuit_t *circ, int reason,
 static int mock_channel_connect_calls = 0;
 static channel_t *mock_channel_connect_nchan = NULL;
 static channel_t *
-mock_channel_connect_for_circuit(const tor_addr_t *addr,
-                                 uint16_t port,
-                                 const char *id_digest,
-                                 const struct ed25519_public_key_t *ed_id)
+mock_channel_connect_for_circuit(const extend_info_t *ei)
 {
-  (void)addr;
-  (void)port;
-  (void)id_digest;
-  (void)ed_id;
+  (void)ei;
   mock_channel_connect_calls++;
   return mock_channel_connect_nchan;
 }



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