ouroboros-network-framework-0.13.1.0: Ouroboros network framework
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Network.Subscription.PeerState

Description

This module contains peer state management and error policies.

Synopsis

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.

Constructors

SuspendPeer !t !t

peer is suspend; The first t is the time until which a local producer is suspended, the second one is the time until which a local consumer is suspended.

SuspendConsumer !t

suspend local consumer / initiator side until t (this mean we are not allowing to communicate with the producer / responder of a remote peer).

Throw

throw an error from the main thread.

Instances

Instances details
Functor SuspendDecision Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

fmap ∷ (a → b) → SuspendDecision a → SuspendDecision b #

(<$) ∷ a → SuspendDecision b → SuspendDecision a #

Ord t ⇒ Semigroup (SuspendDecision t) Source #

The semigroup instance. Note that composing SuspendPeer with SuspendConsumer gives SuspendPeer. SuspendPeer and SuspendConsumer form a sub-semigroup.

Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Show t ⇒ Show (SuspendDecision t) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Eq t ⇒ Eq (SuspendDecision t) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Ord t ⇒ Ord (SuspendDecision t) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

SAct (SuspendDecision Time) (Maybe (PeerState m)) Source #

Action of SuspendDecision on Maybe PeerState. We use this action together with alter function.

Note: SuspendDecision does not act on PeerState, only the sub-semigroup generated by SuspendConsumer and SuspendPeer does.

Instance details

Defined in Ouroboros.Network.Subscription.PeerState

suspendOrd (Async m ()) ⇒ Maybe (PeerState m) → SuspendDecision Time → (Set (Async m ()), Maybe (PeerState m)) Source #

Action of SuspendDecision on Maybe PeerState. Action laws are only satisfied for the submonoid form by SuspendPeer and SuspendConsumer.

PeerStates and its operations

data PeerState m Source #

Constructors

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

Instances details
MonadAsync m ⇒ Show (PeerState m) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

showsPrecIntPeerState m → ShowS #

showPeerState m → String #

showList ∷ [PeerState m] → ShowS #

Eq (Async m ()) ⇒ Eq (PeerState m) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

(==)PeerState m → PeerState m → Bool #

(/=)PeerState m → PeerState m → Bool #

Ord (Async m ()) ⇒ Ord (PeerState m) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

comparePeerState m → PeerState m → Ordering #

(<)PeerState m → PeerState m → Bool #

(<=)PeerState m → PeerState m → Bool #

(>)PeerState m → PeerState m → Bool #

(>=)PeerState m → PeerState m → Bool #

maxPeerState m → PeerState m → PeerState m #

minPeerState m → PeerState m → PeerState m #

SAct (SuspendDecision Time) (Maybe (PeerState m)) Source #

Action of SuspendDecision on Maybe PeerState. We use this action together with alter function.

Note: SuspendDecision does not act on PeerState, only the sub-semigroup generated by SuspendConsumer and SuspendPeer does.

Instance details

Defined in Ouroboros.Network.Subscription.PeerState

threadsToCancelOrd (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 PeerStates; it will be be shared in a StrictTVar.

Abstracting t is useful for tests, the IO version will use Time IO.

Constructors

PeerStates ∷ !(Map addr (PeerState m)) → PeerStates m addr

Map of peer states

ThrowExceptionException e ⇒ e → PeerStates m addr

Or an exception to throw

Instances

Instances details
Show addr ⇒ Show (PeerStates IO addr) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

showsPrecIntPeerStates IO addr → ShowS #

showPeerStates IO addr → String #

showList ∷ [PeerStates IO addr] → ShowS #

Eq addr ⇒ Eq (PeerStates IO addr) Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

(==)PeerStates IO addr → PeerStates IO addr → Bool #

(/=)PeerStates IO addr → PeerStates IO addr → Bool #

cleanPeerStates ∷ (MonadDelay m, MonadTimer m) ⇒ DiffTimeStrictTVar m (PeerStates m addr) → m () Source #

Periodically clean PeerState. It will stop when PeerState becomes ThrowException.

runSuspendDecision ∷ ∀ m addr e. (Ord addr, Ord (Async m ()), Exception e) ⇒ Time → addr → e → SuspendDecision DiffTimePeerStates 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 ∷ ∀ m addr. (Ord addr, Ord (Async m ())) ⇒ addr → Async m () → PeerStates m addr → PeerStates m addr Source #

Register consumer in PeerState. This is a partial function which assumes that the PeerState is HotPeer.

unregisterConsumer ∷ ∀ m addr. (Ord addr, Ord (Async m ())) ⇒ addr → Async m () → PeerStates m addr → PeerStates m addr Source #

Unregister consumer from a PeerState.

registerProducer ∷ ∀ 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 ∷ ∀ 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

Instances details
Functor ConnectDecision Source # 
Instance details

Defined in Ouroboros.Network.Subscription.PeerState

Methods

fmap ∷ (a → b) → ConnectDecision a → ConnectDecision b #

(<$) ∷ a → ConnectDecision b → ConnectDecision a #

runBeforeConnect ∷ (MonadMonotonicTime m, MonadSTM m) ⇒ StrictTVar m s → BeforeConnect m s addr → addr → m Bool Source #

Run BeforeConnect callback in a MonadTime monad.

beforeConnectTx ∷ ∀ 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

data DiffTime #

This is a length of time, as measured by a clock. Conversion functions such as fromInteger and realToFrac will treat it as seconds. For example, (0.010 :: DiffTime) corresponds to 10 milliseconds.

It has a precision of one picosecond (= 10^-12 s). Enumeration functions will treat it as picoseconds.

Instances

Instances details
Data DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

gfoldl ∷ (∀ d b. Data d ⇒ c (d → b) → d → c b) → (∀ g. g → c g) → DiffTime → c DiffTime #

gunfold ∷ (∀ b r. Data b ⇒ c (b → r) → c r) → (∀ r. r → c r) → Constr → c DiffTime #

toConstrDiffTimeConstr #

dataTypeOfDiffTimeDataType #

dataCast1Typeable t ⇒ (∀ d. Data d ⇒ c (t d)) → Maybe (c DiffTime) #

dataCast2Typeable t ⇒ (∀ d e. (Data d, Data e) ⇒ c (t d e)) → Maybe (c DiffTime) #

gmapT ∷ (∀ b. Data b ⇒ b → b) → DiffTimeDiffTime #

gmapQl ∷ (r → r' → r) → r → (∀ d. Data d ⇒ d → r') → DiffTime → r #

gmapQr ∷ ∀ r r'. (r' → r → r) → r → (∀ d. Data d ⇒ d → r') → DiffTime → r #

gmapQ ∷ (∀ d. Data d ⇒ d → u) → DiffTime → [u] #

gmapQiInt → (∀ d. Data d ⇒ d → u) → DiffTime → u #

gmapMMonad m ⇒ (∀ d. Data d ⇒ d → m d) → DiffTime → m DiffTime #

gmapMpMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → DiffTime → m DiffTime #

gmapMoMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → DiffTime → m DiffTime #

Enum DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Num DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Read DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Fractional DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Real DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

toRationalDiffTimeRational #

RealFrac DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

properFractionIntegral b ⇒ DiffTime → (b, DiffTime) #

truncateIntegral b ⇒ DiffTime → b #

roundIntegral b ⇒ DiffTime → b #

ceilingIntegral b ⇒ DiffTime → b #

floorIntegral b ⇒ DiffTime → b #

Show DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

showsPrecIntDiffTimeShowS #

showDiffTimeString #

showList ∷ [DiffTime] → ShowS #

NFData DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

rnfDiffTime → () #

Eq DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

(==)DiffTimeDiffTimeBool #

(/=)DiffTimeDiffTimeBool #

Ord DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

NoThunks DiffTime 
Instance details

Defined in NoThunks.Class

Auxiliary functions

alterAndLookup ∷ ∀ k s a. Ord k ⇒ (Maybe a → (s, Maybe a)) → k → Map k a → (Map k a, Maybe s) Source #