Skip to content

Commit

Permalink
local-roots: added Config type alias
Browse files Browse the repository at this point in the history
Most changes in P2P module are imposed by `stylish-haskell`.
  • Loading branch information
coot committed Apr 16, 2024
1 parent ac6b542 commit 6ad7807
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
17 changes: 9 additions & 8 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Expand Up @@ -136,6 +136,7 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS.PublicRootPeers
(TracePublicRootPeers)
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency,
WarmValency)
import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers
import Ouroboros.Network.PeerSharing (PeerSharingRegistry (..))
import Ouroboros.Network.RethrowPolicy
import Ouroboros.Network.Server2 (ServerArguments (..), ServerTrace (..))
Expand Down Expand Up @@ -246,17 +247,17 @@ nullTracers =
data ArgumentsExtra m = ArgumentsExtra {
-- | selection targets for the peer governor
--
daPeerSelectionTargets :: PeerSelectionTargets
daPeerSelectionTargets :: PeerSelectionTargets

, daReadLocalRootPeers :: STM m [(HotValency, WarmValency, Map RelayAccessPoint (PeerAdvertise, PeerTrustable))]
, daReadPublicRootPeers :: STM m (Map RelayAccessPoint PeerAdvertise)
, daReadLocalRootPeers :: STM m (LocalRootPeers.Config RelayAccessPoint)
, daReadPublicRootPeers :: STM m (Map RelayAccessPoint PeerAdvertise)
, daReadUseBootstrapPeers :: STM m UseBootstrapPeers

-- | Peer's own PeerSharing value.
--
-- This value comes from the node's configuration file and is static.
, daOwnPeerSharing :: PeerSharing
, daReadUseLedgerPeers :: STM m UseLedgerPeers
, daOwnPeerSharing :: PeerSharing
, daReadUseLedgerPeers :: STM m UseLedgerPeers

-- | Timeout which starts once all responder protocols are idle. If the
-- responders stay idle for duration of the timeout, the connection will
Expand All @@ -267,7 +268,7 @@ data ArgumentsExtra m = ArgumentsExtra {
--
-- See 'serverProtocolIdleTimeout'.
--
, daProtocolIdleTimeout :: DiffTime
, daProtocolIdleTimeout :: DiffTime

-- | Time for which /node-to-node/ connections are kept in
-- 'TerminatingState', it should correspond to the OS configured @TCP@
Expand All @@ -277,7 +278,7 @@ data ArgumentsExtra m = ArgumentsExtra {
-- purpose is to be resilient for delayed packets in the same way @TCP@
-- is using @TIME_WAIT@.
--
, daTimeWaitTimeout :: DiffTime
, daTimeWaitTimeout :: DiffTime

-- | Churn interval between churn events in deadline mode. A small fuzz
-- is added (max 10 minutes) so that not all nodes churn at the same time.
Expand All @@ -291,7 +292,7 @@ data ArgumentsExtra m = ArgumentsExtra {
--
-- By default it is set to 300 seconds.
--
, daBulkChurnInterval :: DiffTime
, daBulkChurnInterval :: DiffTime
}

--
Expand Down
Expand Up @@ -761,10 +761,7 @@ readIsHiddenRelayOrBP
)
=> PeerSelectionInterfaces peeraddr peerconn m
-> UseBootstrapPeers
-> STM m [( LocalRootPeers.HotValency
, LocalRootPeers.WarmValency
, Map peeraddr ( PeerAdvertise
, PeerTrustable))]
-> STM m (LocalRootPeers.Config peeraddr)
-> PeerSelectionTargets
-> PeerSelectionSetsWithSizes peeraddr
-> STM m Bool
Expand Down
Expand Up @@ -317,8 +317,6 @@ sanePeerSelectionTargets PeerSelectionTargets{..} =
&& targetNumberOfKnownBigLedgerPeers <= 10000


-- | Actions performed by the peer selection governor.
--
-- These being pluggable allows:
--
-- * choice of known peer root sets
Expand All @@ -338,10 +336,7 @@ data PeerSelectionActions peeraddr peerconn m = PeerSelectionActions {
-- It is structured as a collection of (non-overlapping) groups of peers
-- where we are supposed to select n from each group.
--
readLocalRootPeers :: STM m [( HotValency
, WarmValency
, Map peeraddr ( PeerAdvertise
, PeerTrustable))],
readLocalRootPeers :: STM m (LocalRootPeers.Config peeraddr),

readNewInboundConnection :: STM m (peeraddr, PeerSharing),

Expand Down
Expand Up @@ -38,26 +38,19 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSSemaphore (DNSSemaphore,
newDNSLocalRootSemaphore, withDNSSemaphore)
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency,
WarmValency)
import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRootPeers

data TraceLocalRootPeers peerAddr exception =
TraceLocalRootDomains [( HotValency
, WarmValency
, Map RelayAccessPoint (PeerAdvertise, PeerTrustable))]
TraceLocalRootDomains (LocalRootPeers.Config RelayAccessPoint)
-- ^ 'Int' is the configured valency for the local producer groups
| TraceLocalRootWaiting DomainAccessPoint DiffTime
| TraceLocalRootResult DomainAccessPoint [(IP, DNS.TTL)]
| TraceLocalRootGroups [( HotValency
, WarmValency
, Map peerAddr (PeerAdvertise, PeerTrustable))]
| TraceLocalRootGroups (LocalRootPeers.Config peeraddr)
-- ^ This traces the results of the local root peer provider
| TraceLocalRootDNSMap (Map DomainAccessPoint [peerAddr])
-- ^ This traces the results of the domain name resolution
| TraceLocalRootReconfigured [( HotValency
, WarmValency
, Map RelayAccessPoint (PeerAdvertise, PeerTrustable))] -- ^ Old value
[( HotValency
, WarmValency
, Map RelayAccessPoint (PeerAdvertise, PeerTrustable))] -- ^ New value
| TraceLocalRootReconfigured (LocalRootPeers.Config RelayAccessPoint) -- ^ Old value
(LocalRootPeers.Config RelayAccessPoint) -- ^ New value
| TraceLocalRootFailure DomainAccessPoint (DNSorIOError exception)
--TODO: classify DNS errors, config error vs transitory
| TraceLocalRootError DomainAccessPoint SomeException
Expand Down
Expand Up @@ -9,6 +9,7 @@ module Ouroboros.Network.PeerSelection.State.LocalRootPeers
LocalRootPeers (..)
, HotValency (..)
, WarmValency (..)
, LocalRootsConfig
-- Export constructors for defining tests.
, invariant
-- * Basic operations
Expand Down Expand Up @@ -72,6 +73,12 @@ newtype WarmValency = WarmValency { getWarmValency :: Int }
deriving (Show, Eq, Ord)
deriving Num via Int

-- | Data available from topology file.
--
type Config peeraddr =
[(HotValency, WarmValency, Map peeraddr ( PeerAdvertise, PeerTrustable))]


-- It is an abstract type, so the derived Show is unhelpful, e.g. for replaying
-- test cases.
--
Expand Down

0 comments on commit 6ad7807

Please sign in to comment.