Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implementation of
ConnectionHandler
While connection manager responsibility is to keep track of resources:
sockets and threads running connection and their state changes (including
changes imposed by
ConnectionHandler
, e.g. weather a uni- or duplex- data
flow was negotiated), the responsibility of
ConnectionHandler
is to:
- run handshake protocol on the underlying bearer
- start mux
ConnectionHandler
is run on each inbound or outbound connection and returns
Handle
. Upon successful handshake negotiation it returns all the
necessary information to run mini-protocols. Note that it is not responsible
for running them: that's what a server does or p2p-governor by means of
PeerStateActions
.
Synopsis
-
data
Handle
(muxMode ::
MuxMode
) peerAddr bytes m a b =
Handle
{
- hMux :: !( Mux muxMode m)
- hMuxBundle :: !( MuxBundle muxMode bytes m a b)
- hControlMessage :: !( Bundle ( StrictTVar m ControlMessage ))
-
data
HandleError
(muxMode ::
MuxMode
) versionNumber
where
- HandleHandshakeClientError :: HasInitiator muxMode ~ True => !( HandshakeException versionNumber) -> HandleError muxMode versionNumber
- HandleHandshakeServerError :: HasResponder muxMode ~ True => !( HandshakeException versionNumber) -> HandleError muxMode versionNumber
- HandleError :: ! SomeException -> HandleError muxMode versionNumber
- classifyHandleError :: HandleError muxMode versionNumber -> HandleErrorType
- type MuxConnectionHandler muxMode socket peerAddr versionNumber versionData bytes m a b = ConnectionHandler muxMode ( ConnectionHandlerTrace versionNumber versionData) socket peerAddr ( Handle muxMode peerAddr bytes m a b) ( HandleError muxMode versionNumber) (versionNumber, versionData) m
- makeConnectionHandler :: forall peerAddr muxMode socket versionNumber versionData m a b. ( MonadAsync m, MonadCatch m, MonadFork m, MonadLabelledSTM m, MonadThrow ( STM m), MonadTime m, MonadTimer m, MonadMask m, Ord versionNumber, Show peerAddr, Typeable peerAddr) => Tracer m ( WithMuxBearer ( ConnectionId peerAddr) MuxTrace ) -> SingMuxMode muxMode -> HandshakeArguments ( ConnectionId peerAddr) versionNumber versionData m -> Versions versionNumber versionData ( OuroborosBundle muxMode peerAddr ByteString m a b) -> ( ThreadId m, RethrowPolicy ) -> MuxConnectionHandler muxMode socket peerAddr versionNumber versionData ByteString m a b
- type MuxConnectionManager muxMode socket peerAddr versionNumber bytes m a b = ConnectionManager muxMode socket peerAddr ( Handle muxMode peerAddr bytes m a b) ( HandleError muxMode versionNumber) m
-
data
ConnectionHandlerTrace
versionNumber versionData
- = TrHandshakeSuccess versionNumber versionData
- | TrHandshakeClientError ( HandshakeException versionNumber)
- | TrHandshakeServerError ( HandshakeException versionNumber)
- | TrError ErrorContext SomeException ErrorCommand
Documentation
data Handle (muxMode :: MuxMode ) peerAddr bytes m a b Source #
States of the connection handler thread.
-
MuxRunning
- successful Handshake, mux started -
HandleHandshakeClientError
-
the connection handler thread was running client side
of the handshake negotiation, which failed with
a
HandshakeException
-
HandleHandshakeServerError
-
the connection handler thread was running server side of the
handshake protocol, which fail with
HandshakeException
-
HandleError
-
the multiplexer thrown
MuxError
.
Handle | |
|
data HandleError (muxMode :: MuxMode ) versionNumber where Source #
HandleHandshakeClientError :: HasInitiator muxMode ~ True => !( HandshakeException versionNumber) -> HandleError muxMode versionNumber | |
HandleHandshakeServerError :: HasResponder muxMode ~ True => !( HandshakeException versionNumber) -> HandleError muxMode versionNumber | |
HandleError :: ! SomeException -> HandleError muxMode versionNumber |
Instances
Show versionNumber => Show ( HandleError muxMode versionNumber) Source # | |
Defined in Ouroboros.Network.ConnectionHandler |
classifyHandleError :: HandleError muxMode versionNumber -> HandleErrorType Source #
type MuxConnectionHandler muxMode socket peerAddr versionNumber versionData bytes m a b = ConnectionHandler muxMode ( ConnectionHandlerTrace versionNumber versionData) socket peerAddr ( Handle muxMode peerAddr bytes m a b) ( HandleError muxMode versionNumber) (versionNumber, versionData) m Source #
Type of
ConnectionHandler
implemented in this module.
makeConnectionHandler Source #
:: forall peerAddr muxMode socket versionNumber versionData m a b. ( MonadAsync m, MonadCatch m, MonadFork m, MonadLabelledSTM m, MonadThrow ( STM m), MonadTime m, MonadTimer m, MonadMask m, Ord versionNumber, Show peerAddr, Typeable peerAddr) | |
=> Tracer m ( WithMuxBearer ( ConnectionId peerAddr) MuxTrace ) | |
-> SingMuxMode muxMode |
describe whether this is outbound or inbound connection, and bring evidence that we can use mux with it. |
-> HandshakeArguments ( ConnectionId peerAddr) versionNumber versionData m | |
-> Versions versionNumber versionData ( OuroborosBundle muxMode peerAddr ByteString m a b) | |
-> ( ThreadId m, RethrowPolicy ) |
|
-> MuxConnectionHandler muxMode socket peerAddr versionNumber versionData ByteString m a b |
To be used as
makeConnectionHandler
field of
ConnectionManagerArguments
.
Note: We need to pass
MiniProtocolBundle
what forces us to have two
different
ConnectionManager
s: one for `node-to-client` and another for
`node-to-node` connections. But this is ok, as these resources are
independent.
type MuxConnectionManager muxMode socket peerAddr versionNumber bytes m a b = ConnectionManager muxMode socket peerAddr ( Handle muxMode peerAddr bytes m a b) ( HandleError muxMode versionNumber) m Source #
Type alias for
ConnectionManager
using
Handle
.
tracing
data ConnectionHandlerTrace versionNumber versionData Source #
ConnectionHandlerTrace
is embedded into
ConnectionManagerTrace
with
ConnectionHandlerTrace
constructor. It already includes
ConnectionId
so we don't need to take
care of it here.
TODO: when
Handshake
will get its own tracer, independent of
Mux
, it
should be embedded into
ConnectionHandlerTrace
.
TrHandshakeSuccess versionNumber versionData | |
TrHandshakeClientError ( HandshakeException versionNumber) | |
TrHandshakeServerError ( HandshakeException versionNumber) | |
TrError ErrorContext SomeException ErrorCommand |
Instances
( Show versionNumber, Show versionData) => Show ( ConnectionHandlerTrace versionNumber versionData) Source # | |
Defined in Ouroboros.Network.ConnectionHandler |