@@ -37,7 +37,7 @@ use libp2p_swarm::handler::{
3737 ConnectionEvent , DialUpgradeError , FullyNegotiatedInbound , FullyNegotiatedOutbound ,
3838} ;
3939use libp2p_swarm:: {
40- ConnectionHandler , ConnectionHandlerEvent , ConnectionId , KeepAlive , Stream , StreamProtocol ,
40+ ConnectionHandler , ConnectionHandlerEvent , ConnectionId , Stream , StreamProtocol ,
4141 StreamUpgradeError , SubstreamProtocol ,
4242} ;
4343use std:: collections:: VecDeque ;
@@ -376,10 +376,6 @@ pub struct Handler {
376376 ///
377377 /// Contains a [`futures::future::Future`] for each lend out substream that
378378 /// resolves once the substream is dropped.
379- ///
380- /// Once all substreams are dropped and this handler has no other work,
381- /// [`KeepAlive::Until`] can be set, allowing the connection to be closed
382- /// eventually.
383379 alive_lend_out_substreams : FuturesUnordered < oneshot:: Receiver < ( ) > > ,
384380 /// Futures relaying data for circuit between two peers.
385381 circuits : Futures < ( CircuitId , PeerId , Result < ( ) , std:: io:: Error > ) > ,
@@ -615,13 +611,12 @@ impl ConnectionHandler for Handler {
615611 }
616612 }
617613
618- fn connection_keep_alive ( & self ) -> KeepAlive {
619- match self . idle_at {
620- Some ( idle_at) if Instant :: now ( ) . duration_since ( idle_at) > Duration :: from_secs ( 10 ) => {
621- KeepAlive :: No
622- }
623- _ => KeepAlive :: Yes ,
624- }
614+ fn connection_keep_alive ( & self ) -> bool {
615+ let Some ( idle_at) = self . idle_at else {
616+ return true ;
617+ } ;
618+
619+ Instant :: now ( ) . duration_since ( idle_at) <= Duration :: from_secs ( 10 )
625620 }
626621
627622 fn poll (
@@ -881,13 +876,7 @@ impl ConnectionHandler for Handler {
881876 { }
882877
883878 // Check keep alive status.
884- if self . reservation_request_future . is_none ( )
885- && self . circuit_accept_futures . is_empty ( )
886- && self . circuit_deny_futures . is_empty ( )
887- && self . alive_lend_out_substreams . is_empty ( )
888- && self . circuits . is_empty ( )
889- && self . active_reservation . is_none ( )
890- {
879+ if self . active_reservation . is_none ( ) {
891880 if self . idle_at . is_none ( ) {
892881 self . idle_at = Some ( Instant :: now ( ) ) ;
893882 }
0 commit comments