@@ -30,10 +30,12 @@ use std::{
3030} ;
3131
3232use futures:: StreamExt ;
33+ use futures_ticker:: Ticker ;
3334use log:: { debug, error, trace, warn} ;
3435use prometheus_client:: registry:: Registry ;
3536use rand:: { seq:: SliceRandom , thread_rng} ;
3637
38+ use instant:: Instant ;
3739use libp2p_core:: { multiaddr:: Protocol :: Ip4 , multiaddr:: Protocol :: Ip6 , Endpoint , Multiaddr } ;
3840use libp2p_identity:: Keypair ;
3941use libp2p_identity:: PeerId ;
@@ -43,7 +45,6 @@ use libp2p_swarm::{
4345 ConnectionDenied , ConnectionId , NetworkBehaviour , NotifyHandler , PollParameters , THandler ,
4446 THandlerInEvent , THandlerOutEvent , ToSwarm ,
4547} ;
46- use wasm_timer:: Instant ;
4748
4849use crate :: backoff:: BackoffStorage ;
4950use crate :: config:: { Config , ValidationMode } ;
@@ -67,7 +68,6 @@ use crate::{PublishError, SubscriptionError, ValidationError};
6768use instant:: SystemTime ;
6869use quick_protobuf:: { MessageWrite , Writer } ;
6970use std:: { cmp:: Ordering :: Equal , fmt:: Debug } ;
70- use wasm_timer:: Interval ;
7171
7272#[ cfg( test) ]
7373mod tests;
@@ -289,7 +289,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
289289 mcache : MessageCache ,
290290
291291 /// Heartbeat interval stream.
292- heartbeat : Interval ,
292+ heartbeat : Ticker ,
293293
294294 /// Number of heartbeats since the beginning of time; this allows us to amortize some resource
295295 /// clean up -- eg backoff clean up.
@@ -307,7 +307,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
307307
308308 /// Stores optional peer score data together with thresholds, decay interval and gossip
309309 /// promises.
310- peer_score : Option < ( PeerScore , PeerScoreThresholds , Interval , GossipPromises ) > ,
310+ peer_score : Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
311311
312312 /// Counts the number of `IHAVE` received from each peer since the last heartbeat.
313313 count_received_ihave : HashMap < PeerId , usize > ,
@@ -460,9 +460,9 @@ where
460460 config. backoff_slack ( ) ,
461461 ) ,
462462 mcache : MessageCache :: new ( config. history_gossip ( ) , config. history_length ( ) ) ,
463- heartbeat : Interval :: new_at (
464- Instant :: now ( ) + config. heartbeat_initial_delay ( ) ,
463+ heartbeat : Ticker :: new_with_next (
465464 config. heartbeat_interval ( ) ,
465+ config. heartbeat_initial_delay ( ) ,
466466 ) ,
467467 heartbeat_ticks : 0 ,
468468 px_peers : HashSet :: new ( ) ,
@@ -908,7 +908,7 @@ where
908908 return Err ( "Peer score set twice" . into ( ) ) ;
909909 }
910910
911- let interval = Interval :: new ( params. decay_interval ) ;
911+ let interval = Ticker :: new ( params. decay_interval ) ;
912912 let peer_score = PeerScore :: new_with_message_delivery_time_callback ( params, callback) ;
913913 self . peer_score = Some ( ( peer_score, threshold, interval, GossipPromises :: default ( ) ) ) ;
914914 Ok ( ( ) )
@@ -1175,7 +1175,7 @@ where
11751175 }
11761176
11771177 fn score_below_threshold_from_scores (
1178- peer_score : & Option < ( PeerScore , PeerScoreThresholds , Interval , GossipPromises ) > ,
1178+ peer_score : & Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
11791179 peer_id : & PeerId ,
11801180 threshold : impl Fn ( & PeerScoreThresholds ) -> f64 ,
11811181 ) -> ( bool , f64 ) {
@@ -3472,12 +3472,12 @@ where
34723472
34733473 // update scores
34743474 if let Some ( ( peer_score, _, interval, _) ) = & mut self . peer_score {
3475- while let Poll :: Ready ( Some ( ( ) ) ) = interval. poll_next_unpin ( cx) {
3475+ while let Poll :: Ready ( Some ( _ ) ) = interval. poll_next_unpin ( cx) {
34763476 peer_score. refresh_scores ( ) ;
34773477 }
34783478 }
34793479
3480- while let Poll :: Ready ( Some ( ( ) ) ) = self . heartbeat . poll_next_unpin ( cx) {
3480+ while let Poll :: Ready ( Some ( _ ) ) = self . heartbeat . poll_next_unpin ( cx) {
34813481 self . heartbeat ( ) ;
34823482 }
34833483
0 commit comments