Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- runPeer :: forall ps (st :: ps) (pr :: PeerRole) failure bytes f m a. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) stok. stok ~ StateToken st' => Show stok, ShowProxy ps) => Tracer m (TraceSendRecv ps f) -> Codec ps failure f m bytes -> Channel m bytes -> f st -> Peer ps pr st f m a -> m (a, Maybe bytes)
- data TraceSendRecv ps (f :: ps -> Type) where
- TraceSendMsg :: forall ps (f :: ps -> Type). AnyMessage ps f -> TraceSendRecv ps f
- TraceRecvMsg :: forall ps (f :: ps -> Type). AnyMessage ps f -> TraceSendRecv ps f
- data Role
- data DecoderFailure where
- DecoderFailure :: forall ps (st :: ps) failure. (Show failure, Show (StateToken st), ShowProxy ps, ActiveState st) => StateToken st -> failure -> DecoderFailure
- runConnectedPeers :: forall ps (pr :: PeerRole) (st :: ps) failure bytes f m a b. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) tok. tok ~ StateToken st' => Show tok, ShowProxy ps) => m (Channel m bytes, Channel m bytes) -> Tracer m (Role, TraceSendRecv ps f) -> Codec ps failure f m bytes -> f st -> Peer ps pr st f m a -> Peer ps (FlipAgency pr) st f m b -> m (a, b)
- runConnectedPeersAsymmetric :: forall m failure ps bytes f (st :: ps) (pr :: PeerRole) a b. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) tok. tok ~ StateToken st' => Show tok, ShowProxy ps) => m (Channel m bytes, Channel m bytes) -> Tracer m (Role, TraceSendRecv ps f) -> Codec ps failure f m bytes -> Codec ps failure f m bytes -> f st -> Peer ps pr st f m a -> Peer ps (FlipAgency pr) st f m b -> m (a, b)
Introduction
A Peer
is a particular implementation of an agent that engages in a
typed protocol. To actually run one we need a source and sink for the typed
protocol messages. These are provided by a Channel
and a Codec
. The
Channel
represents one end of an untyped duplex message transport, and
the Codec
handles conversion between the typed protocol messages and
the untyped channel.
So given the Peer
and a compatible Codec
and Channel
we can run the
peer in some appropriate monad. The peer and codec have to agree on
the same protocol and role in that protocol. The codec and channel have to
agree on the same untyped medium, e.g. text or bytes. All three have to
agree on the same monad in which they will run.
This module provides drivers for normal and pipelined peers. There is very little policy involved here so typically it should be possible to use these drivers, and customise things by adjusting the peer, or codec or channel.
It is of course possible to write custom drivers and the code for these ones
may provide a useful starting point. The runDecoder
function may be a
helpful utility for use in custom drives.
runPeer :: forall ps (st :: ps) (pr :: PeerRole) failure bytes f m a. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) stok. stok ~ StateToken st' => Show stok, ShowProxy ps) => Tracer m (TraceSendRecv ps f) -> Codec ps failure f m bytes -> Channel m bytes -> f st -> Peer ps pr st f m a -> m (a, Maybe bytes) Source #
Run a peer with the given channel via the given codec.
This runs the peer to completion (if the protocol allows for termination).
data TraceSendRecv ps (f :: ps -> Type) where Source #
TraceSendMsg :: forall ps (f :: ps -> Type). AnyMessage ps f -> TraceSendRecv ps f | |
TraceRecvMsg :: forall ps (f :: ps -> Type). AnyMessage ps f -> TraceSendRecv ps f |
Instances
Show (AnyMessage ps f) => Show (TraceSendRecv ps f) Source # | |
Defined in Ouroboros.Network.Driver.Stateful showsPrec :: Int -> TraceSendRecv ps f -> ShowS # show :: TraceSendRecv ps f -> String # showList :: [TraceSendRecv ps f] -> ShowS # |
data DecoderFailure where Source #
DecoderFailure :: forall ps (st :: ps) failure. (Show failure, Show (StateToken st), ShowProxy ps, ActiveState st) => StateToken st -> failure -> DecoderFailure |
Instances
Exception DecoderFailure Source # | |
Defined in Ouroboros.Network.Driver.Simple | |
Show DecoderFailure Source # | |
Defined in Ouroboros.Network.Driver.Simple showsPrec :: Int -> DecoderFailure -> ShowS # show :: DecoderFailure -> String # showList :: [DecoderFailure] -> ShowS # |
Connected peers
runConnectedPeers :: forall ps (pr :: PeerRole) (st :: ps) failure bytes f m a b. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) tok. tok ~ StateToken st' => Show tok, ShowProxy ps) => m (Channel m bytes, Channel m bytes) -> Tracer m (Role, TraceSendRecv ps f) -> Codec ps failure f m bytes -> f st -> Peer ps pr st f m a -> Peer ps (FlipAgency pr) st f m b -> m (a, b) Source #
Run two Peer
s via a pair of connected Channel
s and a common Codec
.
This is useful for tests and quick experiments.
The first argument is expected to create two channels that are connected,
for example createConnectedChannels
.
runConnectedPeersAsymmetric :: forall m failure ps bytes f (st :: ps) (pr :: PeerRole) a b. (MonadAsync m, MonadMask m, Show failure, forall (st' :: ps) tok. tok ~ StateToken st' => Show tok, ShowProxy ps) => m (Channel m bytes, Channel m bytes) -> Tracer m (Role, TraceSendRecv ps f) -> Codec ps failure f m bytes -> Codec ps failure f m bytes -> f st -> Peer ps pr st f m a -> Peer ps (FlipAgency pr) st f m b -> m (a, b) Source #