diff options
author | hozan23 <hozan23@karyontech.net> | 2024-07-15 13:16:01 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-07-15 13:16:01 +0200 |
commit | e15d3e6fd20b3f87abaad7ddec1c88b0e66419f9 (patch) | |
tree | 7976f6993e4f6b3646f5bd6954189346d5ffd330 /p2p/src/protocol.rs | |
parent | 6c65232d741229635151671708556b9af7ef75ac (diff) |
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.
Diffstat (limited to 'p2p/src/protocol.rs')
-rw-r--r-- | p2p/src/protocol.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 021844f..249692b 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -56,11 +56,8 @@ impl EventValue for ProtocolEvent { /// #[async_trait] /// impl Protocol for NewProtocol { /// async fn start(self: Arc<Self>) -> Result<(), Error> { -/// let listener = self.peer.register_listener::<Self>().await; /// loop { -/// let event = listener.recv().await.unwrap(); -/// -/// match event { +/// match self.peer.recv::<Self>().await.expect("Receive msg") { /// ProtocolEvent::Message(msg) => { /// println!("{:?}", msg); /// } @@ -69,8 +66,6 @@ impl EventValue for ProtocolEvent { /// } /// } /// } -/// -/// listener.cancel().await; /// Ok(()) /// } /// @@ -114,3 +109,10 @@ pub trait Protocol: Send + Sync { where Self: Sized; } + +#[async_trait] +pub(crate) trait InitProtocol: Send + Sync { + type T; + /// Initialize the protocol + async fn init(self: Arc<Self>) -> Self::T; +} |