This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(p2p): accept listener connection during bootstrap (#484)
Signed-off-by: Simon Paitrault <[email protected]> Signed-off-by: Monir Hadji <[email protected]> Co-authored-by: Monir Hadji <[email protected]>
- Loading branch information
Showing
12 changed files
with
216 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,52 @@ | ||
use tracing::debug; | ||
|
||
use crate::{behaviour::grpc, Runtime}; | ||
|
||
use super::{EventHandler, EventResult}; | ||
|
||
#[async_trait::async_trait] | ||
impl EventHandler<grpc::Event> for Runtime { | ||
async fn handle(&mut self, _event: grpc::Event) -> EventResult { | ||
async fn handle(&mut self, event: grpc::Event) -> EventResult { | ||
match event { | ||
grpc::Event::OutboundFailure { | ||
peer_id, | ||
request_id, | ||
error, | ||
} => { | ||
debug!( | ||
"Outbound connection failure to peer {} for request {}: {}", | ||
peer_id, request_id, error | ||
); | ||
} | ||
grpc::Event::OutboundSuccess { | ||
peer_id, | ||
request_id, | ||
.. | ||
} => { | ||
debug!( | ||
"Outbound connection success to peer {} for request {}", | ||
peer_id, request_id | ||
); | ||
} | ||
grpc::Event::InboundNegotiatedConnection { | ||
request_id, | ||
connection_id, | ||
} => { | ||
debug!( | ||
"Inbound connection negotiated for request {} with connection {}", | ||
request_id, connection_id | ||
); | ||
} | ||
grpc::Event::OutboundNegotiatedConnection { | ||
peer_id, | ||
request_id, | ||
} => { | ||
debug!( | ||
"Outbound connection negotiated to peer {} for request {}", | ||
peer_id, request_id | ||
); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::time::Duration; | ||
|
||
use futures::{future::join_all, FutureExt}; | ||
use rstest::rstest; | ||
use test_log::test; | ||
use topos_test_sdk::tce::NodeConfig; | ||
use tracing::Instrument; | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
#[timeout(Duration::from_secs(5))] | ||
async fn two_bootnode_communicating() { | ||
let bootnode = NodeConfig::memory(2); | ||
let local = NodeConfig::memory(1); | ||
let bootnode_known_peers = vec![(local.peer_id(), local.addr.clone())]; | ||
let local_known_peers = vec![(bootnode.peer_id(), bootnode.addr.clone())]; | ||
|
||
let mut handlers = Vec::new(); | ||
|
||
let context_local = tracing::info_span!("start_node", "peer_id" = local.peer_id().to_string()); | ||
|
||
let context_bootnode = | ||
tracing::info_span!("start_node", "peer_id" = bootnode.peer_id().to_string()); | ||
handlers.push( | ||
async move { | ||
let (client, mut stream, runtime) = crate::network::builder() | ||
.minimum_cluster_size(1) | ||
.peer_key(local.keypair.clone()) | ||
.listen_addresses(&[local.addr.clone()]) | ||
.known_peers(&local_known_peers) | ||
.memory() | ||
.build() | ||
.await | ||
.expect("Unable to create p2p network"); | ||
|
||
runtime.bootstrap(&mut stream).await | ||
} | ||
.instrument(context_local) | ||
.boxed(), | ||
); | ||
|
||
handlers.push( | ||
async move { | ||
let (client, mut stream, runtime) = crate::network::builder() | ||
.minimum_cluster_size(1) | ||
.peer_key(bootnode.keypair.clone()) | ||
.listen_addresses(&[bootnode.addr.clone()]) | ||
.known_peers(&bootnode_known_peers) | ||
.memory() | ||
.build() | ||
.await | ||
.expect("Unable to create p2p network"); | ||
|
||
runtime.bootstrap(&mut stream).await | ||
} | ||
.instrument(context_bootnode) | ||
.boxed(), | ||
); | ||
assert!(join_all(handlers).await.iter().all(Result::is_ok)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod behaviour; | ||
mod bootstrap; | ||
mod command; | ||
mod support; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.