Browse Source

Moved the channel creation outside of the TLS handshake

The 'connection_tls_start_handshake' function now assumes that the
channel has already been created, rather than sometimes creating
it itself.
Steven Engler 4 years ago
parent
commit
2d735b871c
3 changed files with 23 additions and 14 deletions
  1. 13 0
      src/core/mainloop/connection.c
  2. 1 14
      src/core/or/connection_or.c
  3. 9 0
      src/feature/relay/ext_orport.c

+ 13 - 0
src/core/mainloop/connection.c

@@ -1849,12 +1849,25 @@ connection_handle_listener_read(connection_t *conn, int new_type)
     tor_assert(0);
   };
 
+  channel_t *chan = NULL;
+
+  if (new_type == CONN_TYPE_OR) {
+    /* Incoming connections will need a new channel passed to the
+     * channel_tls_listener */
+    tor_assert(TO_OR_CONN(newconn)->chan == NULL);
+
+    chan = channel_tls_handle_incoming(TO_OR_CONN(newconn));
+    channel_listener_queue_incoming(channel_tls_get_listener(), chan);
+  }
+
   if (connection_add(newconn) < 0) { /* no space, forget it */
+    channel_close_for_error(chan);
     connection_free(newconn);
     return 0; /* no need to tear down the parent */
   }
 
   if (connection_init_accepted_conn(newconn, TO_LISTENER_CONN(conn)) < 0) {
+    channel_close_for_error(chan);
     if (! newconn->marked_for_close)
       connection_mark_for_close(newconn);
     return 0;

+ 1 - 14
src/core/or/connection_or.c

@@ -1661,20 +1661,7 @@ connection_or_close_for_error,(or_connection_t *orconn, int flush))
 MOCK_IMPL(int,
 connection_tls_start_handshake,(or_connection_t *conn, int receiving))
 {
-  channel_listener_t *chan_listener;
-  channel_t *chan;
-
-  /* Incoming connections will need a new channel passed to the
-   * channel_tls_listener */
-  if (receiving) {
-    /* It shouldn't already be set */
-    tor_assert(!(conn->chan));
-    chan_listener = channel_tls_get_listener();
-    tor_assert(chan_listener != NULL);
-    chan = channel_tls_handle_incoming(conn);
-    channel_listener_queue_incoming(chan_listener, chan);
-  }
-
+  tor_assert(conn->chan != NULL);
   connection_or_change_state(conn, OR_CONN_STATE_TLS_HANDSHAKING);
   tor_assert(!conn->tls);
   conn->tls = tor_tls_new(conn->base_.s, receiving);

+ 9 - 0
src/feature/relay/ext_orport.c

@@ -17,7 +17,10 @@
  */
 
 #define EXT_ORPORT_PRIVATE
+#define TOR_CHANNEL_INTERNAL_
 #include "core/or/or.h"
+#include "core/or/channel.h"
+#include "core/or/channeltls.h"
 #include "core/mainloop/connection.h"
 #include "core/or/connection_or.h"
 #include "feature/control/control_events.h"
@@ -91,6 +94,12 @@ connection_ext_or_transition(or_connection_t *conn)
   conn->base_.type = CONN_TYPE_OR;
   TO_CONN(conn)->state = 0; // set the state to a neutral value
   connection_or_event_status(conn, OR_CONN_EVENT_NEW, 0);
+
+  tor_assert(conn->chan == NULL);
+
+  channel_t *chan = channel_tls_handle_incoming(conn);
+  channel_listener_queue_incoming(channel_tls_get_listener(), chan);
+
   connection_tls_start_handshake(conn, 1);
 }