From bb6b7dd149ecfa7ced30eda1a6e3640a3e0206b5 Mon Sep 17 00:00:00 2001 From: bochaco Date: Wed, 7 Apr 2021 20:48:07 -0300 Subject: [PATCH] fix(boostrap): connect to peers concurrently when querying their echo service --- src/endpoint.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/endpoint.rs b/src/endpoint.rs index cf7e6d40..d90d4e53 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -453,10 +453,13 @@ impl Endpoint { let mut tasks = Vec::default(); for node in self.bootstrap_nodes.iter().cloned() { - debug!("Connecting to {:?}", &node); - self.connect_to(&node).await?; - let connection = self.get_connection(&node).ok_or(Error::MissingConnection)?; + let endpoint = self.clone(); let task_handle = tokio::spawn(async move { + debug!("Connecting to {:?}", &node); + endpoint.connect_to(&node).await?; + let connection = endpoint + .get_connection(&node) + .ok_or(Error::MissingConnection)?; let (mut send_stream, mut recv_stream) = connection.open_bi().await?; send_stream.send(WireMsg::EndpointEchoReq).await?; match WireMsg::read_from_stream(&mut recv_stream.quinn_recv_stream).await { @@ -469,9 +472,10 @@ impl Endpoint { } let (result, _) = futures::future::select_ok(tasks).await.map_err(|err| { - log::error!("Failed to contact echo service: {}", err); + error!("Failed to contact echo service: {}", err); Error::EchoServiceFailure(err.to_string()) })?; + result }