ouroboros-network
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.PeerSelection.State.LocalRootPeers

Synopsis

Types

data LocalRootPeers peeraddr Source #

Constructors

LocalRootPeers (Map peeraddr (PeerAdvertise, PeerTrustable)) [(HotValency, WarmValency, Set peeraddr)] 

Instances

Instances details
(Show peeraddr, Ord peeraddr) => Show (LocalRootPeers peeraddr) Source # 
Instance details

Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers

Methods

showsPrec :: Int -> LocalRootPeers peeraddr -> ShowS #

show :: LocalRootPeers peeraddr -> String #

showList :: [LocalRootPeers peeraddr] -> ShowS #

Eq peeraddr => Eq (LocalRootPeers peeraddr) Source # 
Instance details

Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers

Methods

(==) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool #

(/=) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool #

type Config peeraddr = [(HotValency, WarmValency, Map peeraddr (PeerAdvertise, PeerTrustable))] Source #

Data available from topology file.

invariant :: Ord peeraddr => LocalRootPeers peeraddr -> Bool Source #

Basic operations

size :: LocalRootPeers peeraddr -> Int Source #

member :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool Source #

fromGroups :: Ord peeraddr => [(HotValency, WarmValency, Map peeraddr (PeerAdvertise, PeerTrustable))] -> LocalRootPeers peeraddr Source #

The local root peers info has some invariants that are not directly enforced in the types, and the config comes from an external source. Of course it's good to validate that at source, but here we need to not fail if we're given imperfect data.

So what we do is bash it until it is valid. We don't need to be too careful about how we do it, it's ok to be brutal. We should however make sure we trace a warning about dodgy config.

toGroups :: Ord peeraddr => LocalRootPeers peeraddr -> [(HotValency, WarmValency, Map peeraddr (PeerAdvertise, PeerTrustable))] Source #

Inverse of fromGroups, for the subset of inputs to fromGroups that satisfy the invariant.

keysSet :: LocalRootPeers peeraddr -> Set peeraddr Source #

trustableKeysSet :: LocalRootPeers peeraddr -> Set peeraddr Source #

Special operations

clampToLimit Source #

Arguments

:: Ord peeraddr 
=> Int

The limit on the total number of local peers

-> LocalRootPeers peeraddr 
-> LocalRootPeers peeraddr 

Limit the size of the root peers collection to fit within given bounds.

The governor needs to be able to do this to enforce its invariant that:

LocalRootPeers.size localRootPeers <= targetNumberOfKnownPeers

It needs to be able to establish that invariant given arbitrary configuration for local root peers. It makes sense to do it this way rather than just enforce that local root peers config fits the invariant because the invariant depends on both the targets and the local root peers config and these can both vary dynamically and independently.

It is unlikely in practice that there are so many local root peers configured that it goes over this targets, so it's ok to resolve it pretty arbitrarily. We just take the local roots in left to right order up to the limit. So we have the property that

LocalRootPeers.size (LocalRootPeers.clampToLimit sz lrps)
 == min sz (LocalRootPeers.size lrps)

clampToTrustable :: Ord peeraddr => LocalRootPeers peeraddr -> LocalRootPeers peeraddr Source #

isPeerTrustable :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool Source #