{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Network.NodeToNode
( nodeToNodeProtocols
, NodeToNodeProtocols (..)
, NodeToNodeProtocolsWithExpandedCtx
, NodeToNodeProtocolsWithMinimalCtx
, MiniProtocolParameters (..)
, chainSyncProtocolLimits
, blockFetchProtocolLimits
, txSubmissionProtocolLimits
, keepAliveProtocolLimits
, defaultMiniProtocolParameters
, NodeToNodeVersion (..)
, NodeToNodeVersionData (..)
, NetworkConnectTracers (..)
, nullNetworkConnectTracers
, connectTo
, NetworkServerTracers (..)
, nullNetworkServerTracers
, NetworkMutableState (..)
, AcceptedConnectionsLimit (..)
, newNetworkMutableState
, newNetworkMutableStateSTM
, cleanNetworkMutableState
, withServer
, PeerAdvertise (..)
, PeerSelectionTargets (..)
, IPSubscriptionTarget (..)
, NetworkIPSubscriptionTracers
, NetworkSubscriptionTracers (..)
, nullNetworkSubscriptionTracers
, SubscriptionParams (..)
, IPSubscriptionParams
, ipSubscriptionWorker
, DnsSubscriptionTarget (..)
, DnsSubscriptionParams
, NetworkDNSSubscriptionTracers (..)
, nullNetworkDNSSubscriptionTracers
, dnsSubscriptionWorker
, Versions (..)
, DiffusionMode (..)
, simpleSingletonVersions
, foldMapVersions
, combineVersions
, nodeToNodeHandshakeCodec
, nodeToNodeVersionCodec
, nodeToNodeCodecCBORTerm
, ExpandedInitiatorContext (..)
, MinimalInitiatorContext (..)
, ResponderContext (..)
, ConnectionId (..)
, ControlMessage (..)
, ControlMessageSTM
, RemoteAddress
, RemoteConnectionId
, IsBigLedgerPeer (..)
, NumTxIdsToAck (..)
, ProtocolLimitFailure
, Handshake
, LocalAddresses (..)
, Socket
, ExceptionInHandler (..)
, ErrorPolicies (..)
, remoteNetworkErrorPolicy
, localNetworkErrorPolicy
, nullErrorPolicies
, ErrorPolicy (..)
, SuspendDecision (..)
, AcceptConnectionsPolicyTrace (..)
, TraceSendRecv (..)
, SubscriptionTrace (..)
, DnsTrace (..)
, ErrorPolicyTrace (..)
, WithIPList (..)
, WithDomainName (..)
, WithAddr (..)
, HandshakeTr
, chainSyncMiniProtocolNum
, blockFetchMiniProtocolNum
, txSubmissionMiniProtocolNum
, keepAliveMiniProtocolNum
, peerSharingMiniProtocolNum
) where
import Control.Concurrent.Async qualified as Async
import Control.Exception (IOException, SomeException)
import Control.Monad.Class.MonadTime.SI (DiffTime)
import Codec.CBOR.Read qualified as CBOR
import Codec.CBOR.Term qualified as CBOR
import Data.ByteString.Lazy qualified as BL
import Data.Functor (void)
import Data.Void (Void)
import Data.Word
import Network.Mux qualified as Mx
import Network.Socket (Socket, StructLinger (..))
import Network.Socket qualified as Socket
import Ouroboros.Network.BlockFetch.Client (BlockFetchProtocolFailure)
import Ouroboros.Network.ConnectionManager.Types (ExceptionInHandler (..))
import Ouroboros.Network.Context
import Ouroboros.Network.ControlMessage (ControlMessage (..))
import Ouroboros.Network.Driver (TraceSendRecv (..))
import Ouroboros.Network.Driver.Limits (ProtocolLimitFailure (..))
import Ouroboros.Network.Driver.Simple (DecoderFailure)
import Ouroboros.Network.ErrorPolicy
import Ouroboros.Network.IOManager
import Ouroboros.Network.Mux
import Ouroboros.Network.NodeToNode.Version
import Ouroboros.Network.PeerSelection.Governor.Types
(PeerSelectionTargets (..))
import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (..))
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.Protocol.Handshake.Codec
import Ouroboros.Network.Protocol.Handshake.Type
import Ouroboros.Network.Protocol.Handshake.Version hiding (Accept)
import Ouroboros.Network.Protocol.TxSubmission2.Type (NumTxIdsToAck (..))
import Ouroboros.Network.Snocket
import Ouroboros.Network.Socket
import Ouroboros.Network.Subscription.Dns (DnsSubscriptionParams,
DnsSubscriptionTarget (..), DnsTrace (..), WithDomainName (..))
import Ouroboros.Network.Subscription.Dns qualified as Subscription
import Ouroboros.Network.Subscription.Ip (IPSubscriptionParams,
IPSubscriptionTarget (..), SubscriptionParams (..),
SubscriptionTrace (..), WithIPList (..))
import Ouroboros.Network.Subscription.Ip qualified as Subscription
import Ouroboros.Network.Subscription.Worker (LocalAddresses (..),
SubscriberError)
import Ouroboros.Network.Tracers
import Ouroboros.Network.TxSubmission.Inbound qualified as TxInbound
import Ouroboros.Network.TxSubmission.Outbound qualified as TxOutbound
import Ouroboros.Network.Util.ShowProxy (ShowProxy, showProxy)
type HandshakeTr ntnAddr ntnVersion =
Mx.WithBearer (ConnectionId ntnAddr)
(TraceSendRecv (Handshake ntnVersion CBOR.Term))
data NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b = NodeToNodeProtocols {
forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
chainSyncProtocol :: RunMiniProtocol appType initiatorCtx responderCtx bytes m a b,
forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
blockFetchProtocol :: RunMiniProtocol appType initiatorCtx responderCtx bytes m a b,
forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
txSubmissionProtocol :: RunMiniProtocol appType initiatorCtx responderCtx bytes m a b,
forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
keepAliveProtocol :: RunMiniProtocol appType initiatorCtx responderCtx bytes m a b,
forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
peerSharingProtocol :: RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
}
type NodeToNodeProtocolsWithExpandedCtx appType ntnAddr bytes m a b =
NodeToNodeProtocols appType (ExpandedInitiatorContext ntnAddr m) (ResponderContext ntnAddr) bytes m a b
type NodeToNodeProtocolsWithMinimalCtx appType ntnAddr bytes m a b =
NodeToNodeProtocols appType (MinimalInitiatorContext ntnAddr) (ResponderContext ntnAddr) bytes m a b
data MiniProtocolParameters = MiniProtocolParameters {
MiniProtocolParameters -> Word16
chainSyncPipeliningHighMark :: !Word16,
MiniProtocolParameters -> Word16
chainSyncPipeliningLowMark :: !Word16,
MiniProtocolParameters -> Word16
blockFetchPipeliningMax :: !Word16,
MiniProtocolParameters -> NumTxIdsToAck
txSubmissionMaxUnacked :: !NumTxIdsToAck
}
defaultMiniProtocolParameters :: MiniProtocolParameters
defaultMiniProtocolParameters :: MiniProtocolParameters
defaultMiniProtocolParameters = MiniProtocolParameters {
chainSyncPipeliningLowMark :: Word16
chainSyncPipeliningLowMark = Word16
200
, chainSyncPipeliningHighMark :: Word16
chainSyncPipeliningHighMark = Word16
300
, blockFetchPipeliningMax :: Word16
blockFetchPipeliningMax = Word16
100
, txSubmissionMaxUnacked :: NumTxIdsToAck
txSubmissionMaxUnacked = NumTxIdsToAck
10
}
nodeToNodeProtocols
:: MiniProtocolParameters
-> NodeToNodeProtocols muxMode initiatorCtx responderCtx bytes m a b
-> NodeToNodeVersion
-> PeerSharing
-> OuroborosBundle muxMode initiatorCtx responderCtx bytes m a b
nodeToNodeProtocols :: forall (muxMode :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
MiniProtocolParameters
-> NodeToNodeProtocols
muxMode initiatorCtx responderCtx bytes m a b
-> NodeToNodeVersion
-> PeerSharing
-> OuroborosBundle muxMode initiatorCtx responderCtx bytes m a b
nodeToNodeProtocols MiniProtocolParameters
miniProtocolParameters NodeToNodeProtocols muxMode initiatorCtx responderCtx bytes m a b
protocols NodeToNodeVersion
_version PeerSharing
ownPeerSharing =
WithProtocolTemperature
'Hot [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Warm [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Established
[MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> TemperatureBundle
[MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a.
WithProtocolTemperature 'Hot a
-> WithProtocolTemperature 'Warm a
-> WithProtocolTemperature 'Established a
-> TemperatureBundle a
TemperatureBundle
([MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Hot [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a. a -> WithProtocolTemperature 'Hot a
WithHot ([MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Hot [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b])
-> [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Hot [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a b. (a -> b) -> a -> b
$
case NodeToNodeProtocols muxMode initiatorCtx responderCtx bytes m a b
protocols of
NodeToNodeProtocols { RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
chainSyncProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
chainSyncProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
chainSyncProtocol,
RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
blockFetchProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
blockFetchProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
blockFetchProtocol,
RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
txSubmissionProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
txSubmissionProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
txSubmissionProtocol
} ->
[ MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
chainSyncMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
chainSyncProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
chainSyncProtocol
}
, MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
blockFetchMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
blockFetchProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
blockFetchProtocol
}
, MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
txSubmissionMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
txSubmissionProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
txSubmissionProtocol
}
])
([MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Warm [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a. a -> WithProtocolTemperature 'Warm a
WithWarm [])
([MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Established
[MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a. a -> WithProtocolTemperature 'Established a
WithEstablished ([MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Established
[MiniProtocol muxMode initiatorCtx responderCtx bytes m a b])
-> [MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Established
[MiniProtocol muxMode initiatorCtx responderCtx bytes m a b]
forall a b. (a -> b) -> a -> b
$
case NodeToNodeProtocols muxMode initiatorCtx responderCtx bytes m a b
protocols of
NodeToNodeProtocols { RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
keepAliveProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol, RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
peerSharingProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
peerSharingProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
peerSharingProtocol }
| PeerSharing
ownPeerSharing PeerSharing -> PeerSharing -> Bool
forall a. Eq a => a -> a -> Bool
/= PeerSharing
PeerSharingDisabled ->
[ MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
keepAliveMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
keepAliveProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol
}
, MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
peerSharingMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
peerSharingProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
peerSharingProtocol
}
]
NodeToNodeProtocols { RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol :: forall (appType :: Mode) initiatorCtx responderCtx bytes
(m :: * -> *) a b.
NodeToNodeProtocols appType initiatorCtx responderCtx bytes m a b
-> RunMiniProtocol appType initiatorCtx responderCtx bytes m a b
keepAliveProtocol :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol }
| Bool
otherwise ->
[ MiniProtocol {
miniProtocolNum :: MiniProtocolNum
miniProtocolNum = MiniProtocolNum
keepAliveMiniProtocolNum,
miniProtocolLimits :: MiniProtocolLimits
miniProtocolLimits = MiniProtocolParameters -> MiniProtocolLimits
keepAliveProtocolLimits MiniProtocolParameters
miniProtocolParameters,
miniProtocolRun :: RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
miniProtocolRun = RunMiniProtocol muxMode initiatorCtx responderCtx bytes m a b
keepAliveProtocol
}
])
addSafetyMargin :: Int -> Int
addSafetyMargin :: Int -> Int
addSafetyMargin Int
x = Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
10
chainSyncProtocolLimits
, blockFetchProtocolLimits
, txSubmissionProtocolLimits
, keepAliveProtocolLimits
, peerSharingProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
chainSyncProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
chainSyncProtocolLimits MiniProtocolParameters { Word16
chainSyncPipeliningHighMark :: MiniProtocolParameters -> Word16
chainSyncPipeliningHighMark :: Word16
chainSyncPipeliningHighMark } =
MiniProtocolLimits {
maximumIngressQueue :: Int
maximumIngressQueue = Int -> Int
addSafetyMargin (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$
Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
chainSyncPipeliningHighMark Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1400
}
blockFetchProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
blockFetchProtocolLimits MiniProtocolParameters { Word16
blockFetchPipeliningMax :: MiniProtocolParameters -> Word16
blockFetchPipeliningMax :: Word16
blockFetchPipeliningMax } = MiniProtocolLimits {
maximumIngressQueue :: Int
maximumIngressQueue = Int -> Int
addSafetyMargin (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$
Int -> Int -> Int
forall a. Ord a => a -> a -> a
max (Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2_097_154 :: Int) (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
blockFetchPipeliningMax Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
90_112)
}
txSubmissionProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
txSubmissionProtocolLimits MiniProtocolParameters { NumTxIdsToAck
txSubmissionMaxUnacked :: MiniProtocolParameters -> NumTxIdsToAck
txSubmissionMaxUnacked :: NumTxIdsToAck
txSubmissionMaxUnacked } = MiniProtocolLimits {
maximumIngressQueue :: Int
maximumIngressQueue = Int -> Int
addSafetyMargin (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$
NumTxIdsToAck -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumTxIdsToAck
txSubmissionMaxUnacked Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
44 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
65_540)
}
keepAliveProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
keepAliveProtocolLimits MiniProtocolParameters
_ =
MiniProtocolLimits {
maximumIngressQueue :: Int
maximumIngressQueue = Int -> Int
addSafetyMargin Int
1280
}
peerSharingProtocolLimits :: MiniProtocolParameters -> MiniProtocolLimits
peerSharingProtocolLimits MiniProtocolParameters
_ =
MiniProtocolLimits {
maximumIngressQueue :: Int
maximumIngressQueue = Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1440
}
chainSyncMiniProtocolNum :: MiniProtocolNum
chainSyncMiniProtocolNum :: MiniProtocolNum
chainSyncMiniProtocolNum = Word16 -> MiniProtocolNum
MiniProtocolNum Word16
2
blockFetchMiniProtocolNum :: MiniProtocolNum
blockFetchMiniProtocolNum :: MiniProtocolNum
blockFetchMiniProtocolNum = Word16 -> MiniProtocolNum
MiniProtocolNum Word16
3
txSubmissionMiniProtocolNum :: MiniProtocolNum
txSubmissionMiniProtocolNum :: MiniProtocolNum
txSubmissionMiniProtocolNum = Word16 -> MiniProtocolNum
MiniProtocolNum Word16
4
keepAliveMiniProtocolNum :: MiniProtocolNum
keepAliveMiniProtocolNum :: MiniProtocolNum
keepAliveMiniProtocolNum = Word16 -> MiniProtocolNum
MiniProtocolNum Word16
8
peerSharingMiniProtocolNum :: MiniProtocolNum
peerSharingMiniProtocolNum :: MiniProtocolNum
peerSharingMiniProtocolNum = Word16 -> MiniProtocolNum
MiniProtocolNum Word16
10
connectTo
:: Snocket IO Socket.Socket Socket.SockAddr
-> NetworkConnectTracers Socket.SockAddr NodeToNodeVersion
-> Versions NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
Mx.InitiatorMode Socket.SockAddr BL.ByteString IO a b)
-> Maybe Socket.SockAddr
-> Socket.SockAddr
-> IO (Either SomeException (Either a b))
connectTo :: forall a b.
Snocket IO Socket SockAddr
-> NetworkConnectTracers SockAddr NodeToNodeVersion
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'InitiatorMode SockAddr ByteString IO a b)
-> Maybe SockAddr
-> SockAddr
-> IO (Either SomeException (Either a b))
connectTo Snocket IO Socket SockAddr
sn NetworkConnectTracers SockAddr NodeToNodeVersion
tr =
Snocket IO Socket SockAddr
-> MakeBearer IO Socket
-> ConnectToArgs
Socket SockAddr NodeToNodeVersion NodeToNodeVersionData
-> (Socket -> IO ())
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'InitiatorMode SockAddr ByteString IO a b)
-> Maybe SockAddr
-> SockAddr
-> IO (Either SomeException (Either a b))
forall (muxMode :: Mode) vNumber vData fd addr a b.
(Ord vNumber, Typeable vNumber, Show vNumber,
HasInitiator muxMode ~ 'True) =>
Snocket IO fd addr
-> MakeBearer IO fd
-> ConnectToArgs fd addr vNumber vData
-> (fd -> IO ())
-> Versions
vNumber
vData
(OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)
-> Maybe addr
-> addr
-> IO (Either SomeException (Either a b))
connectToNode Snocket IO Socket SockAddr
sn MakeBearer IO Socket
makeSocketBearer
ConnectToArgs {
ctaHandshakeCodec :: Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
ctaHandshakeCodec = Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
forall (m :: * -> *).
MonadST m =>
Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure m ByteString
nodeToNodeHandshakeCodec,
ctaHandshakeTimeLimits :: ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
ctaHandshakeTimeLimits = ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
forall {k} (vNumber :: k).
ProtocolTimeLimits (Handshake vNumber Term)
timeLimitsHandshake,
ctaVersionDataCodec :: VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
ctaVersionDataCodec = (NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData)
-> VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
forall vNumber vData.
(vNumber -> CodecCBORTerm Text vData)
-> VersionDataCodec Term vNumber vData
cborTermVersionDataCodec NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm,
ctaConnectTracers :: NetworkConnectTracers SockAddr NodeToNodeVersion
ctaConnectTracers = NetworkConnectTracers SockAddr NodeToNodeVersion
tr,
ctaHandshakeCallbacks :: HandshakeCallbacks NodeToNodeVersionData
ctaHandshakeCallbacks = (NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData)
-> (NodeToNodeVersionData -> Bool)
-> HandshakeCallbacks NodeToNodeVersionData
forall vData.
(vData -> vData -> Accept vData)
-> (vData -> Bool) -> HandshakeCallbacks vData
HandshakeCallbacks NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData
forall v. Acceptable v => v -> v -> Accept v
acceptableVersion NodeToNodeVersionData -> Bool
forall v. Queryable v => v -> Bool
queryVersion
}
Socket -> IO ()
configureOutboundSocket
where
configureOutboundSocket :: Socket -> IO ()
configureOutboundSocket :: Socket -> IO ()
configureOutboundSocket Socket
sock = do
Socket -> SocketOption -> Int -> IO ()
Socket.setSocketOption Socket
sock SocketOption
Socket.NoDelay Int
1
Socket -> SocketOption -> StructLinger -> IO ()
forall a. Storable a => Socket -> SocketOption -> a -> IO ()
Socket.setSockOpt Socket
sock SocketOption
Socket.Linger
(StructLinger { sl_onoff :: CInt
sl_onoff = CInt
1,
sl_linger :: CInt
sl_linger = CInt
0 })
withServer
:: SocketSnocket
-> NetworkServerTracers Socket.SockAddr NodeToNodeVersion
-> NetworkMutableState Socket.SockAddr
-> AcceptedConnectionsLimit
-> Socket.Socket
-> Versions NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
Mx.ResponderMode Socket.SockAddr BL.ByteString IO a b)
-> ErrorPolicies
-> IO Void
withServer :: forall a b.
Snocket IO Socket SockAddr
-> NetworkServerTracers SockAddr NodeToNodeVersion
-> NetworkMutableState SockAddr
-> AcceptedConnectionsLimit
-> Socket
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b)
-> ErrorPolicies
-> IO IOManagerError
withServer Snocket IO Socket SockAddr
sn NetworkServerTracers SockAddr NodeToNodeVersion
tracers NetworkMutableState SockAddr
networkState AcceptedConnectionsLimit
acceptedConnectionsLimit Socket
sd Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b)
versions ErrorPolicies
errPolicies =
Snocket IO Socket SockAddr
-> MakeBearer IO Socket
-> NetworkServerTracers SockAddr NodeToNodeVersion
-> NetworkMutableState SockAddr
-> AcceptedConnectionsLimit
-> Socket
-> Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
-> ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
-> VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
-> HandshakeCallbacks NodeToNodeVersionData
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(SomeResponderApplication SockAddr ByteString IO b)
-> ErrorPolicies
-> (SockAddr -> Async IOManagerError -> IO IOManagerError)
-> IO IOManagerError
forall vNumber vData t fd addr b.
(Ord vNumber, Typeable vNumber, Show vNumber, Ord addr) =>
Snocket IO fd addr
-> MakeBearer IO fd
-> NetworkServerTracers addr vNumber
-> NetworkMutableState addr
-> AcceptedConnectionsLimit
-> fd
-> Codec (Handshake vNumber Term) DeserialiseFailure IO ByteString
-> ProtocolTimeLimits (Handshake vNumber Term)
-> VersionDataCodec Term vNumber vData
-> HandshakeCallbacks vData
-> Versions
vNumber vData (SomeResponderApplication addr ByteString IO b)
-> ErrorPolicies
-> (addr -> Async IOManagerError -> IO t)
-> IO t
withServerNode'
Snocket IO Socket SockAddr
sn
MakeBearer IO Socket
makeSocketBearer
NetworkServerTracers SockAddr NodeToNodeVersion
tracers
NetworkMutableState SockAddr
networkState
AcceptedConnectionsLimit
acceptedConnectionsLimit
Socket
sd
Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
forall (m :: * -> *).
MonadST m =>
Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure m ByteString
nodeToNodeHandshakeCodec
ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
forall {k} (vNumber :: k).
ProtocolTimeLimits (Handshake vNumber Term)
timeLimitsHandshake
((NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData)
-> VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
forall vNumber vData.
(vNumber -> CodecCBORTerm Text vData)
-> VersionDataCodec Term vNumber vData
cborTermVersionDataCodec NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm)
((NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData)
-> (NodeToNodeVersionData -> Bool)
-> HandshakeCallbacks NodeToNodeVersionData
forall vData.
(vData -> vData -> Accept vData)
-> (vData -> Bool) -> HandshakeCallbacks vData
HandshakeCallbacks NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData
forall v. Acceptable v => v -> v -> Accept v
acceptableVersion NodeToNodeVersionData -> Bool
forall v. Queryable v => v -> Bool
queryVersion)
(OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b
-> SomeResponderApplication SockAddr ByteString IO b
forall (muxMode :: Mode) addr bytes (m :: * -> *) a b.
(HasResponder muxMode ~ 'True) =>
OuroborosApplicationWithMinimalCtx muxMode addr bytes m a b
-> SomeResponderApplication addr bytes m b
SomeResponderApplication (OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b
-> SomeResponderApplication SockAddr ByteString IO b)
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b)
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(SomeResponderApplication SockAddr ByteString IO b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
'ResponderMode SockAddr ByteString IO a b)
versions)
ErrorPolicies
errPolicies
(\SockAddr
_ Async IOManagerError
async -> Async IOManagerError -> IO IOManagerError
forall a. Async a -> IO a
Async.wait Async IOManagerError
async)
ipSubscriptionWorker
:: forall mode x y.
( HasInitiator mode ~ True )
=> SocketSnocket
-> NetworkIPSubscriptionTracers Socket.SockAddr NodeToNodeVersion
-> NetworkMutableState Socket.SockAddr
-> IPSubscriptionParams ()
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode Socket.SockAddr BL.ByteString IO x y)
-> IO Void
ipSubscriptionWorker :: forall (mode :: Mode) x y.
(HasInitiator mode ~ 'True) =>
Snocket IO Socket SockAddr
-> NetworkIPSubscriptionTracers SockAddr NodeToNodeVersion
-> NetworkMutableState SockAddr
-> IPSubscriptionParams ()
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
-> IO IOManagerError
ipSubscriptionWorker
Snocket IO Socket SockAddr
sn
NetworkSubscriptionTracers
{ Tracer IO (WithIPList (SubscriptionTrace SockAddr))
nsSubscriptionTracer :: Tracer IO (WithIPList (SubscriptionTrace SockAddr))
nsSubscriptionTracer :: forall (withIPList :: * -> *) addr vNumber.
NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (withIPList (SubscriptionTrace addr))
nsSubscriptionTracer
, Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
nsMuxTracer :: Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
nsMuxTracer :: forall (withIPList :: * -> *) addr vNumber.
NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (WithBearer (ConnectionId addr) Trace)
nsMuxTracer
, Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
nsHandshakeTracer :: Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
nsHandshakeTracer :: forall (withIPList :: * -> *) addr vNumber.
NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer
IO
(WithBearer
(ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
nsHandshakeTracer
, Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
nsErrorPolicyTracer :: Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
nsErrorPolicyTracer :: forall (withIPList :: * -> *) addr vNumber.
NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
nsErrorPolicyTracer
}
NetworkMutableState SockAddr
networkState
IPSubscriptionParams ()
subscriptionParams
Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
versions
= Snocket IO Socket SockAddr
-> Tracer IO (WithIPList (SubscriptionTrace SockAddr))
-> Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
-> NetworkMutableState SockAddr
-> IPSubscriptionParams ()
-> (Socket -> IO ())
-> IO IOManagerError
forall a.
Snocket IO Socket SockAddr
-> Tracer IO (WithIPList (SubscriptionTrace SockAddr))
-> Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
-> NetworkMutableState SockAddr
-> IPSubscriptionParams a
-> (Socket -> IO a)
-> IO IOManagerError
Subscription.ipSubscriptionWorker
Snocket IO Socket SockAddr
sn
Tracer IO (WithIPList (SubscriptionTrace SockAddr))
nsSubscriptionTracer
Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
nsErrorPolicyTracer
NetworkMutableState SockAddr
networkState
IPSubscriptionParams ()
subscriptionParams
(IO (Either SomeException (Either x y)) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Either SomeException (Either x y)) -> IO ())
-> (Socket -> IO (Either SomeException (Either x y)))
-> Socket
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Snocket IO Socket SockAddr
-> MakeBearer IO Socket
-> ConnectToArgs
Socket SockAddr NodeToNodeVersion NodeToNodeVersionData
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
-> Socket
-> IO (Either SomeException (Either x y))
forall (muxMode :: Mode) vNumber vData fd addr a b.
(Ord vNumber, Typeable vNumber, Show vNumber,
HasInitiator muxMode ~ 'True) =>
Snocket IO fd addr
-> MakeBearer IO fd
-> ConnectToArgs fd addr vNumber vData
-> Versions
vNumber
vData
(OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)
-> fd
-> IO (Either SomeException (Either a b))
connectToNode'
Snocket IO Socket SockAddr
sn
MakeBearer IO Socket
makeSocketBearer
ConnectToArgs {
ctaHandshakeCodec :: Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
ctaHandshakeCodec = Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
forall (m :: * -> *).
MonadST m =>
Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure m ByteString
nodeToNodeHandshakeCodec,
ctaHandshakeTimeLimits :: ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
ctaHandshakeTimeLimits = ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
forall {k} (vNumber :: k).
ProtocolTimeLimits (Handshake vNumber Term)
timeLimitsHandshake,
ctaVersionDataCodec :: VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
ctaVersionDataCodec = (NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData)
-> VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
forall vNumber vData.
(vNumber -> CodecCBORTerm Text vData)
-> VersionDataCodec Term vNumber vData
cborTermVersionDataCodec NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm,
ctaConnectTracers :: NetworkConnectTracers SockAddr NodeToNodeVersion
ctaConnectTracers = Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
-> Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
-> NetworkConnectTracers SockAddr NodeToNodeVersion
forall addr vNumber.
Tracer IO (WithBearer (ConnectionId addr) Trace)
-> Tracer
IO
(WithBearer
(ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
-> NetworkConnectTracers addr vNumber
NetworkConnectTracers Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
nsMuxTracer Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
nsHandshakeTracer,
ctaHandshakeCallbacks :: HandshakeCallbacks NodeToNodeVersionData
ctaHandshakeCallbacks = (NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData)
-> (NodeToNodeVersionData -> Bool)
-> HandshakeCallbacks NodeToNodeVersionData
forall vData.
(vData -> vData -> Accept vData)
-> (vData -> Bool) -> HandshakeCallbacks vData
HandshakeCallbacks NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData
forall v. Acceptable v => v -> v -> Accept v
acceptableVersion NodeToNodeVersionData -> Bool
forall v. Queryable v => v -> Bool
queryVersion
}
Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
versions)
dnsSubscriptionWorker
:: forall mode x y.
( HasInitiator mode ~ True )
=> SocketSnocket
-> NetworkDNSSubscriptionTracers NodeToNodeVersion Socket.SockAddr
-> NetworkMutableState Socket.SockAddr
-> DnsSubscriptionParams ()
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode Socket.SockAddr BL.ByteString IO x y)
-> IO Void
dnsSubscriptionWorker :: forall (mode :: Mode) x y.
(HasInitiator mode ~ 'True) =>
Snocket IO Socket SockAddr
-> NetworkDNSSubscriptionTracers NodeToNodeVersion SockAddr
-> NetworkMutableState SockAddr
-> DnsSubscriptionParams ()
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
-> IO IOManagerError
dnsSubscriptionWorker
Snocket IO Socket SockAddr
sn
NetworkDNSSubscriptionTracers
{ Tracer IO (WithDomainName (SubscriptionTrace SockAddr))
ndstSubscriptionTracer :: Tracer IO (WithDomainName (SubscriptionTrace SockAddr))
ndstSubscriptionTracer :: forall vNumber addr.
NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithDomainName (SubscriptionTrace addr))
ndstSubscriptionTracer
, Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer :: Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer :: forall vNumber addr.
NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer
, Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
ndstMuxTracer :: Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
ndstMuxTracer :: forall vNumber addr.
NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithBearer (ConnectionId addr) Trace)
ndstMuxTracer
, Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
ndstHandshakeTracer :: Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
ndstHandshakeTracer :: forall vNumber addr.
NetworkDNSSubscriptionTracers vNumber addr
-> Tracer
IO
(WithBearer
(ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
ndstHandshakeTracer
, Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
ndstErrorPolicyTracer :: Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
ndstErrorPolicyTracer :: forall vNumber addr.
NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
ndstErrorPolicyTracer
}
NetworkMutableState SockAddr
networkState
DnsSubscriptionParams ()
subscriptionParams
Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
versions =
Snocket IO Socket SockAddr
-> Tracer IO (WithDomainName (SubscriptionTrace SockAddr))
-> Tracer IO (WithDomainName DnsTrace)
-> Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
-> NetworkMutableState SockAddr
-> DnsSubscriptionParams ()
-> (Socket -> IO ())
-> IO IOManagerError
forall a.
Snocket IO Socket SockAddr
-> Tracer IO (WithDomainName (SubscriptionTrace SockAddr))
-> Tracer IO (WithDomainName DnsTrace)
-> Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
-> NetworkMutableState SockAddr
-> DnsSubscriptionParams a
-> (Socket -> IO a)
-> IO IOManagerError
Subscription.dnsSubscriptionWorker
Snocket IO Socket SockAddr
sn
Tracer IO (WithDomainName (SubscriptionTrace SockAddr))
ndstSubscriptionTracer
Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer
Tracer IO (WithAddr SockAddr ErrorPolicyTrace)
ndstErrorPolicyTracer
NetworkMutableState SockAddr
networkState
DnsSubscriptionParams ()
subscriptionParams
(IO (Either SomeException (Either x y)) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Either SomeException (Either x y)) -> IO ())
-> (Socket -> IO (Either SomeException (Either x y)))
-> Socket
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Snocket IO Socket SockAddr
-> MakeBearer IO Socket
-> ConnectToArgs
Socket SockAddr NodeToNodeVersion NodeToNodeVersionData
-> Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
-> Socket
-> IO (Either SomeException (Either x y))
forall (muxMode :: Mode) vNumber vData fd addr a b.
(Ord vNumber, Typeable vNumber, Show vNumber,
HasInitiator muxMode ~ 'True) =>
Snocket IO fd addr
-> MakeBearer IO fd
-> ConnectToArgs fd addr vNumber vData
-> Versions
vNumber
vData
(OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)
-> fd
-> IO (Either SomeException (Either a b))
connectToNode'
Snocket IO Socket SockAddr
sn
MakeBearer IO Socket
makeSocketBearer
ConnectToArgs {
ctaHandshakeCodec :: Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
ctaHandshakeCodec = Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure IO ByteString
forall (m :: * -> *).
MonadST m =>
Codec
(Handshake NodeToNodeVersion Term) DeserialiseFailure m ByteString
nodeToNodeHandshakeCodec,
ctaHandshakeTimeLimits :: ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
ctaHandshakeTimeLimits = ProtocolTimeLimits (Handshake NodeToNodeVersion Term)
forall {k} (vNumber :: k).
ProtocolTimeLimits (Handshake vNumber Term)
timeLimitsHandshake,
ctaVersionDataCodec :: VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
ctaVersionDataCodec = (NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData)
-> VersionDataCodec Term NodeToNodeVersion NodeToNodeVersionData
forall vNumber vData.
(vNumber -> CodecCBORTerm Text vData)
-> VersionDataCodec Term vNumber vData
cborTermVersionDataCodec NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm,
ctaConnectTracers :: NetworkConnectTracers SockAddr NodeToNodeVersion
ctaConnectTracers = Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
-> Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
-> NetworkConnectTracers SockAddr NodeToNodeVersion
forall addr vNumber.
Tracer IO (WithBearer (ConnectionId addr) Trace)
-> Tracer
IO
(WithBearer
(ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
-> NetworkConnectTracers addr vNumber
NetworkConnectTracers Tracer IO (WithBearer (ConnectionId SockAddr) Trace)
ndstMuxTracer Tracer
IO
(WithBearer
(ConnectionId SockAddr)
(TraceSendRecv (Handshake NodeToNodeVersion Term)))
ndstHandshakeTracer,
ctaHandshakeCallbacks :: HandshakeCallbacks NodeToNodeVersionData
ctaHandshakeCallbacks = (NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData)
-> (NodeToNodeVersionData -> Bool)
-> HandshakeCallbacks NodeToNodeVersionData
forall vData.
(vData -> vData -> Accept vData)
-> (vData -> Bool) -> HandshakeCallbacks vData
HandshakeCallbacks NodeToNodeVersionData
-> NodeToNodeVersionData -> Accept NodeToNodeVersionData
forall v. Acceptable v => v -> v -> Accept v
acceptableVersion NodeToNodeVersionData -> Bool
forall v. Queryable v => v -> Bool
queryVersion
}
Versions
NodeToNodeVersion
NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx
mode SockAddr ByteString IO x y)
versions)
remoteNetworkErrorPolicy :: ErrorPolicies
remoteNetworkErrorPolicy :: ErrorPolicies
remoteNetworkErrorPolicy = ErrorPolicies {
epAppErrorPolicies :: [ErrorPolicy]
epAppErrorPolicies = [
(HandshakeProtocolError NodeToNodeVersion
-> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((HandshakeProtocolError NodeToNodeVersion
-> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (HandshakeProtocolError NodeToNodeVersion
-> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(HandshakeProtocolError NodeToNodeVersion
_ :: HandshakeProtocolError NodeToNodeVersion)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
misconfiguredPeer
, (DecoderFailure -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((DecoderFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (DecoderFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(DecoderFailure
_ :: DecoderFailure)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
, (ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(ProtocolLimitFailure
msg :: ProtocolLimitFailure)
-> case ProtocolLimitFailure
msg of
ExceededSizeLimit{} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
ExceededTimeLimit{} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> SuspendDecision DiffTime
forall t. t -> SuspendDecision t
SuspendConsumer DiffTime
shortDelay)
, (Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy)
-> (Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \Error
e -> case Error
e of
Mx.UnknownMiniProtocol {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
Mx.IngressQueueOverRun {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
Mx.InitiatorOnly {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
Mx.BearerClosed {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
veryShortDelay DiffTime
shortDelay)
Mx.IOException {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
veryShortDelay DiffTime
shortDelay)
Mx.SDUDecodeError {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
Error
Mx.SDUReadTimeout -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
veryShortDelay DiffTime
shortDelay)
Error
Mx.SDUWriteTimeout -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
veryShortDelay DiffTime
shortDelay)
Mx.Shutdown {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
veryShortDelay DiffTime
shortDelay)
, (RuntimeError -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((RuntimeError -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy)
-> (RuntimeError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(RuntimeError
e :: Mx.RuntimeError)
-> case RuntimeError
e of
Mx.ProtocolAlreadyRunning {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
shortDelay DiffTime
shortDelay)
Mx.UnknownProtocolInternalError {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
forall t. SuspendDecision t
Throw
Mx.BlockedOnCompletionVar {} -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
shortDelay DiffTime
shortDelay)
, (TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(TxSubmissionProtocolError
_ :: TxOutbound.TxSubmissionProtocolError)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
, (TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (TxSubmissionProtocolError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(TxSubmissionProtocolError
_ :: TxInbound.TxSubmissionProtocolError)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
, (BlockFetchProtocolFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((BlockFetchProtocolFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (BlockFetchProtocolFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(BlockFetchProtocolFailure
_ :: BlockFetchProtocolFailure)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
theyBuggyOrEvil
, (IOManagerError -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((IOManagerError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (IOManagerError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(IOManagerError
_ :: IOManagerError)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
forall t. SuspendDecision t
Throw
],
epConErrorPolicies :: [ErrorPolicy]
epConErrorPolicies = [
(IOException -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy ((IOException -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy)
-> (IOException -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(IOException
_ :: IOException) -> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime))
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a b. (a -> b) -> a -> b
$
DiffTime -> SuspendDecision DiffTime
forall t. t -> SuspendDecision t
SuspendConsumer DiffTime
shortDelay
, (IOManagerError -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((IOManagerError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (IOManagerError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(IOManagerError
_ :: IOManagerError)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just SuspendDecision DiffTime
forall t. SuspendDecision t
Throw
, (SubscriberError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((SubscriberError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (SubscriberError -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(SubscriberError
_ :: SubscriberError)
-> SuspendDecision DiffTime -> Maybe (SuspendDecision DiffTime)
forall a. a -> Maybe a
Just (DiffTime -> SuspendDecision DiffTime
forall t. t -> SuspendDecision t
SuspendConsumer DiffTime
veryShortDelay)
]
}
where
theyBuggyOrEvil :: SuspendDecision DiffTime
theyBuggyOrEvil :: SuspendDecision DiffTime
theyBuggyOrEvil = DiffTime -> DiffTime -> SuspendDecision DiffTime
forall t. t -> t -> SuspendDecision t
SuspendPeer DiffTime
defaultDelay DiffTime
defaultDelay
misconfiguredPeer :: SuspendDecision DiffTime
misconfiguredPeer :: SuspendDecision DiffTime
misconfiguredPeer = DiffTime -> SuspendDecision DiffTime
forall t. t -> SuspendDecision t
SuspendConsumer DiffTime
defaultDelay
defaultDelay :: DiffTime
defaultDelay :: DiffTime
defaultDelay = DiffTime
200
shortDelay :: DiffTime
shortDelay :: DiffTime
shortDelay = DiffTime
20
veryShortDelay :: DiffTime
veryShortDelay :: DiffTime
veryShortDelay = DiffTime
1
localNetworkErrorPolicy :: ErrorPolicies
localNetworkErrorPolicy :: ErrorPolicies
localNetworkErrorPolicy = ErrorPolicies {
epAppErrorPolicies :: [ErrorPolicy]
epAppErrorPolicies = [
(ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (ProtocolLimitFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(ProtocolLimitFailure
_ :: ProtocolLimitFailure)
-> Maybe (SuspendDecision DiffTime)
forall a. Maybe a
Nothing
, (DeserialiseFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((DeserialiseFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy)
-> (DeserialiseFailure -> Maybe (SuspendDecision DiffTime))
-> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(DeserialiseFailure
_ :: CBOR.DeserialiseFailure) -> Maybe (SuspendDecision DiffTime)
forall a. Maybe a
Nothing
, (Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall e.
Exception e =>
(e -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
ErrorPolicy
((Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy)
-> (Error -> Maybe (SuspendDecision DiffTime)) -> ErrorPolicy
forall a b. (a -> b) -> a -> b
$ \(Error
_ :: Mx.Error) -> Maybe (SuspendDecision DiffTime)
forall a. Maybe a
Nothing
],
epConErrorPolicies :: [ErrorPolicy]
epConErrorPolicies = []
}
type RemoteAddress = Socket.SockAddr
instance ShowProxy RemoteAddress where
showProxy :: Proxy SockAddr -> String
showProxy Proxy SockAddr
_ = String
"SockAddr"
type RemoteConnectionId = ConnectionId RemoteAddress