Skip to content

Commit

Permalink
p2p-governor: minConnectTime computation
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Jan 28, 2021
1 parent e912e5a commit eda86d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Expand Up @@ -80,7 +80,7 @@ invariant EstablishedPeers { establishedReady,
<> (Set.fromList (PSQ.keys nextActivateTimes))
== Map.keysSet establishedStatus

-- there are ony warm peers in 'nextActiveTimes'
-- there are only warm peers in 'nextActiveTimes'
&& all (== PeerWarm)
(Map.filterWithKey
(\peeraddr _ -> PSQ.member peeraddr nextActivateTimes)
Expand Down
Expand Up @@ -92,7 +92,11 @@ belowTarget actions
-- If we could connect except that there are no peers currently available
-- then we return the next wakeup time (if any)
| numEstablishedPeers + numConnectInProgress < targetNumberOfEstablishedPeers
= GuardedSkip (Min <$> KnownPeers.minConnectTime knownPeers)
= GuardedSkip (Min <$> KnownPeers.minConnectTime
(inProgressPromoteCold
`Set.union`
Map.keysSet (EstablishedPeers.toMap establishedPeers))
knownPeers)

| otherwise
= GuardedSkip Nothing
Expand Down
Expand Up @@ -352,12 +352,18 @@ setGossipTime peeraddrs time
-- Tracking when we can (re)connect
--

minConnectTime :: Ord peeraddr => KnownPeers peeraddr -> Maybe Time
minConnectTime KnownPeers {
minConnectTime :: Ord peeraddr
=> Set peeraddr
-- ^ peers that are either established or which we are
-- establishing a connection
-> KnownPeers peeraddr
-> Maybe Time
minConnectTime establishedPeers
KnownPeers {
availableToConnect,
nextConnectTimes
}
| Set.null availableToConnect
| Set.null (availableToConnect Set.\\ establishedPeers)
, Just (_k, t, _, _psq) <- PSQ.minView nextConnectTimes
= Just t

Expand Down

0 comments on commit eda86d3

Please sign in to comment.