@@ -271,7 +271,7 @@ class PeerManagerActor(
271
271
handshakedPeer.ref ! PeerActor .DisconnectPeer (Disconnect .Reasons .TooManyPeers )
272
272
273
273
// It looks like all incoming slots are taken; try to make some room.
274
- schedulePruningIncomingPeers()
274
+ self ! SchedulePruneIncomingPeers
275
275
276
276
context become listening(connectedPeers)
277
277
@@ -302,18 +302,18 @@ class PeerManagerActor(
302
302
(pendingPeer, newConnectedPeers)
303
303
}
304
304
305
- /** Ask for statistics and try to prune incoming peers when they arrive. */
306
- private def schedulePruningIncomingPeers (): Unit = {
307
- implicit val timeout : Timeout = Timeout (peerConfiguration.updateNodesInterval)
308
- // Picking the minimum pruning age is fair for anyone
309
- val window = peerConfiguration.minPruneAge
310
- (peerStatistics ? PeerStatisticsActor .GetStatsForAll (window))
311
- .mapTo[PeerStatisticsActor .StatsForAll ]
312
- .map(PruneIncomingPeers (_))
313
- .pipeTo(self)
314
- }
315
-
316
305
private def handlePruning (connectedPeers : ConnectedPeers ): Receive = {
306
+ case SchedulePruneIncomingPeers =>
307
+ implicit val timeout : Timeout = Timeout (peerConfiguration.updateNodesInterval)
308
+
309
+ // Ask for the whole statistics duration, we'll use averages to make it fair.
310
+ val window = peerConfiguration.statSlotCount * peerConfiguration.statSlotDuration
311
+
312
+ (peerStatistics ? PeerStatisticsActor .GetStatsForAll (window))
313
+ .mapTo[PeerStatisticsActor .StatsForAll ]
314
+ .map(PruneIncomingPeers (_))
315
+ .pipeTo(self)
316
+
317
317
case PruneIncomingPeers (PeerStatisticsActor .StatsForAll (stats)) =>
318
318
val prunedConnectedPeers = pruneIncomingPeers(connectedPeers, stats)
319
319
@@ -505,6 +505,7 @@ object PeerManagerActor {
505
505
506
506
case class PeerAddress (value : String ) extends BlackListId
507
507
508
+ case object SchedulePruneIncomingPeers
508
509
case class PruneIncomingPeers (stats : PeerStatisticsActor .StatsForAll )
509
510
510
511
/** Number of new connections the node should try to open at any given time. */
0 commit comments