@@ -4,6 +4,11 @@ use async_trait::async_trait;
44use futures:: { Sink , Stream } ;
55use libp2p:: PeerId ;
66
7+ pub enum NegotiationSide {
8+ Inbound ,
9+ Outbound ,
10+ }
11+
712pub enum NegotiatorOutput {
813 None ,
914 /// Returned when the handshake concluded that the currently connecting peer is a duplicate of
@@ -20,34 +25,25 @@ pub enum NegotiatorError {
2025 AuthenticationFailed ,
2126}
2227
28+ pub type ConnectionSender = dyn Sink < Vec < u8 > , Error = IoError > + Unpin + Send ;
29+ pub type ConnectionReceiver = dyn Stream < Item = Result < Vec < u8 > , IoError > > + Unpin + Send ;
30+
2331#[ async_trait]
2432pub trait Negotiator : Send + Clone {
25- /// Performs the handshake protocol when we are the incoming connection side.
26- /// `connection` is the channel that can be used to communicate with the other peer.
27- async fn negotiate_incoming_connection < NegotiatorChannel > (
28- & mut self ,
29- my_peer_id : PeerId ,
30- other_peer_id : PeerId ,
31- connection : & mut NegotiatorChannel ,
32- ) -> Result < NegotiatorOutput , NegotiatorError >
33- where
34- NegotiatorChannel :
35- Sink < Vec < u8 > , Error = IoError > + Stream < Item = Result < Vec < u8 > , IoError > > + Unpin + Send ;
36-
37- /// Performs the handshake protocol when we are the outgoing connection side.
38- /// `connection` is the channel that can be used to communicate with the other peer.
39- async fn negotiate_outgoing_connection < NegotiatorChannel > (
33+ /// Performs the handshake protocol.
34+ /// `connection_sender` is the channel that can be used to send data to the remote peer.
35+ /// `connection_receiver` is the channel that can be used to receive data from the remote peer.
36+ async fn negotiate_connection (
4037 & mut self ,
4138 my_peer_id : PeerId ,
4239 other_peer_id : PeerId ,
43- connection : & mut NegotiatorChannel ,
44- ) -> Result < NegotiatorOutput , NegotiatorError >
45- where
46- NegotiatorChannel :
47- Sink < Vec < u8 > , Error = IoError > + Stream < Item = Result < Vec < u8 > , IoError > > + Unpin + Send ;
40+ connection_sender : & mut ConnectionSender ,
41+ connection_receiver : & mut ConnectionReceiver ,
42+ side : NegotiationSide ,
43+ ) -> Result < NegotiatorOutput , NegotiatorError > ;
4844
4945 /// A unique identified for your authentication protocol. For example: "strk_id" or
5046 /// "strk_id_v2".
51- // TODO(guy.f ): Consider making this a const.
47+ // TODO(noam.s ): Consider making this a const.
5248 fn protocol_name ( & self ) -> & ' static str ;
5349}
0 commit comments