Skip to content

Commit

Permalink
fix(boostrap): connect to peers concurrently when querying their echo…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
bochaco authored and lionel-faber committed Apr 8, 2021
1 parent 06ddd1c commit bb6b7dd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit bb6b7dd

Please sign in to comment.