Safe Haskell | None |
---|---|
Language | Haskell2010 |
IP subscription worker implentation.
Synopsis
- data SubscriptionParams a target = SubscriptionParams {}
- type IPSubscriptionParams a = SubscriptionParams a IPSubscriptionTarget
- ipSubscriptionWorker :: Snocket IO Socket SockAddr -> Tracer IO (WithIPList (SubscriptionTrace SockAddr)) -> Tracer IO (WithAddr SockAddr ErrorPolicyTrace) -> NetworkMutableState SockAddr -> IPSubscriptionParams a -> (Socket -> IO a) -> IO Void
- subscriptionWorker :: Snocket IO Socket SockAddr -> Tracer IO (SubscriptionTrace SockAddr) -> Tracer IO (WithAddr SockAddr ErrorPolicyTrace) -> NetworkMutableState SockAddr -> WorkerParams IO LocalAddresses SockAddr -> ErrorPolicies -> Main IO (PeerStates IO SockAddr) x -> (Socket -> IO a) -> IO x
- data IPSubscriptionTarget = IPSubscriptionTarget {
- ispIps :: ![SockAddr]
- ispValency :: !Int
- ipSubscriptionTarget :: forall (m :: Type -> Type) addr. (MonadMonotonicTime m, MonadSTM m, Ord addr) => Tracer m (SubscriptionTrace addr) -> StrictTVar m (PeerStates m addr) -> [addr] -> SubscriptionTarget m addr
- data SubscriptionTrace addr
- = SubscriptionTraceConnectStart addr
- | SubscriptionTraceConnectEnd addr ConnectResult
- | Exception e => SubscriptionTraceSocketAllocationException addr e
- | Exception e => SubscriptionTraceConnectException addr e
- | Exception e => SubscriptionTraceApplicationException addr e
- | SubscriptionTraceTryConnectToPeer addr
- | SubscriptionTraceSkippingPeer addr
- | SubscriptionTraceSubscriptionRunning
- | SubscriptionTraceSubscriptionWaiting Int
- | SubscriptionTraceSubscriptionFailed
- | SubscriptionTraceSubscriptionWaitingNewConnection DiffTime
- | SubscriptionTraceStart Int
- | SubscriptionTraceRestart DiffTime Int Int
- | SubscriptionTraceConnectionExist addr
- | SubscriptionTraceUnsupportedRemoteAddr addr
- | SubscriptionTraceMissingLocalAddress
- | SubscriptionTraceAllocateSocket addr
- | SubscriptionTraceCloseSocket addr
- data ErrorPolicyTrace
- = ErrorPolicySuspendPeer (Maybe (ConnectionOrApplicationExceptionTrace SomeException)) DiffTime DiffTime
- | ErrorPolicySuspendConsumer (Maybe (ConnectionOrApplicationExceptionTrace SomeException)) DiffTime
- | ErrorPolicyLocalNodeError (ConnectionOrApplicationExceptionTrace SomeException)
- | ErrorPolicyResumePeer
- | ErrorPolicyKeepSuspended
- | ErrorPolicyResumeConsumer
- | ErrorPolicyResumeProducer
- | ErrorPolicyUnhandledApplicationException SomeException
- | ErrorPolicyUnhandledConnectionException SomeException
- | ErrorPolicyAcceptException IOException
- data WithIPList a = WithIPList {}
- type BeforeConnect (m :: Type -> Type) s addr = Time -> addr -> s -> STM m (ConnectDecision s)
- runBeforeConnect :: (MonadMonotonicTime m, MonadSTM m) => StrictTVar m s -> BeforeConnect m s addr -> addr -> m Bool
- beforeConnectTx :: forall (m :: Type -> Type) addr. (MonadSTM m, Ord addr) => BeforeConnect m (PeerStates m addr) addr
- completeApplicationTx :: forall (m :: Type -> Type) addr a. (MonadAsync m, Ord addr, Ord (Async m ())) => ErrorPolicies -> CompleteApplication m (PeerStates m addr) addr a
- socketStateChangeTx :: Ord addr => SocketStateChange IO (PeerStates IO addr) addr
- mainTx :: forall (m :: Type -> Type) addr. (MonadThrow (STM m), MonadSTM m) => Main m (PeerStates m addr) Void
- selectSockAddr :: SockAddr -> LocalAddresses SockAddr -> Maybe SockAddr
Documentation
data SubscriptionParams a target Source #
ipSubscriptionWorker
and dnsSubscriptionWorker
parameters
SubscriptionParams | |
|
ipSubscriptionWorker :: Snocket IO Socket SockAddr -> Tracer IO (WithIPList (SubscriptionTrace SockAddr)) -> Tracer IO (WithAddr SockAddr ErrorPolicyTrace) -> NetworkMutableState SockAddr -> IPSubscriptionParams a -> (Socket -> IO a) -> IO Void Source #
Spawns a subscription worker which will attempt to keep the specified number of connections (Valency) active towards the list of IP addresses given in IPSubscriptionTarget.
:: Snocket IO Socket SockAddr | |
-> Tracer IO (SubscriptionTrace SockAddr) | |
-> Tracer IO (WithAddr SockAddr ErrorPolicyTrace) | |
-> NetworkMutableState SockAddr | |
-> WorkerParams IO LocalAddresses SockAddr | |
-> ErrorPolicies | |
-> Main IO (PeerStates IO SockAddr) x | main callback |
-> (Socket -> IO a) | application to run on each connection |
-> IO x |
Like worker
but in IO
; It provides address selection function,
SocketStateChange
and CompleteApplication
callbacks. The Main
callback is left as it's useful for testing purposes.
data IPSubscriptionTarget Source #
IPSubscriptionTarget | |
|
Instances
Show IPSubscriptionTarget Source # | |
Defined in Ouroboros.Network.Subscription.Ip showsPrec :: Int -> IPSubscriptionTarget -> ShowS # show :: IPSubscriptionTarget -> String # showList :: [IPSubscriptionTarget] -> ShowS # | |
Eq IPSubscriptionTarget Source # | |
Defined in Ouroboros.Network.Subscription.Ip (==) :: IPSubscriptionTarget -> IPSubscriptionTarget -> Bool # (/=) :: IPSubscriptionTarget -> IPSubscriptionTarget -> Bool # |
ipSubscriptionTarget :: forall (m :: Type -> Type) addr. (MonadMonotonicTime m, MonadSTM m, Ord addr) => Tracer m (SubscriptionTrace addr) -> StrictTVar m (PeerStates m addr) -> [addr] -> SubscriptionTarget m addr Source #
data SubscriptionTrace addr Source #
Instances
Show addr => Show (SubscriptionTrace addr) Source # | |
Defined in Ouroboros.Network.Subscription.Worker showsPrec :: Int -> SubscriptionTrace addr -> ShowS # show :: SubscriptionTrace addr -> String # showList :: [SubscriptionTrace addr] -> ShowS # |
data ErrorPolicyTrace Source #
Trace data for error policies
ErrorPolicySuspendPeer (Maybe (ConnectionOrApplicationExceptionTrace SomeException)) DiffTime DiffTime | suspending peer with a given exception until |
ErrorPolicySuspendConsumer (Maybe (ConnectionOrApplicationExceptionTrace SomeException)) DiffTime | suspending consumer until |
ErrorPolicyLocalNodeError (ConnectionOrApplicationExceptionTrace SomeException) | caught a local exception |
ErrorPolicyResumePeer | resume a peer (both consumer and producer) |
ErrorPolicyKeepSuspended | consumer was suspended until producer will resume |
ErrorPolicyResumeConsumer | resume consumer |
ErrorPolicyResumeProducer | resume producer |
ErrorPolicyUnhandledApplicationException SomeException | an application throwed an exception, which was not handled by any
|
ErrorPolicyUnhandledConnectionException SomeException |
|
ErrorPolicyAcceptException IOException |
|
Instances
Show ErrorPolicyTrace Source # | |
Defined in Ouroboros.Network.ErrorPolicy showsPrec :: Int -> ErrorPolicyTrace -> ShowS # show :: ErrorPolicyTrace -> String # showList :: [ErrorPolicyTrace] -> ShowS # |
data WithIPList a Source #
Instances
Show a => Show (WithIPList a) Source # | |
Defined in Ouroboros.Network.Subscription.Ip showsPrec :: Int -> WithIPList a -> ShowS # show :: WithIPList a -> String # showList :: [WithIPList a] -> ShowS # |
PeerState
STM transactions
type BeforeConnect (m :: Type -> Type) s addr = Time -> addr -> s -> STM m (ConnectDecision s) Source #
Check state before connecting to a remote peer. We will connect only if
it retuns True
.
runBeforeConnect :: (MonadMonotonicTime m, MonadSTM m) => StrictTVar m s -> BeforeConnect m s addr -> addr -> m Bool Source #
Run BeforeConnect
callback in a MonadTime
monad.
beforeConnectTx :: forall (m :: Type -> Type) addr. (MonadSTM m, Ord addr) => BeforeConnect m (PeerStates m addr) addr Source #
BeforeConnect
callback: it updates peer state and return boolean value
wheather to connect to it or not. If a peer hasn't been recorded in
PeerStates
, we add it and try to connect to it.
completeApplicationTx :: forall (m :: Type -> Type) addr a. (MonadAsync m, Ord addr, Ord (Async m ())) => ErrorPolicies -> CompleteApplication m (PeerStates m addr) addr a Source #
CompleteApplication
callback
socketStateChangeTx :: Ord addr => SocketStateChange IO (PeerStates IO addr) addr Source #
mainTx :: forall (m :: Type -> Type) addr. (MonadThrow (STM m), MonadSTM m) => Main m (PeerStates m addr) Void Source #
Main callback. It throws an exception when the state becomes
ThrowException
. This exception is thrown from the main thread.
Utilitity functions
selectSockAddr :: SockAddr -> LocalAddresses SockAddr -> Maybe SockAddr Source #