From e15d3e6fd20b3f87abaad7ddec1c88b0e66419f9 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Mon, 15 Jul 2024 13:16:01 +0200 Subject: p2p: Major refactoring of the handshake protocol Introduce a new protocol InitProtocol which can be used as the core protocol for initializing a connection with a peer. Move the handshake logic from the PeerPool module to the protocols directory and build a handshake protocol that implements InitProtocol trait. --- p2p/examples/chat.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'p2p/examples') diff --git a/p2p/examples/chat.rs b/p2p/examples/chat.rs index 5867c8b..2ea6b2c 100644 --- a/p2p/examples/chat.rs +++ b/p2p/examples/chat.rs @@ -69,11 +69,8 @@ impl Protocol for ChatProtocol { } }); - let listener = self.peer.register_listener::().await; loop { - let event = listener.recv().await.expect("Receive new protocol event"); - - match event { + match self.peer.recv::().await? { ProtocolEvent::Message(msg) => { let msg = String::from_utf8(msg).expect("Convert received bytes to string"); println!("{msg}"); @@ -85,7 +82,6 @@ impl Protocol for ChatProtocol { } task.cancel().await; - listener.cancel().await; Ok(()) } -- cgit v1.2.3