@@ -44,7 +44,12 @@ use super::{
44
44
ConnectionHandler ,
45
45
IntoConnectionHandler ,
46
46
PendingConnectionError ,
47
- Substream
47
+ Substream ,
48
+ handler:: {
49
+ THandlerInEvent ,
50
+ THandlerOutEvent ,
51
+ THandlerError ,
52
+ } ,
48
53
} ;
49
54
use task:: { Task , TaskId } ;
50
55
@@ -88,15 +93,15 @@ impl ConnectionId {
88
93
}
89
94
90
95
/// A connection `Manager` orchestrates the I/O of a set of connections.
91
- pub struct Manager < I , O , H , E , HE > {
96
+ pub struct Manager < H : IntoConnectionHandler , E > {
92
97
/// The tasks of the managed connections.
93
98
///
94
99
/// Each managed connection is associated with a (background) task
95
100
/// spawned onto an executor. Each `TaskInfo` in `tasks` is linked to such a
96
101
/// background task via a channel. Closing that channel (i.e. dropping
97
102
/// the sender in the associated `TaskInfo`) stops the background task,
98
103
/// which will attempt to gracefully close the connection.
99
- tasks : FnvHashMap < TaskId , TaskInfo < I > > ,
104
+ tasks : FnvHashMap < TaskId , TaskInfo < THandlerInEvent < H > > > ,
100
105
101
106
/// Next available identifier for a new connection / task.
102
107
next_task_id : TaskId ,
@@ -115,13 +120,13 @@ pub struct Manager<I, O, H, E, HE> {
115
120
116
121
/// Sender distributed to managed tasks for reporting events back
117
122
/// to the manager.
118
- events_tx : mpsc:: Sender < task:: Event < O , H , E , HE > > ,
123
+ events_tx : mpsc:: Sender < task:: Event < H , E > > ,
119
124
120
125
/// Receiver for events reported from managed tasks.
121
- events_rx : mpsc:: Receiver < task:: Event < O , H , E , HE > >
126
+ events_rx : mpsc:: Receiver < task:: Event < H , E > >
122
127
}
123
128
124
- impl < I , O , H , E , HE > fmt:: Debug for Manager < I , O , H , E , HE >
129
+ impl < H : IntoConnectionHandler , E > fmt:: Debug for Manager < H , E >
125
130
{
126
131
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
127
132
f. debug_map ( )
@@ -179,7 +184,7 @@ enum TaskState {
179
184
180
185
/// Events produced by the [`Manager`].
181
186
#[ derive( Debug ) ]
182
- pub enum Event < ' a , I , O , H , TE , HE > {
187
+ pub enum Event < ' a , H : IntoConnectionHandler , TE > {
183
188
/// A connection attempt has failed.
184
189
PendingConnectionError {
185
190
/// The connection ID.
@@ -206,35 +211,35 @@ pub enum Event<'a, I, O, H, TE, HE> {
206
211
connected : Connected ,
207
212
/// The error that occurred, if any. If `None`, the connection
208
213
/// has been actively closed.
209
- error : Option < ConnectionError < HE > > ,
214
+ error : Option < ConnectionError < THandlerError < H > > > ,
210
215
} ,
211
216
212
217
/// A connection has been established.
213
218
ConnectionEstablished {
214
219
/// The entry associated with the new connection.
215
- entry : EstablishedEntry < ' a , I > ,
220
+ entry : EstablishedEntry < ' a , THandlerInEvent < H > > ,
216
221
} ,
217
222
218
223
/// A connection handler has produced an event.
219
224
ConnectionEvent {
220
225
/// The entry associated with the connection that produced the event.
221
- entry : EstablishedEntry < ' a , I > ,
226
+ entry : EstablishedEntry < ' a , THandlerInEvent < H > > ,
222
227
/// The produced event.
223
- event : O
228
+ event : THandlerOutEvent < H >
224
229
} ,
225
230
226
231
/// A connection to a node has changed its address.
227
232
AddressChange {
228
233
/// The entry associated with the connection that changed address.
229
- entry : EstablishedEntry < ' a , I > ,
234
+ entry : EstablishedEntry < ' a , THandlerInEvent < H > > ,
230
235
/// The former [`ConnectedPoint`].
231
236
old_endpoint : ConnectedPoint ,
232
237
/// The new [`ConnectedPoint`].
233
238
new_endpoint : ConnectedPoint ,
234
239
} ,
235
240
}
236
241
237
- impl < I , O , H , TE , HE > Manager < I , O , H , TE , HE > {
242
+ impl < H : IntoConnectionHandler , TE > Manager < H , TE > {
238
243
/// Creates a new connection manager.
239
244
pub fn new ( config : ManagerConfig ) -> Self {
240
245
let ( tx, rx) = mpsc:: channel ( config. task_event_buffer_size ) ;
@@ -255,19 +260,13 @@ impl<I, O, H, TE, HE> Manager<I, O, H, TE, HE> {
255
260
/// processing the node's events.
256
261
pub fn add_pending < F , M > ( & mut self , future : F , handler : H ) -> ConnectionId
257
262
where
258
- I : Send + ' static ,
259
- O : Send + ' static ,
260
263
TE : error:: Error + Send + ' static ,
261
- HE : error:: Error + Send + ' static ,
262
264
M : StreamMuxer + Send + Sync + ' static ,
263
265
M :: OutboundSubstream : Send + ' static ,
264
266
F : Future < Output = ConnectResult < M , TE > > + Send + ' static ,
265
267
H : IntoConnectionHandler + Send + ' static ,
266
268
H :: Handler : ConnectionHandler <
267
269
Substream = Substream < M > ,
268
- InEvent = I ,
269
- OutEvent = O ,
270
- Error = HE
271
270
> + Send + ' static ,
272
271
<H :: Handler as ConnectionHandler >:: OutboundOpenInfo : Send + ' static ,
273
272
{
@@ -293,15 +292,9 @@ impl<I, O, H, TE, HE> Manager<I, O, H, TE, HE> {
293
292
H : IntoConnectionHandler + Send + ' static ,
294
293
H :: Handler : ConnectionHandler <
295
294
Substream = Substream < M > ,
296
- InEvent = I ,
297
- OutEvent = O ,
298
- Error = HE
299
295
> + Send + ' static ,
300
296
<H :: Handler as ConnectionHandler >:: OutboundOpenInfo : Send + ' static ,
301
297
TE : error:: Error + Send + ' static ,
302
- HE : error:: Error + Send + ' static ,
303
- I : Send + ' static ,
304
- O : Send + ' static ,
305
298
M : StreamMuxer + Send + Sync + ' static ,
306
299
M :: OutboundSubstream : Send + ' static ,
307
300
{
@@ -313,7 +306,7 @@ impl<I, O, H, TE, HE> Manager<I, O, H, TE, HE> {
313
306
sender : tx, state : TaskState :: Established ( info)
314
307
} ) ;
315
308
316
- let task: Pin < Box < Task < Pin < Box < future:: Pending < _ > > > , _ , _ , _ , _ , _ > > > =
309
+ let task: Pin < Box < Task < Pin < Box < future:: Pending < _ > > > , _ , _ , _ > > > =
317
310
Box :: pin ( Task :: established ( task_id, self . events_tx . clone ( ) , rx, conn) ) ;
318
311
319
312
if let Some ( executor) = & mut self . executor {
@@ -326,7 +319,7 @@ impl<I, O, H, TE, HE> Manager<I, O, H, TE, HE> {
326
319
}
327
320
328
321
/// Gets an entry for a managed connection, if it exists.
329
- pub fn entry ( & mut self , id : ConnectionId ) -> Option < Entry < ' _ , I > > {
322
+ pub fn entry ( & mut self , id : ConnectionId ) -> Option < Entry < ' _ , THandlerInEvent < H > > > {
330
323
if let hash_map:: Entry :: Occupied ( task) = self . tasks . entry ( id. 0 ) {
331
324
Some ( Entry :: new ( task) )
332
325
} else {
@@ -340,7 +333,7 @@ impl<I, O, H, TE, HE> Manager<I, O, H, TE, HE> {
340
333
}
341
334
342
335
/// Polls the manager for events relating to the managed connections.
343
- pub fn poll < ' a > ( & ' a mut self , cx : & mut Context < ' _ > ) -> Poll < Event < ' a , I , O , H , TE , HE > > {
336
+ pub fn poll < ' a > ( & ' a mut self , cx : & mut Context < ' _ > ) -> Poll < Event < ' a , H , TE > > {
344
337
// Advance the content of `local_spawns`.
345
338
while let Poll :: Ready ( Some ( _) ) = self . local_spawns . poll_next_unpin ( cx) { }
346
339
0 commit comments