@@ -107,18 +107,15 @@ pub struct Handler {
107107 /// We issue a stream upgrade for each pending request.
108108 pending_requests : VecDeque < PendingRequest > ,
109109
110- /// A `RESERVE` request is in-flight for each item in this queue.
111- active_reserve_requests : VecDeque < mpsc:: Sender < transport:: ToListenerMsg > > ,
112-
113- inflight_reserve_requests :
114- futures_bounded:: FuturesSet < Result < outbound_hop:: Reservation , outbound_hop:: ReserveError > > ,
115-
116- /// A `CONNECT` request is in-flight for each item in this queue.
117- active_connect_requests :
118- VecDeque < oneshot:: Sender < Result < priv_client:: Connection , outbound_hop:: ConnectError > > > ,
110+ inflight_reserve_requests : futures_bounded:: FuturesTupleSet <
111+ Result < outbound_hop:: Reservation , outbound_hop:: ReserveError > ,
112+ mpsc:: Sender < transport:: ToListenerMsg > ,
113+ > ,
119114
120- inflight_outbound_connect_requests :
121- futures_bounded:: FuturesSet < Result < outbound_hop:: Circuit , outbound_hop:: ConnectError > > ,
115+ inflight_outbound_connect_requests : futures_bounded:: FuturesTupleSet <
116+ Result < outbound_hop:: Circuit , outbound_hop:: ConnectError > ,
117+ oneshot:: Sender < Result < priv_client:: Connection , outbound_hop:: ConnectError > > ,
118+ > ,
122119
123120 inflight_inbound_circuit_requests :
124121 futures_bounded:: FuturesSet < Result < inbound_stop:: Circuit , inbound_stop:: Error > > ,
@@ -137,24 +134,22 @@ impl Handler {
137134 remote_addr,
138135 queued_events : Default :: default ( ) ,
139136 pending_requests : Default :: default ( ) ,
140- active_reserve_requests : Default :: default ( ) ,
141- inflight_reserve_requests : futures_bounded:: FuturesSet :: new (
137+ inflight_reserve_requests : futures_bounded:: FuturesTupleSet :: new (
142138 STREAM_TIMEOUT ,
143139 MAX_CONCURRENT_STREAMS_PER_CONNECTION ,
144140 ) ,
145141 inflight_inbound_circuit_requests : futures_bounded:: FuturesSet :: new (
146142 STREAM_TIMEOUT ,
147143 MAX_CONCURRENT_STREAMS_PER_CONNECTION ,
148144 ) ,
149- inflight_outbound_connect_requests : futures_bounded:: FuturesSet :: new (
145+ inflight_outbound_connect_requests : futures_bounded:: FuturesTupleSet :: new (
150146 STREAM_TIMEOUT ,
151147 MAX_CONCURRENT_STREAMS_PER_CONNECTION ,
152148 ) ,
153149 inflight_outbound_circuit_deny_requests : futures_bounded:: FuturesSet :: new (
154150 DENYING_CIRCUIT_TIMEOUT ,
155151 MAX_NUMBER_DENYING_CIRCUIT ,
156152 ) ,
157- active_connect_requests : Default :: default ( ) ,
158153 reservation : Reservation :: None ,
159154 }
160155 }
@@ -276,24 +271,16 @@ impl ConnectionHandler for Handler {
276271 ConnectionHandlerEvent < Self :: OutboundProtocol , Self :: OutboundOpenInfo , Self :: ToBehaviour > ,
277272 > {
278273 loop {
279- debug_assert_eq ! (
280- self . inflight_reserve_requests. len( ) ,
281- self . active_reserve_requests. len( ) ,
282- "expect to have one active request per inflight stream"
283- ) ;
284-
285274 // Reservations
286275 match self . inflight_reserve_requests . poll_unpin ( cx) {
287- Poll :: Ready ( Ok ( Ok ( outbound_hop:: Reservation {
288- renewal_timeout,
289- addrs,
290- limit,
291- } ) ) ) => {
292- let to_listener = self
293- . active_reserve_requests
294- . pop_front ( )
295- . expect ( "must have active request for stream" ) ;
296-
276+ Poll :: Ready ( (
277+ Ok ( Ok ( outbound_hop:: Reservation {
278+ renewal_timeout,
279+ addrs,
280+ limit,
281+ } ) ) ,
282+ to_listener,
283+ ) ) => {
297284 return Poll :: Ready ( ConnectionHandlerEvent :: NotifyBehaviour (
298285 self . reservation . accepted (
299286 renewal_timeout,
@@ -304,12 +291,7 @@ impl ConnectionHandler for Handler {
304291 ) ,
305292 ) ) ;
306293 }
307- Poll :: Ready ( Ok ( Err ( error) ) ) => {
308- let mut to_listener = self
309- . active_reserve_requests
310- . pop_front ( )
311- . expect ( "must have active request for stream" ) ;
312-
294+ Poll :: Ready ( ( Ok ( Err ( error) ) , mut to_listener) ) => {
313295 if let Err ( e) =
314296 to_listener. try_send ( transport:: ToListenerMsg :: Reservation ( Err ( error) ) )
315297 {
@@ -318,12 +300,7 @@ impl ConnectionHandler for Handler {
318300 self . reservation . failed ( ) ;
319301 continue ;
320302 }
321- Poll :: Ready ( Err ( futures_bounded:: Timeout { .. } ) ) => {
322- let mut to_listener = self
323- . active_reserve_requests
324- . pop_front ( )
325- . expect ( "must have active request for stream" ) ;
326-
303+ Poll :: Ready ( ( Err ( futures_bounded:: Timeout { .. } ) , mut to_listener) ) => {
327304 if let Err ( e) =
328305 to_listener. try_send ( transport:: ToListenerMsg :: Reservation ( Err (
329306 outbound_hop:: ReserveError :: Io ( io:: ErrorKind :: TimedOut . into ( ) ) ,
@@ -337,25 +314,17 @@ impl ConnectionHandler for Handler {
337314 Poll :: Pending => { }
338315 }
339316
340- debug_assert_eq ! (
341- self . inflight_outbound_connect_requests. len( ) ,
342- self . active_connect_requests. len( ) ,
343- "expect to have one active request per inflight stream"
344- ) ;
345-
346317 // Circuits
347318 match self . inflight_outbound_connect_requests . poll_unpin ( cx) {
348- Poll :: Ready ( Ok ( Ok ( outbound_hop:: Circuit {
349- limit,
350- read_buffer,
351- stream,
352- } ) ) ) => {
353- let to_listener = self
354- . active_connect_requests
355- . pop_front ( )
356- . expect ( "must have active request for stream" ) ;
357-
358- if to_listener
319+ Poll :: Ready ( (
320+ Ok ( Ok ( outbound_hop:: Circuit {
321+ limit,
322+ read_buffer,
323+ stream,
324+ } ) ) ,
325+ to_dialer,
326+ ) ) => {
327+ if to_dialer
359328 . send ( Ok ( priv_client:: Connection {
360329 state : priv_client:: ConnectionState :: new_outbound ( stream, read_buffer) ,
361330 } ) )
@@ -371,27 +340,18 @@ impl ConnectionHandler for Handler {
371340 Event :: OutboundCircuitEstablished { limit } ,
372341 ) ) ;
373342 }
374- Poll :: Ready ( Ok ( Err ( error) ) ) => {
375- let to_dialer = self
376- . active_connect_requests
377- . pop_front ( )
378- . expect ( "must have active request for stream" ) ;
379-
343+ Poll :: Ready ( ( Ok ( Err ( error) ) , to_dialer) ) => {
380344 let _ = to_dialer. send ( Err ( error) ) ;
381345 continue ;
382346 }
383- Poll :: Ready ( Err ( futures_bounded:: Timeout { .. } ) ) => {
384- let mut to_listener = self
385- . active_reserve_requests
386- . pop_front ( )
387- . expect ( "must have active request for stream" ) ;
388-
389- if let Err ( e) =
390- to_listener. try_send ( transport:: ToListenerMsg :: Reservation ( Err (
391- outbound_hop:: ReserveError :: Io ( io:: ErrorKind :: TimedOut . into ( ) ) ,
347+ Poll :: Ready ( ( Err ( futures_bounded:: Timeout { .. } ) , to_dialer) ) => {
348+ if to_dialer
349+ . send ( Err ( outbound_hop:: ConnectError :: Io (
350+ io:: ErrorKind :: TimedOut . into ( ) ,
392351 ) ) )
352+ . is_err ( )
393353 {
394- tracing:: debug!( "Unable to send error to listener: {}" , e . into_send_error ( ) )
354+ tracing:: debug!( "Unable to send error to dialer" )
395355 }
396356 self . reservation . failed ( ) ;
397357 continue ;
@@ -499,27 +459,24 @@ impl ConnectionHandler for Handler {
499459 ) ;
500460 match pending_request {
501461 PendingRequest :: Reserve { to_listener } => {
502- self . active_reserve_requests . push_back ( to_listener) ;
503462 if self
504463 . inflight_reserve_requests
505- . try_push ( outbound_hop:: make_reservation ( stream) )
464+ . try_push ( outbound_hop:: make_reservation ( stream) , to_listener )
506465 . is_err ( )
507466 {
508- tracing:: warn!( "Dropping outbound stream because we are at capacity" )
467+ tracing:: warn!( "Dropping outbound stream because we are at capacity" ) ;
509468 }
510469 }
511470 PendingRequest :: Connect {
512471 dst_peer_id,
513472 to_dial : send_back,
514473 } => {
515- self . active_connect_requests . push_back ( send_back) ;
516-
517474 if self
518475 . inflight_outbound_connect_requests
519- . try_push ( outbound_hop:: open_circuit ( stream, dst_peer_id) )
476+ . try_push ( outbound_hop:: open_circuit ( stream, dst_peer_id) , send_back )
520477 . is_err ( )
521478 {
522- tracing:: warn!( "Dropping outbound stream because we are at capacity" )
479+ tracing:: warn!( "Dropping outbound stream because we are at capacity" ) ;
523480 }
524481 }
525482 }
0 commit comments