Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data LocalRootPeers peeraddr = LocalRootPeers (Map peeraddr LocalRootConfig) [(HotValency, WarmValency, Set peeraddr)]
- data LocalRootConfig = LocalRootConfig {}
- newtype HotValency = HotValency {
- getHotValency :: Int
- newtype WarmValency = WarmValency {}
- type Config peeraddr = [(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
- invariant :: Ord peeraddr => LocalRootPeers peeraddr -> Bool
- empty :: LocalRootPeers peeraddr
- null :: LocalRootPeers peeraddr -> Bool
- size :: LocalRootPeers peeraddr -> Int
- member :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool
- hotTarget :: LocalRootPeers peeraddr -> HotValency
- warmTarget :: LocalRootPeers peeraddr -> WarmValency
- fromGroups :: Ord peeraddr => [(HotValency, WarmValency, Map peeraddr LocalRootConfig)] -> LocalRootPeers peeraddr
- toGroups :: Ord peeraddr => LocalRootPeers peeraddr -> [(HotValency, WarmValency, Map peeraddr LocalRootConfig)]
- toGroupSets :: LocalRootPeers peeraddr -> [(HotValency, WarmValency, Set peeraddr)]
- toMap :: LocalRootPeers peeraddr -> Map peeraddr LocalRootConfig
- keysSet :: LocalRootPeers peeraddr -> Set peeraddr
- trustableKeysSet :: LocalRootPeers peeraddr -> Set peeraddr
- clampToLimit :: Ord peeraddr => Int -> LocalRootPeers peeraddr -> LocalRootPeers peeraddr
- clampToTrustable :: Ord peeraddr => LocalRootPeers peeraddr -> LocalRootPeers peeraddr
- isPeerTrustable :: Ord peeraddr => peeraddr -> LocalRootPeers peeraddr -> Bool
Types
data LocalRootPeers peeraddr Source #
LocalRootPeers (Map peeraddr LocalRootConfig) [(HotValency, WarmValency, Set peeraddr)] |
Instances
(Show peeraddr, Ord peeraddr) => Show (LocalRootPeers peeraddr) Source # | |
Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers showsPrec :: Int -> LocalRootPeers peeraddr -> ShowS # show :: LocalRootPeers peeraddr -> String # showList :: [LocalRootPeers peeraddr] -> ShowS # | |
Eq peeraddr => Eq (LocalRootPeers peeraddr) Source # | |
Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers (==) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool # (/=) :: LocalRootPeers peeraddr -> LocalRootPeers peeraddr -> Bool # |
data LocalRootConfig Source #
Instances
Show LocalRootConfig Source # | |
Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers showsPrec :: Int -> LocalRootConfig -> ShowS # show :: LocalRootConfig -> String # showList :: [LocalRootConfig] -> ShowS # | |
Eq LocalRootConfig Source # | |
Defined in Ouroboros.Network.PeerSelection.State.LocalRootPeers (==) :: LocalRootConfig -> LocalRootConfig -> Bool # (/=) :: LocalRootConfig -> LocalRootConfig -> Bool # |
newtype HotValency Source #
Newtype wrapper representing hot valency value from local root group configuration
Instances
newtype WarmValency Source #
Newtype wrapper representing warm valency value from local root group configuration
Instances
type Config peeraddr = [(HotValency, WarmValency, Map peeraddr LocalRootConfig)] Source #
Data available from topology file.
Basic operations
empty :: LocalRootPeers peeraddr Source #
null :: LocalRootPeers peeraddr -> Bool Source #
size :: LocalRootPeers peeraddr -> Int Source #
hotTarget :: LocalRootPeers peeraddr -> HotValency Source #
warmTarget :: LocalRootPeers peeraddr -> WarmValency Source #
fromGroups :: Ord peeraddr => [(HotValency, WarmValency, Map peeraddr LocalRootConfig)] -> 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 LocalRootConfig)] Source #
Inverse of fromGroups
, for the subset of inputs to fromGroups
that
satisfy the invariant.
toGroupSets :: LocalRootPeers peeraddr -> [(HotValency, WarmValency, Set peeraddr)] Source #
toMap :: LocalRootPeers peeraddr -> Map peeraddr LocalRootConfig Source #
keysSet :: LocalRootPeers peeraddr -> Set peeraddr Source #
trustableKeysSet :: LocalRootPeers peeraddr -> Set peeraddr Source #
Special operations
:: 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 #