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 29, 2024
1 parent 8eba29f commit 8d368c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
20 changes: 9 additions & 11 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSelection.PeerStateActions (PeerConnectionHandle,
PeerSelectionActionsTrace (..), PeerStateActionsArguments (..),
pchPeerSharing, withPeerStateActions)
import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint)
import Ouroboros.Network.PeerSelection.RootPeersDNS
import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSActions (DNSActions,
Expand All @@ -134,8 +133,7 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS.LocalRootPeers
(TraceLocalRootPeers)
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 +244,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 +265,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 +275,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 +289,7 @@ data ArgumentsExtra m = ArgumentsExtra {
--
-- By default it is set to 300 seconds.
--
, daBulkChurnInterval :: DiffTime
, daBulkChurnInterval :: DiffTime
}

--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ import Ouroboros.Network.PeerSelection.LedgerPeers (IsBigLedgerPeer,
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
(LedgerStateJudgement (..), UseLedgerPeers (..))
import Ouroboros.Network.PeerSelection.LocalRootPeers (OutboundConnectionsState)
import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise)
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing)
import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Ouroboros.Network.PeerSelection.PublicRootPeers (PublicRootPeers)
import Ouroboros.Network.PeerSelection.PublicRootPeers qualified as PublicRootPeers
import Ouroboros.Network.PeerSelection.State.EstablishedPeers (EstablishedPeers)
Expand Down Expand Up @@ -318,8 +316,6 @@ sanePeerSelectionTargets PeerSelectionTargets{..} =
&& targetNumberOfKnownBigLedgerPeers <= 10000


-- | Actions performed by the peer selection governor.
--
-- These being pluggable allows:
--
-- * choice of known peer root sets
Expand All @@ -339,10 +335,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Ouroboros.Network.PeerSelection.State.LocalRootPeers
LocalRootPeers (..)
, HotValency (..)
, WarmValency (..)
, Config
-- 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 8d368c7

Please sign in to comment.