ouroboros-network-framework
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.ConnectionHandler

Contents

Description

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

Documentation

data Handle (muxMode :: Mode) initiatorCtx responderCtx versionData bytes (m :: Type -> Type) a b Source #

States of the connection handler thread.

Constructors

Handle 

Fields

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 #

Constructors

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

Instances details
Show versionNumber => Show (HandleError muxMode versionNumber) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionHandler

Methods

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 #

Arguments

:: 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)

ThreadId and rethrow policy. Rethrow policy might throw an async exception to that thread, when trying to terminate the process.

-> 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 ConnectionManagers: 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.

Instances

Instances details
(Show versionNumber, Show versionData) => Show (ConnectionHandlerTrace versionNumber versionData) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionHandler

Methods

showsPrec :: Int -> ConnectionHandlerTrace versionNumber versionData -> ShowS #

show :: ConnectionHandlerTrace versionNumber versionData -> String #

showList :: [ConnectionHandlerTrace versionNumber versionData] -> ShowS #