@@ -29,8 +29,8 @@ use std::{
29
29
time:: Duration ,
30
30
} ;
31
31
32
- use futures:: StreamExt ;
33
- use futures_ticker :: Ticker ;
32
+ use futures:: FutureExt ;
33
+ use futures_timer :: Delay ;
34
34
use prometheus_client:: registry:: Registry ;
35
35
use rand:: { seq:: SliceRandom , thread_rng} ;
36
36
@@ -283,7 +283,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
283
283
mcache : MessageCache ,
284
284
285
285
/// Heartbeat interval stream.
286
- heartbeat : Ticker ,
286
+ heartbeat : Delay ,
287
287
288
288
/// Number of heartbeats since the beginning of time; this allows us to amortize some resource
289
289
/// clean up -- eg backoff clean up.
@@ -301,7 +301,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
301
301
302
302
/// Stores optional peer score data together with thresholds, decay interval and gossip
303
303
/// promises.
304
- peer_score : Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
304
+ peer_score : Option < ( PeerScore , PeerScoreThresholds , Delay , GossipPromises ) > ,
305
305
306
306
/// Counts the number of `IHAVE` received from each peer since the last heartbeat.
307
307
count_received_ihave : HashMap < PeerId , usize > ,
@@ -448,10 +448,7 @@ where
448
448
config. backoff_slack ( ) ,
449
449
) ,
450
450
mcache : MessageCache :: new ( config. history_gossip ( ) , config. history_length ( ) ) ,
451
- heartbeat : Ticker :: new_with_next (
452
- config. heartbeat_interval ( ) ,
453
- config. heartbeat_initial_delay ( ) ,
454
- ) ,
451
+ heartbeat : Delay :: new ( config. heartbeat_interval ( ) + config. heartbeat_initial_delay ( ) ) ,
455
452
heartbeat_ticks : 0 ,
456
453
px_peers : HashSet :: new ( ) ,
457
454
outbound_peers : HashSet :: new ( ) ,
@@ -879,7 +876,7 @@ where
879
876
return Err ( "Peer score set twice" . into ( ) ) ;
880
877
}
881
878
882
- let interval = Ticker :: new ( params. decay_interval ) ;
879
+ let interval = Delay :: new ( params. decay_interval ) ;
883
880
let peer_score = PeerScore :: new_with_message_delivery_time_callback ( params, callback) ;
884
881
self . peer_score = Some ( ( peer_score, threshold, interval, GossipPromises :: default ( ) ) ) ;
885
882
Ok ( ( ) )
@@ -1145,7 +1142,7 @@ where
1145
1142
}
1146
1143
1147
1144
fn score_below_threshold_from_scores (
1148
- peer_score : & Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
1145
+ peer_score : & Option < ( PeerScore , PeerScoreThresholds , Delay , GossipPromises ) > ,
1149
1146
peer_id : & PeerId ,
1150
1147
threshold : impl Fn ( & PeerScoreThresholds ) -> f64 ,
1151
1148
) -> ( bool , f64 ) {
@@ -3105,14 +3102,16 @@ where
3105
3102
}
3106
3103
3107
3104
// update scores
3108
- if let Some ( ( peer_score, _, interval , _) ) = & mut self . peer_score {
3109
- while let Poll :: Ready ( Some ( _ ) ) = interval . poll_next_unpin ( cx ) {
3105
+ if let Some ( ( peer_score, _, delay , _) ) = & mut self . peer_score {
3106
+ if delay . poll_unpin ( cx ) . is_ready ( ) {
3110
3107
peer_score. refresh_scores ( ) ;
3108
+ delay. reset ( peer_score. params . decay_interval ) ;
3111
3109
}
3112
3110
}
3113
3111
3114
- while let Poll :: Ready ( Some ( _ ) ) = self . heartbeat . poll_next_unpin ( cx) {
3112
+ if self . heartbeat . poll_unpin ( cx) . is_ready ( ) {
3115
3113
self . heartbeat ( ) ;
3114
+ self . heartbeat . reset ( self . config . heartbeat_interval ( ) ) ;
3116
3115
}
3117
3116
3118
3117
Poll :: Pending
0 commit comments