aboutsummaryrefslogtreecommitdiff
path: root/src/feature/relay/circuitbuild_relay.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2020-04-01 09:20:58 +1000
committerteor <teor@torproject.org>2020-04-09 11:00:04 +1000
commit2563d74a5cb321887324c010d6509c3af3f1e238 (patch)
treeb1f32bafab111ed04aa3674f59e8ce5e25e387a4 /src/feature/relay/circuitbuild_relay.c
parentbeee9ca608e860ee71446e4923bf4f673eb012e3 (diff)
downloadtor-2563d74a5cb321887324c010d6509c3af3f1e238.tar.gz
tor-2563d74a5cb321887324c010d6509c3af3f1e238.zip
relay: Split state checks out of circuit_extend()
Part of 33633.
Diffstat (limited to 'src/feature/relay/circuitbuild_relay.c')
-rw-r--r--src/feature/relay/circuitbuild_relay.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/feature/relay/circuitbuild_relay.c b/src/feature/relay/circuitbuild_relay.c
index 85a05a8651..469fd44b82 100644
--- a/src/feature/relay/circuitbuild_relay.c
+++ b/src/feature/relay/circuitbuild_relay.c
@@ -42,17 +42,12 @@
/* 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,