From a2aa701eb6b2a760990b6a52e65bd6ed8c3c8f76 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 21 Mar 2023 17:42:29 +0000 Subject: [PATCH] arti-client: Move client stream creation out of match, in connect We want this part for HS too. --- crates/arti-client/src/client.rs | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/arti-client/src/client.rs b/crates/arti-client/src/client.rs index b7d669b32..4c2ef6374 100644 --- a/crates/arti-client/src/client.rs +++ b/crates/arti-client/src/client.rs @@ -868,7 +868,7 @@ impl TorClient { let addr = target.into_tor_addr().map_err(wrap_err)?; addr.enforce_config(&self.addrcfg.get())?; - match addr.into_stream_instructions()? { + let (circ, addr, port) = match addr.into_stream_instructions()? { StreamInstructions::Exit { hostname: addr, port, @@ -879,20 +879,7 @@ impl TorClient { .await .map_err(wrap_err)?; debug!("Got a circuit for {}:{}", sensitive(&addr), port); - - let stream_future = circ.begin_stream(&addr, port, Some(prefs.stream_parameters())); - // This timeout is needless but harmless for optimistic streams. - let stream = self - .runtime - .timeout(self.timeoutcfg.get().connect_timeout, stream_future) - .await - .map_err(|_| ErrorDetail::ExitTimeout)? - .map_err(|cause| ErrorDetail::StreamFailed { - cause, - kind: "data", - })?; - - Ok(stream) + (circ, addr, port) } #[cfg(not(feature = "onion-client"))] @@ -914,7 +901,21 @@ impl TorClient { // needs to come out of this match statement todo!() // TODO HS } - } + }; + + let stream_future = circ.begin_stream(&addr, port, Some(prefs.stream_parameters())); + // This timeout is needless but harmless for optimistic streams. + let stream = self + .runtime + .timeout(self.timeoutcfg.get().connect_timeout, stream_future) + .await + .map_err(|_| ErrorDetail::ExitTimeout)? + .map_err(|cause| ErrorDetail::StreamFailed { + cause, + kind: "data", + })?; + + Ok(stream) } /// Sets the default preferences for future connections made with this client.