{-# LANGUAGE NamedFieldPuns #-}
module Ouroboros.Network.Diffusion.Configuration
( defaultAcceptedConnectionsLimit
, defaultPeerSharing
, defaultBlockFetchConfiguration
, defaultChainSyncTimeout
, defaultDeadlineTargets
, defaultDeadlineChurnInterval
, defaultBulkChurnInterval
, AcceptedConnectionsLimit (..)
, BlockFetchConfiguration (..)
, ChainSyncTimeout (..)
, DiffusionMode (..)
, MiniProtocolParameters (..)
, PeerSelectionTargets (..)
, PeerSharing (..)
, ConsensusMode (..)
, defaultConsensusMode
, defaultMiniProtocolParameters
, deactivateTimeout
, closeConnectionTimeout
, peerMetricsConfiguration
, defaultTimeWaitTimeout
, defaultProtocolIdleTimeout
, defaultResetTimeout
, handshake_QUERY_SHUTDOWN_DELAY
, ps_POLICY_PEER_SHARE_STICKY_TIME
, ps_POLICY_PEER_SHARE_MAX_PEERS
, local_PROTOCOL_IDLE_TIMEOUT
, local_TIME_WAIT_TIMEOUT
) where
import Control.Monad.Class.MonadTime.SI
import System.Random (randomRIO)
import Cardano.Network.ConsensusMode
import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..),
GenesisBlockFetchConfiguration (..))
import Ouroboros.Network.ConnectionManager.Core (defaultProtocolIdleTimeout,
defaultResetTimeout, defaultTimeWaitTimeout)
import Ouroboros.Network.Diffusion.Policies (closeConnectionTimeout,
deactivateTimeout, maxChainSyncTimeout, minChainSyncTimeout,
peerMetricsConfiguration)
import Ouroboros.Network.NodeToNode (DiffusionMode (..),
MiniProtocolParameters (..), defaultMiniProtocolParameters)
import Ouroboros.Network.PeerSelection.Governor.Types
(PeerSelectionTargets (..))
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSharing (ps_POLICY_PEER_SHARE_MAX_PEERS,
ps_POLICY_PEER_SHARE_STICKY_TIME)
import Ouroboros.Network.Protocol.ChainSync.Codec (ChainSyncTimeout (..))
import Ouroboros.Network.Protocol.Handshake (handshake_QUERY_SHUTDOWN_DELAY)
import Ouroboros.Network.Protocol.Limits (shortWait)
import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..))
defaultDeadlineTargets :: PeerSelectionTargets
defaultDeadlineTargets :: PeerSelectionTargets
defaultDeadlineTargets =
PeerSelectionTargets {
targetNumberOfRootPeers :: Int
targetNumberOfRootPeers = Int
60,
targetNumberOfKnownPeers :: Int
targetNumberOfKnownPeers = Int
85,
targetNumberOfEstablishedPeers :: Int
targetNumberOfEstablishedPeers = Int
40,
targetNumberOfActivePeers :: Int
targetNumberOfActivePeers = Int
15,
targetNumberOfKnownBigLedgerPeers :: Int
targetNumberOfKnownBigLedgerPeers = Int
15,
targetNumberOfEstablishedBigLedgerPeers :: Int
targetNumberOfEstablishedBigLedgerPeers = Int
10,
targetNumberOfActiveBigLedgerPeers :: Int
targetNumberOfActiveBigLedgerPeers = Int
5 }
defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit
defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit
defaultAcceptedConnectionsLimit =
AcceptedConnectionsLimit {
acceptedConnectionsHardLimit :: Word32
acceptedConnectionsHardLimit = Word32
512,
acceptedConnectionsSoftLimit :: Word32
acceptedConnectionsSoftLimit = Word32
384,
acceptedConnectionsDelay :: DiffTime
acceptedConnectionsDelay = DiffTime
5 }
defaultPeerSharing :: PeerSharing
defaultPeerSharing :: PeerSharing
defaultPeerSharing = PeerSharing
PeerSharingDisabled
defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration Int
bfcSalt =
BlockFetchConfiguration {
bfcMaxConcurrencyBulkSync :: Word
bfcMaxConcurrencyBulkSync = Word
1,
bfcMaxConcurrencyDeadline :: Word
bfcMaxConcurrencyDeadline = Word
1,
bfcMaxRequestsInflight :: Word
bfcMaxRequestsInflight = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ MiniProtocolParameters -> Word16
blockFetchPipeliningMax MiniProtocolParameters
defaultMiniProtocolParameters,
bfcDecisionLoopIntervalGenesis :: DiffTime
bfcDecisionLoopIntervalGenesis = DiffTime
0.04,
bfcDecisionLoopIntervalPraos :: DiffTime
bfcDecisionLoopIntervalPraos = DiffTime
0.01,
bfcGenesisBFConfig :: GenesisBlockFetchConfiguration
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcGracePeriod :: DiffTime
gbfcGracePeriod = DiffTime
10 },
Int
bfcSalt :: Int
bfcSalt :: Int
bfcSalt }
defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout = do
mustReplyTimeout <- DiffTime -> Maybe DiffTime
forall a. a -> Maybe a
Just (DiffTime -> Maybe DiffTime)
-> (Double -> DiffTime) -> Double -> Maybe DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Double -> Maybe DiffTime) -> IO Double -> IO (Maybe DiffTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Double, Double) -> IO Double
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO ( DiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac DiffTime
minChainSyncTimeout :: Double
, DiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac DiffTime
maxChainSyncTimeout :: Double
)
return ChainSyncTimeout { canAwaitTimeout = shortWait,
intersectTimeout = shortWait,
mustReplyTimeout,
idleTimeout = Just 3673 }
defaultDeadlineChurnInterval :: DiffTime
defaultDeadlineChurnInterval :: DiffTime
defaultDeadlineChurnInterval = DiffTime
3300
defaultBulkChurnInterval :: DiffTime
defaultBulkChurnInterval :: DiffTime
defaultBulkChurnInterval = DiffTime
900
local_PROTOCOL_IDLE_TIMEOUT :: DiffTime
local_PROTOCOL_IDLE_TIMEOUT :: DiffTime
local_PROTOCOL_IDLE_TIMEOUT = DiffTime
2
local_TIME_WAIT_TIMEOUT :: DiffTime
local_TIME_WAIT_TIMEOUT :: DiffTime
local_TIME_WAIT_TIMEOUT = DiffTime
0