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 :: Mode) initiatorCtx responderCtx versionData bytes (m :: Type -> Type) a b = Handle {
- hMux :: !(Mux muxMode m)
- hMuxBundle :: !(OuroborosBundle muxMode initiatorCtx responderCtx bytes m a b)
- hControlMessage :: !(TemperatureBundle (StrictTVar m ControlMessage))
- hVersionData :: !versionData
- type HandleWithExpandedCtx (muxMode :: Mode) peerAddr versionData bytes (m :: Type -> Type) a b = Handle muxMode (ExpandedInitiatorContext peerAddr m) (ResponderContext peerAddr) versionData bytes m a b
- type HandleWithMinimalCtx (muxMode :: Mode) peerAddr versionData bytes (m :: Type -> Type) a b = Handle muxMode (MinimalInitiatorContext peerAddr) (ResponderContext peerAddr) versionData bytes m a b
- data HandleError (muxMode :: Mode) versionNumber where
- HandleHandshakeClientError :: forall (muxMode :: Mode) versionNumber. HasInitiator muxMode ~ 'True => !(HandshakeException versionNumber) -> HandleError muxMode versionNumber
- HandleHandshakeServerError :: forall (muxMode :: Mode) versionNumber. HasResponder muxMode ~ 'True => !(HandshakeException versionNumber) -> HandleError muxMode versionNumber
- HandleError :: forall (muxMode :: Mode) versionNumber. !SomeException -> HandleError muxMode versionNumber
- classifyHandleError :: forall (muxMode :: Mode) versionNumber. HandleError muxMode versionNumber -> HandleErrorType
- type MuxConnectionHandler (muxMode :: Mode) socket initiatorCtx responderCtx peerAddr versionNumber versionData bytes (m :: Type -> Type) a b = ConnectionHandler muxMode (ConnectionHandlerTrace versionNumber versionData) socket peerAddr (Handle muxMode initiatorCtx responderCtx versionData bytes m a b) (HandleError muxMode versionNumber) versionNumber versionData m
- makeConnectionHandler :: forall initiatorCtx responderCtx peerAddr (muxMode :: Mode) socket versionNumber versionData (m :: Type -> Type) a b. (Alternative (STM m), MonadAsync m, MonadDelay m, MonadFork m, MonadLabelledSTM m, MonadThrow (STM m), MonadTimer m, MonadMask m, Ord versionNumber, Show peerAddr, Typeable peerAddr) => Tracer m (WithBearer (ConnectionId peerAddr) Trace) -> SingMuxMode muxMode -> HandshakeArguments (ConnectionId peerAddr) versionNumber versionData m -> Versions versionNumber versionData (OuroborosBundle muxMode initiatorCtx responderCtx ByteString m a b) -> (ThreadId m, RethrowPolicy) -> MuxConnectionHandler muxMode socket initiatorCtx responderCtx peerAddr versionNumber versionData ByteString m a b
- type MuxConnectionManager (muxMode :: Mode) socket initiatorCtx responderCtx peerAddr versionData versionNumber bytes (m :: Type -> Type) a b = ConnectionManager muxMode socket peerAddr (Handle muxMode initiatorCtx responderCtx versionData bytes m a b) (HandleError muxMode versionNumber) m
- type ConnectionManagerWithExpandedCtx (muxMode :: Mode) socket peerAddr versionData versionNumber bytes (m :: Type -> Type) a b = ConnectionManager muxMode socket peerAddr (HandleWithExpandedCtx muxMode peerAddr versionData bytes m a b) (HandleError muxMode versionNumber) m
- data ConnectionHandlerTrace versionNumber versionData
- = TrHandshakeSuccess versionNumber versionData
- | TrHandshakeQuery (Map versionNumber (Either Text versionData))
- | TrHandshakeClientError (HandshakeException versionNumber)
- | TrHandshakeServerError (HandshakeException versionNumber)
- | TrConnectionHandlerError ErrorContext SomeException ErrorCommand
Documentation
data Handle (muxMode :: Mode) initiatorCtx responderCtx versionData bytes (m :: Type -> Type) a b Source #
States of the connection handler thread.
MuxRunning
- successful Handshake, mux startedHandleHandshakeClientError
- 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 | |
|
type HandleWithExpandedCtx (muxMode :: Mode) peerAddr versionData bytes (m :: Type -> Type) a b = Handle muxMode (ExpandedInitiatorContext peerAddr m) (ResponderContext peerAddr) versionData bytes m a b Source #
Handle
used by `node-to-node` P2P connections.
type HandleWithMinimalCtx (muxMode :: Mode) peerAddr versionData bytes (m :: Type -> Type) a b = Handle muxMode (MinimalInitiatorContext peerAddr) (ResponderContext peerAddr) versionData bytes m a b Source #
Handle
used by:
- `node-to-node` non P2P mode;
- `node-to-client` connections.
data HandleError (muxMode :: Mode) versionNumber where Source #
HandleHandshakeClientError :: forall (muxMode :: Mode) versionNumber. HasInitiator muxMode ~ 'True => !(HandshakeException versionNumber) -> HandleError muxMode versionNumber | |
HandleHandshakeServerError :: forall (muxMode :: Mode) versionNumber. HasResponder muxMode ~ 'True => !(HandshakeException versionNumber) -> HandleError muxMode versionNumber | |
HandleError :: forall (muxMode :: Mode) versionNumber. !SomeException -> HandleError muxMode versionNumber |
Instances
Show versionNumber => Show (HandleError muxMode versionNumber) Source # | |
Defined in Ouroboros.Network.ConnectionHandler showsPrec :: Int -> HandleError muxMode versionNumber -> ShowS # show :: HandleError muxMode versionNumber -> String # showList :: [HandleError muxMode versionNumber] -> ShowS # |
classifyHandleError :: forall (muxMode :: Mode) versionNumber. HandleError muxMode versionNumber -> HandleErrorType Source #
type MuxConnectionHandler (muxMode :: Mode) socket initiatorCtx responderCtx peerAddr versionNumber versionData bytes (m :: Type -> Type) a b = ConnectionHandler muxMode (ConnectionHandlerTrace versionNumber versionData) socket peerAddr (Handle muxMode initiatorCtx responderCtx versionData bytes m a b) (HandleError muxMode versionNumber) versionNumber versionData m Source #
Type of ConnectionHandler
implemented in this module.
makeConnectionHandler Source #
:: forall initiatorCtx responderCtx peerAddr (muxMode :: Mode) socket versionNumber versionData (m :: Type -> Type) a b. (Alternative (STM m), MonadAsync m, MonadDelay m, MonadFork m, MonadLabelledSTM m, MonadThrow (STM m), MonadTimer m, MonadMask m, Ord versionNumber, Show peerAddr, Typeable peerAddr) | |
=> Tracer m (WithBearer (ConnectionId peerAddr) Trace) | |
-> 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 initiatorCtx responderCtx ByteString m a b) | |
-> (ThreadId m, RethrowPolicy) |
|
-> MuxConnectionHandler muxMode socket initiatorCtx responderCtx 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 :: Mode) socket initiatorCtx responderCtx peerAddr versionData versionNumber bytes (m :: Type -> Type) a b = ConnectionManager muxMode socket peerAddr (Handle muxMode initiatorCtx responderCtx versionData bytes m a b) (HandleError muxMode versionNumber) m Source #
Type alias for ConnectionManager
using Handle
.
type ConnectionManagerWithExpandedCtx (muxMode :: Mode) socket peerAddr versionData versionNumber bytes (m :: Type -> Type) a b = ConnectionManager muxMode socket peerAddr (HandleWithExpandedCtx muxMode peerAddr versionData bytes m a b) (HandleError muxMode versionNumber) m Source #
Type alias for ConnectionManager
which is using expanded context.
tracing
data ConnectionHandlerTrace versionNumber versionData Source #
ConnectionHandlerTrace
is embedded into
Trace
with
TrConnectionHandler
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 | |
TrHandshakeQuery (Map versionNumber (Either Text versionData)) | |
TrHandshakeClientError (HandshakeException versionNumber) | |
TrHandshakeServerError (HandshakeException versionNumber) | |
TrConnectionHandlerError ErrorContext SomeException ErrorCommand |
Instances
(Show versionNumber, Show versionData) => Show (ConnectionHandlerTrace versionNumber versionData) Source # | |
Defined in Ouroboros.Network.ConnectionHandler showsPrec :: Int -> ConnectionHandlerTrace versionNumber versionData -> ShowS # show :: ConnectionHandlerTrace versionNumber versionData -> String # showList :: [ConnectionHandlerTrace versionNumber versionData] -> ShowS # |