Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains peer state management and error policies.
Synopsis
-
data
SuspendDecision
t
- = SuspendPeer !t !t
- | SuspendConsumer !t
- | Throw
- suspend :: Ord ( Async m ()) => Maybe ( PeerState m) -> SuspendDecision Time -> ( Set ( Async m ()), Maybe ( PeerState m))
- data PeerState m
- threadsToCancel :: Ord ( Async m ()) => PeerState m -> SuspendDecision diffTime -> Set ( Async m ())
-
data
PeerStates
m addr
where
- PeerStates :: !( Map addr ( PeerState m)) -> PeerStates m addr
- ThrowException :: Exception e => e -> PeerStates m addr
- newPeerStatesVar :: MonadSTM m => m ( StrictTVar m ( PeerStates m addr))
- newPeerStatesVarSTM :: MonadSTM m => STM m ( StrictTVar m ( PeerStates m addr))
- cleanPeerStates :: ( MonadSTM m, MonadAsync m, MonadTime m, MonadTimer m) => DiffTime -> StrictTVar m ( PeerStates m addr) -> m ()
- runSuspendDecision :: forall m addr e. ( Ord addr, Ord ( Async m ()), Exception e) => Time -> addr -> e -> SuspendDecision DiffTime -> PeerStates m addr -> ( PeerStates m addr, Set ( Async m ()))
- registerConsumer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr
- unregisterConsumer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr
- registerProducer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr
- unregisterProducer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr
- type BeforeConnect m s addr = Time -> addr -> s -> STM m ( ConnectDecision s)
-
data
ConnectDecision
s
- = AllowConnection !s
- | DisallowConnection !s
- runBeforeConnect :: ( MonadSTM m, MonadTime m) => StrictTVar m s -> BeforeConnect m s addr -> addr -> m Bool
- beforeConnectTx :: forall m addr. ( MonadSTM m, Ord addr) => BeforeConnect m ( PeerStates m addr) addr
- data DiffTime
- alterAndLookup :: forall k s a. Ord k => ( Maybe a -> (s, Maybe a)) -> k -> Map k a -> ( Map k a, Maybe s)
Documentation
data SuspendDecision t Source #
Semigroup of commands which acts on
PeerState
. The
t
variable might
be initiated to
DiffTime
or
Time m
.
This semigroup allows to either suspend both consumer and producer or just the consumer part.
SuspendPeer !t !t |
peer is suspend; The first
|
SuspendConsumer !t |
suspend local consumer / initiator side until
|
Throw |
throw an error from the main thread. |
Instances
suspend :: Ord ( Async m ()) => Maybe ( PeerState m) -> SuspendDecision Time -> ( Set ( Async m ()), Maybe ( PeerState m)) Source #
Action of
SuspendDecision
on
Maybe
. Action laws are only
satisfied for the submonoid form by
PeerState
SuspendPeer
and
SuspendConsumer
.
PeerStates and its operations
HotPeer !( Set ( Async m ())) !( Set ( Async m ())) |
active peer with its producers and consumer threads |
SuspendedConsumer !( Set ( Async m ())) ! Time |
suspended consumer: with producer threads and time until the consumer is suspended |
SuspendedPeer ! Time ! Time |
suspended peer: producer & consumer suspend time |
ColdPeer |
peer with no opened connections in either direction |
Instances
Eq ( Async m ()) => Eq ( PeerState m) Source # | |
Ord ( Async m ()) => Ord ( PeerState m) Source # | |
Defined in Ouroboros.Network.Subscription.PeerState compare :: PeerState m -> PeerState m -> Ordering Source # (<) :: PeerState m -> PeerState m -> Bool Source # (<=) :: PeerState m -> PeerState m -> Bool Source # (>) :: PeerState m -> PeerState m -> Bool Source # (>=) :: PeerState m -> PeerState m -> Bool Source # |
|
( MonadAsync m, Show ( ThreadId m), Ord ( ThreadId m)) => Show ( PeerState m) Source # | |
SAct ( SuspendDecision Time ) ( Maybe ( PeerState m)) Source # |
Action of
Note:
|
Defined in Ouroboros.Network.Subscription.PeerState |
threadsToCancel :: Ord ( Async m ()) => PeerState m -> SuspendDecision diffTime -> Set ( Async m ()) Source #
Threads which needs to be cancelled when updating the
PeerState
with
SuspendDecision
.
data PeerStates m addr where Source #
Map from addresses to
PeerState
s; it will be be shared in a
StrictTVar
.
Abstracting
t
is useful for tests, the
IO
version will use
Time IO
.
PeerStates :: !( Map addr ( PeerState m)) -> PeerStates m addr |
Map of peer states |
ThrowException :: Exception e => e -> PeerStates m addr |
Or an exception to throw |
Instances
Eq addr => Eq ( PeerStates IO addr) Source # | |
Defined in Ouroboros.Network.Subscription.PeerState (==) :: PeerStates IO addr -> PeerStates IO addr -> Bool Source # (/=) :: PeerStates IO addr -> PeerStates IO addr -> Bool Source # |
|
Show addr => Show ( PeerStates IO addr) Source # | |
Defined in Ouroboros.Network.Subscription.PeerState |
newPeerStatesVar :: MonadSTM m => m ( StrictTVar m ( PeerStates m addr)) Source #
newPeerStatesVarSTM :: MonadSTM m => STM m ( StrictTVar m ( PeerStates m addr)) Source #
cleanPeerStates :: ( MonadSTM m, MonadAsync m, MonadTime m, MonadTimer m) => DiffTime -> StrictTVar m ( PeerStates m addr) -> m () Source #
Periodically clean
PeerState
. It will stop when
PeerState
becomes
ThrowException
.
runSuspendDecision :: forall m addr e. ( Ord addr, Ord ( Async m ()), Exception e) => Time -> addr -> e -> SuspendDecision DiffTime -> PeerStates m addr -> ( PeerStates m addr, Set ( Async m ())) Source #
Update
PeerStates
for a given
addr
, using
suspend
, and return
threads which must be cancelled.
This is more efficient that using the action of
SuspendDecision
on
PeerStates
, since it only uses a single dictionary lookup to update the
state and return the set of threads to be cancelled.
registerConsumer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr Source #
unregisterConsumer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr Source #
Unregister consumer from a
PeerState
.
registerProducer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr Source #
Register producer in PeerStates. This is a partial function which assumes
that the
PeerState
is either
HotPeer
or
SuspendedConsumer
.
unregisterProducer :: forall m addr. ( Ord addr, Ord ( Async m ())) => addr -> Async m () -> PeerStates m addr -> PeerStates m addr Source #
type BeforeConnect m 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
.
data ConnectDecision s Source #
Before connectin with a peer we make a decision to either connect to it or not.
Instances
Functor ConnectDecision Source # | |
Defined in Ouroboros.Network.Subscription.PeerState fmap :: (a -> b) -> ConnectDecision a -> ConnectDecision b Source # (<$) :: a -> ConnectDecision b -> ConnectDecision a Source # |
runBeforeConnect :: ( MonadSTM m, MonadTime m) => StrictTVar m s -> BeforeConnect m s addr -> addr -> m Bool Source #
Run
BeforeConnect
callback in a
MonadTime
monad.
beforeConnectTx :: forall m 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.
Re-exports
This is a length of time, as measured by a clock. Conversion functions will treat it as seconds. It has a precision of 10^-12 s.