@@ -23,13 +23,14 @@ pub(crate) mod handler;
23
23
mod listeners;
24
24
mod substream;
25
25
26
- pub ( crate ) mod manager;
27
26
pub ( crate ) mod pool;
28
27
29
- pub use error:: { ConnectionError , PendingConnectionError } ;
28
+ pub use error:: {
29
+ ConnectionError , PendingConnectionError , PendingInboundConnectionError ,
30
+ PendingOutboundConnectionError ,
31
+ } ;
30
32
pub use handler:: { ConnectionHandler , ConnectionHandlerEvent , IntoConnectionHandler } ;
31
33
pub use listeners:: { ListenerId , ListenersEvent , ListenersStream } ;
32
- pub use manager:: ConnectionId ;
33
34
pub use pool:: { ConnectionCounters , ConnectionLimits } ;
34
35
pub use pool:: { EstablishedConnection , EstablishedConnectionIter , PendingConnection } ;
35
36
pub use substream:: { Close , Substream , SubstreamEndpoint } ;
@@ -40,6 +41,21 @@ use std::hash::Hash;
40
41
use std:: { error:: Error , fmt, pin:: Pin , task:: Context , task:: Poll } ;
41
42
use substream:: { Muxing , SubstreamEvent } ;
42
43
44
+ /// Connection identifier.
45
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
46
+ pub struct ConnectionId ( usize ) ;
47
+
48
+ impl ConnectionId {
49
+ /// Creates a `ConnectionId` from a non-negative integer.
50
+ ///
51
+ /// This is primarily useful for creating connection IDs
52
+ /// in test environments. There is in general no guarantee
53
+ /// that all connection IDs are based on non-negative integers.
54
+ pub fn new ( id : usize ) -> Self {
55
+ ConnectionId ( id)
56
+ }
57
+ }
58
+
43
59
/// The endpoint roles associated with a peer-to-peer communication channel.
44
60
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
45
61
pub enum Endpoint {
@@ -72,7 +88,40 @@ impl Endpoint {
72
88
}
73
89
}
74
90
75
- /// The endpoint roles associated with a peer-to-peer connection.
91
+ /// The endpoint roles associated with a pending peer-to-peer connection.
92
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
93
+ pub enum PendingPoint {
94
+ /// The socket comes from a dialer.
95
+ ///
96
+ /// There is no single address associated with the Dialer of a pending
97
+ /// connection. Addresses are dialed in parallel. Only once the first dial
98
+ /// is successful is the address of the connection known.
99
+ Dialer ,
100
+ /// The socket comes from a listener.
101
+ Listener {
102
+ /// Local connection address.
103
+ local_addr : Multiaddr ,
104
+ /// Address used to send back data to the remote.
105
+ send_back_addr : Multiaddr ,
106
+ } ,
107
+ }
108
+
109
+ impl From < ConnectedPoint > for PendingPoint {
110
+ fn from ( endpoint : ConnectedPoint ) -> Self {
111
+ match endpoint {
112
+ ConnectedPoint :: Dialer { .. } => PendingPoint :: Dialer ,
113
+ ConnectedPoint :: Listener {
114
+ local_addr,
115
+ send_back_addr,
116
+ } => PendingPoint :: Listener {
117
+ local_addr,
118
+ send_back_addr,
119
+ } ,
120
+ }
121
+ }
122
+ }
123
+
124
+ /// The endpoint roles associated with an established peer-to-peer connection.
76
125
#[ derive( PartialEq , Eq , Debug , Clone , Hash ) ]
77
126
pub enum ConnectedPoint {
78
127
/// We dialed the node.
@@ -84,7 +133,7 @@ pub enum ConnectedPoint {
84
133
Listener {
85
134
/// Local connection address.
86
135
local_addr : Multiaddr ,
87
- /// Stack of protocols used to send back data to the remote.
136
+ /// Address used to send back data to the remote.
88
137
send_back_addr : Multiaddr ,
89
138
} ,
90
139
}
@@ -289,32 +338,23 @@ where
289
338
pub struct IncomingInfo < ' a > {
290
339
/// Local connection address.
291
340
pub local_addr : & ' a Multiaddr ,
292
- /// Stack of protocols used to send back data to the remote.
341
+ /// Address used to send back data to the remote.
293
342
pub send_back_addr : & ' a Multiaddr ,
294
343
}
295
344
296
345
impl < ' a > IncomingInfo < ' a > {
297
- /// Builds the `ConnectedPoint` corresponding to the incoming connection.
298
- pub fn to_connected_point ( & self ) -> ConnectedPoint {
299
- ConnectedPoint :: Listener {
346
+ /// Builds the [`PendingPoint`] corresponding to the incoming connection.
347
+ pub fn to_pending_point ( & self ) -> PendingPoint {
348
+ PendingPoint :: Listener {
300
349
local_addr : self . local_addr . clone ( ) ,
301
350
send_back_addr : self . send_back_addr . clone ( ) ,
302
351
}
303
352
}
304
- }
305
-
306
- /// Borrowed information about an outgoing connection currently being negotiated.
307
- #[ derive( Debug , Copy , Clone ) ]
308
- pub struct OutgoingInfo < ' a > {
309
- pub address : & ' a Multiaddr ,
310
- pub peer_id : Option < & ' a PeerId > ,
311
- }
312
-
313
- impl < ' a > OutgoingInfo < ' a > {
314
- /// Builds a `ConnectedPoint` corresponding to the outgoing connection.
353
+ /// Builds the [`ConnectedPoint`] corresponding to the incoming connection.
315
354
pub fn to_connected_point ( & self ) -> ConnectedPoint {
316
- ConnectedPoint :: Dialer {
317
- address : self . address . clone ( ) ,
355
+ ConnectedPoint :: Listener {
356
+ local_addr : self . local_addr . clone ( ) ,
357
+ send_back_addr : self . send_back_addr . clone ( ) ,
318
358
}
319
359
}
320
360
}
0 commit comments