Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ouroboros.Network.Driver.Simple
Synopsis
- runPeer ∷ ∀ ps (st ∷ ps) pr failure bytes m a. (MonadThrow m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ Tracer m (TraceSendRecv ps) → Codec ps failure m bytes → Channel m bytes → Peer ps pr st m a → m (a, Maybe bytes)
- data TraceSendRecv ps where
- TraceSendMsg ∷ AnyMessageAndAgency ps → TraceSendRecv ps
- TraceRecvMsg ∷ AnyMessageAndAgency ps → TraceSendRecv ps
- data DecoderFailure where
- DecoderFailure ∷ ∀ (pr ∷ PeerRole) ps (st ∷ ps) failure. (∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps, Show failure) ⇒ PeerHasAgency pr st → failure → DecoderFailure
- runPipelinedPeer ∷ ∀ ps (st ∷ ps) pr failure bytes m a. (MonadAsync m, MonadThrow m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ Tracer m (TraceSendRecv ps) → Codec ps failure m bytes → Channel m bytes → PeerPipelined ps pr st m a → m (a, Maybe bytes)
- data Role
- runConnectedPeers ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → Peer ps pr st m a → Peer ps (FlipAgency pr) st m b → m (a, b)
- runConnectedPeersAsymmetric ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → Codec ps failure m bytes → Peer ps pr st m a → Peer ps (FlipAgency pr) st m b → m (a, b)
- runConnectedPeersPipelined ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → PeerPipelined ps pr st m a → Peer ps (FlipAgency pr) st m b → m (a, b)
Introduction
A Peer
is a particular implementation of an agent that engages in a
typed protocol. To actualy 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 ∷ ∀ ps (st ∷ ps) pr failure bytes m a. (MonadThrow m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ Tracer m (TraceSendRecv ps) → Codec ps failure m bytes → Channel m bytes → Peer ps pr st 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 where Source #
Constructors
TraceSendMsg ∷ AnyMessageAndAgency ps → TraceSendRecv ps | |
TraceRecvMsg ∷ AnyMessageAndAgency ps → TraceSendRecv ps |
Instances
Show (AnyMessageAndAgency ps) ⇒ Show (TraceSendRecv ps) Source # | |
Defined in Ouroboros.Network.Driver.Simple |
data DecoderFailure where Source #
Constructors
DecoderFailure ∷ ∀ (pr ∷ PeerRole) ps (st ∷ ps) failure. (∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps, Show failure) ⇒ PeerHasAgency pr st → failure → DecoderFailure |
Instances
Exception DecoderFailure Source # | |
Defined in Ouroboros.Network.Driver.Simple | |
Show DecoderFailure Source # | |
Defined in Ouroboros.Network.Driver.Simple |
Pipelined peers
runPipelinedPeer ∷ ∀ ps (st ∷ ps) pr failure bytes m a. (MonadAsync m, MonadThrow m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ Tracer m (TraceSendRecv ps) → Codec ps failure m bytes → Channel m bytes → PeerPipelined ps pr st m a → m (a, Maybe bytes) Source #
Run a pipelined peer with the given channel via the given codec.
This runs the peer to completion (if the protocol allows for termination).
Unlike normal peers, running pipelined peers rely on concurrency, hence the
MonadAsync
constraint.
Connected peers
runConnectedPeers ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → Peer ps pr st m a → Peer ps (FlipAgency pr) st 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 ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → Codec ps failure m bytes → Peer ps pr st m a → Peer ps (FlipAgency pr) st m b → m (a, b) Source #
Run the same protocol with different codes. This is useful for testing
Handshake
protocol which knows how to decode different versions.
runConnectedPeersPipelined ∷ (MonadAsync m, MonadCatch m, Show failure, ∀ (st' ∷ ps). Show (ClientHasAgency st'), ∀ (st' ∷ ps). Show (ServerHasAgency st'), ShowProxy ps) ⇒ m (Channel m bytes, Channel m bytes) → Tracer m (Role, TraceSendRecv ps) → Codec ps failure m bytes → PeerPipelined ps pr st m a → Peer ps (FlipAgency pr) st m b → m (a, b) Source #