]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay: Split state checks out of circuit_extend()
authorteor <teor@torproject.org>
Tue, 31 Mar 2020 23:20:58 +0000 (09:20 +1000)
committerteor <teor@torproject.org>
Thu, 9 Apr 2020 01:00:04 +0000 (11:00 +1000)
Part of 33633.

src/feature/relay/circuitbuild_relay.c

index 85a05a86517e93abcd399e46b1172622876469d8..469fd44b82637a56a392322a2b6a32192b2bf96e 100644 (file)
 /* Before replying to an extend cell, check the state of the circuit
  * <b>circ</b>, and the configured tor mode.
  *
- * Return -1 if we want to warn and tear down the circuit, else return 0.
+ * If the state and mode are valid, return 0.
+ * Otherwise, if they are invalid, log a protocol warning, and return -1.
  */
-int
-circuit_extend(struct cell_t *cell, struct circuit_t *circ)
+static int
+circuit_extend_state_valid_helper(const struct circuit_t *circ)
 {
-  channel_t *n_chan;
-  relay_header_t rh;
-  extend_cell_t ec;
-  const char *msg = NULL;
-  int should_launch = 0;
-
   if (!server_mode(get_options())) {
     circuitbuild_warn_client_extend();
     return -1;
@@ -69,6 +64,29 @@ circuit_extend(struct cell_t *cell, struct circuit_t *circ)
     return -1;
   }
 
+  return 0;
+}
+
+/** Take the 'extend' <b>cell</b>, pull out addr/port plus the onion
+ * skin and identity digest for the next hop. If we're already connected,
+ * pass the onion skin to the next hop using a create cell; otherwise
+ * launch a new OR connection, and <b>circ</b> will notice when the
+ * connection succeeds or fails.
+ *
+ * Return -1 if we want to warn and tear down the circuit, else return 0.
+ */
+int
+circuit_extend(struct cell_t *cell, struct circuit_t *circ)
+{
+  channel_t *n_chan;
+  relay_header_t rh;
+  extend_cell_t ec;
+  const char *msg = NULL;
+  int should_launch = 0;
+
+  if (circuit_extend_state_valid_helper(circ) < 0)
+    return -1;
+
   relay_header_unpack(&rh, cell->payload);
 
   if (extend_cell_parse(&ec, rh.command,