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

[tor-commits] [tor/master] Factor out common parts of channel_tls_connect() and channel_tls_handle_incoming(); fixes get_remote_addr problem with incoming connections for bug 7112



commit 981f25a73ad5ff5de1147e6f9bc3cb7c55cda71b
Author: Andrea Shepard <andrea@xxxxxxxxxxxxxx>
Date:   Thu Oct 18 18:08:35 2012 -0700

    Factor out common parts of channel_tls_connect() and channel_tls_handle_incoming(); fixes get_remote_addr problem with incoming connections for bug 7112
---
 src/or/channeltls.c |   69 ++++++++++++++++++++++++++------------------------
 1 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index a7ac83f..af0f096 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -46,6 +46,9 @@ uint64_t stats_n_authorize_cells_processed = 0;
 /** Active listener, if any */
 channel_listener_t *channel_tls_listener = NULL;
 
+/* Utility function declarations */
+static void channel_tls_common_init(channel_tls_t *tlschan);
+
 /* channel_tls_t method declarations */
 
 static void channel_tls_close_method(channel_t *chan);
@@ -92,19 +95,18 @@ static int enter_v3_handshake_with_cell(var_cell_t *cell,
                                         channel_tls_t *tlschan);
 
 /**
- * Start a new TLS channel
- *
- * Launch a new OR connection to <b>addr</b>:<b>port</b> and expect to
- * handshake with an OR with identity digest <b>id_digest</b>, and wrap
- * it in a channel_tls_t.
+ * Do parts of channel_tls_t initialization common to channel_tls_connect()
+ * and channel_tls_handle_incoming().
  */
 
-channel_t *
-channel_tls_connect(const tor_addr_t *addr, uint16_t port,
-                    const char *id_digest)
+static void
+channel_tls_common_init(channel_tls_t *tlschan)
 {
-  channel_tls_t *tlschan = tor_malloc_zero(sizeof(*tlschan));
-  channel_t *chan = &(tlschan->base_);
+  channel_t *chan;
+
+  tor_assert(tlschan);
+
+  chan = &(tlschan->base_);
   channel_init(chan);
   chan->magic = TLS_CHAN_MAGIC;
   chan->state = CHANNEL_STATE_OPENING;
@@ -120,6 +122,29 @@ channel_tls_connect(const tor_addr_t *addr, uint16_t port,
   chan->write_packed_cell = channel_tls_write_packed_cell_method;
   chan->write_var_cell = channel_tls_write_var_cell_method;
 
+  chan->cmux = circuitmux_alloc();
+  if (cell_ewma_enabled()) {
+    circuitmux_set_policy(chan->cmux, &ewma_policy);
+  }
+}
+
+/**
+ * Start a new TLS channel
+ *
+ * Launch a new OR connection to <b>addr</b>:<b>port</b> and expect to
+ * handshake with an OR with identity digest <b>id_digest</b>, and wrap
+ * it in a channel_tls_t.
+ */
+
+channel_t *
+channel_tls_connect(const tor_addr_t *addr, uint16_t port,
+                    const char *id_digest)
+{
+  channel_tls_t *tlschan = tor_malloc_zero(sizeof(*tlschan));
+  channel_t *chan = &(tlschan->base_);
+
+  channel_tls_common_init(tlschan);
+
   log_debug(LD_CHANNEL,
             "In channel_tls_connect() for channel %p "
             "(global id " U64_FORMAT ")",
@@ -129,11 +154,6 @@ channel_tls_connect(const tor_addr_t *addr, uint16_t port,
   if (is_local_addr(addr)) channel_mark_local(chan);
   channel_mark_outgoing(chan);
 
-  chan->cmux = circuitmux_alloc();
-  if (cell_ewma_enabled()) {
-    circuitmux_set_policy(chan->cmux, &ewma_policy);
-  }
-
   /* Set up or_connection stuff */
   tlschan->conn = connection_or_connect(addr, port, id_digest, tlschan);
   /* connection_or_connect() will fill in tlschan->conn */
@@ -255,19 +275,7 @@ channel_tls_handle_incoming(or_connection_t *orconn)
   tor_assert(orconn);
   tor_assert(!(orconn->chan));
 
-  channel_init(chan);
-  chan->magic = TLS_CHAN_MAGIC;
-  chan->state = CHANNEL_STATE_OPENING;
-  chan->close = channel_tls_close_method;
-  chan->describe_transport = channel_tls_describe_transport_method;
-  chan->get_remote_descr = channel_tls_get_remote_descr_method;
-  chan->has_queued_writes = channel_tls_has_queued_writes_method;
-  chan->is_canonical = channel_tls_is_canonical_method;
-  chan->matches_extend_info = channel_tls_matches_extend_info_method;
-  chan->matches_target = channel_tls_matches_target_method;
-  chan->write_cell = channel_tls_write_cell_method;
-  chan->write_packed_cell = channel_tls_write_packed_cell_method;
-  chan->write_var_cell = channel_tls_write_var_cell_method;
+  channel_tls_common_init(tlschan);
 
   /* Link the channel and orconn to each other */
   tlschan->conn = orconn;
@@ -276,11 +284,6 @@ channel_tls_handle_incoming(or_connection_t *orconn)
   if (is_local_addr(&(TO_CONN(orconn)->addr))) channel_mark_local(chan);
   channel_mark_incoming(chan);
 
-  chan->cmux = circuitmux_alloc();
-  if (cell_ewma_enabled()) {
-    circuitmux_set_policy(chan->cmux, &ewma_policy);
-  }
-
   /* If we got one, we should register it */
   if (chan) channel_register(chan);
 

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