ouroboros-network-framework
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.Socket

Description

Module exports interface for running a node over a socket over TCP / IP.

Synopsis

High level socket interface

data ConnectionTable (m :: Type -> Type) addr Source #

data ConnectionTableRef Source #

Constructors

ConnectionTableCreate

No connection to peer exists, attempt to create one.

ConnectionTableExist

A connection to the peer existed, either from another subscriber or the peer opened one towards us.

ConnectionTableDuplicate

This subscriber already has counted a connection to this peer. It must try another target.

data ValencyCounter (m :: Type -> Type) Source #

ValencyCounter represents how many active connections we have towards a given peer. It starts out with a positive value representing a desired number of connections for a specific subscription worker. It can become negative, for example if a peer opens multiple connections to us. The vcId is unique per ConnectionTable and ensures that we won't count the same connection twice.

data SomeResponderApplication addr bytes (m :: Type -> Type) b where Source #

Wrapper for OuroborosResponderApplication and OuroborosInitiatorAndResponderApplication.

Constructors

SomeResponderApplication :: forall (muxMode :: Mode) addr bytes (m :: Type -> Type) a b. HasResponder muxMode ~ 'True => OuroborosApplicationWithMinimalCtx muxMode addr bytes m a b -> SomeResponderApplication addr bytes m b 

data ConnectionId addr Source #

Connection is identified by local and remote address.

TODO: the type variable which this data type fills in is called peerid. We should renamed to connectionId.

Constructors

ConnectionId 

Fields

Instances

Instances details
Functor ConnectionId Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Methods

fmap :: (a -> b) -> ConnectionId a -> ConnectionId b #

(<$) :: a -> ConnectionId b -> ConnectionId a #

ShowProxy addr => ShowProxy (ConnectionId addr :: Type) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Methods

showProxy :: Proxy (ConnectionId addr) -> String #

Generic (ConnectionId addr) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Associated Types

type Rep (ConnectionId addr) 
Instance details

Defined in Ouroboros.Network.ConnectionId

type Rep (ConnectionId addr) = D1 ('MetaData "ConnectionId" "Ouroboros.Network.ConnectionId" "ouroboros-network-framework-0.16.0.0-inplace" 'False) (C1 ('MetaCons "ConnectionId" 'PrefixI 'True) (S1 ('MetaSel ('Just "localAddress") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 addr) :*: S1 ('MetaSel ('Just "remoteAddress") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 addr)))

Methods

from :: ConnectionId addr -> Rep (ConnectionId addr) x #

to :: Rep (ConnectionId addr) x -> ConnectionId addr #

Show addr => Show (ConnectionId addr) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Methods

showsPrec :: Int -> ConnectionId addr -> ShowS #

show :: ConnectionId addr -> String #

showList :: [ConnectionId addr] -> ShowS #

Eq addr => Eq (ConnectionId addr) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Methods

(==) :: ConnectionId addr -> ConnectionId addr -> Bool #

(/=) :: ConnectionId addr -> ConnectionId addr -> Bool #

Ord addr => Ord (ConnectionId addr) Source #

Order first by remoteAddress then by localAddress.

Note: we relay on the fact that remoteAddress is an order preserving map (which allows us to use mapKeysMonotonic in some cases. We also relay on this particular order in liveConnections

Instance details

Defined in Ouroboros.Network.ConnectionId

Methods

compare :: ConnectionId addr -> ConnectionId addr -> Ordering #

(<) :: ConnectionId addr -> ConnectionId addr -> Bool #

(<=) :: ConnectionId addr -> ConnectionId addr -> Bool #

(>) :: ConnectionId addr -> ConnectionId addr -> Bool #

(>=) :: ConnectionId addr -> ConnectionId addr -> Bool #

max :: ConnectionId addr -> ConnectionId addr -> ConnectionId addr #

min :: ConnectionId addr -> ConnectionId addr -> ConnectionId addr #

Hashable a => Hashable (ConnectionId a) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

Typeable addr => NoThunks (ConnectionId addr) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

type Rep (ConnectionId addr) Source # 
Instance details

Defined in Ouroboros.Network.ConnectionId

type Rep (ConnectionId addr) = D1 ('MetaData "ConnectionId" "Ouroboros.Network.ConnectionId" "ouroboros-network-framework-0.16.0.0-inplace" 'False) (C1 ('MetaCons "ConnectionId" 'PrefixI 'True) (S1 ('MetaSel ('Just "localAddress") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 addr) :*: S1 ('MetaSel ('Just "remoteAddress") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 addr)))

connectToNode Source #

Arguments

:: forall (muxMode :: Mode) vNumber vData fd addr a b. (Ord vNumber, Typeable vNumber, Show vNumber, HasInitiator muxMode ~ 'True) 
=> Snocket IO fd addr 
-> MakeBearer IO fd 
-> ConnectToArgs fd addr vNumber vData 
-> (fd -> IO ())

configure socket

-> Versions vNumber vData (OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b) 
-> Maybe addr

local address; the created socket will bind to it

-> addr

remote address

-> IO (Either SomeException (Either a b)) 

Connect to a remote node. It is using bracket to enclose the underlying socket acquisition. This implies that when the continuation exits the underlying bearer will get closed.

The connection will start with handshake protocol sending Versions to the remote peer. It must fit into maxTransmissionUnit (~5k bytes).

Exceptions thrown by MuxApplication are rethrown by connectToNode.

connectToNodeWithMux Source #

Arguments

:: forall (muxMode :: Mode) vNumber vData fd addr a b x. (Ord vNumber, Typeable vNumber, Show vNumber, HasInitiator muxMode ~ 'True) 
=> Snocket IO fd addr 
-> MakeBearer IO fd 
-> ConnectToArgs fd addr vNumber vData 
-> (fd -> IO ())

configure socket

-> Versions vNumber vData (OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)

application to run over the connection ^ remote address

-> Maybe addr 
-> addr 
-> (ConnectionId addr -> vNumber -> vData -> OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b -> Mux muxMode IO -> Async IO () -> IO x)

callback which has access to ConnectionId, negotiated protocols, mux handle created for that connection and an Async handle to the thread which runs runMux. The Mux handle allows schedule mini-protocols.

NOTE: when the callback returns or errors, the mux thread will be killed.

-> IO x 

A version connectToNode which allows one to control which mini-protocols to execute on a given connection.

connectToNodeSocket Source #

Arguments

:: forall (muxMode :: Mode) vNumber vData a b. (Ord vNumber, Typeable vNumber, Show vNumber, HasInitiator muxMode ~ 'True) 
=> IOManager 
-> ConnectToArgs Socket SockAddr vNumber vData 
-> Versions vNumber vData (OuroborosApplicationWithMinimalCtx muxMode SockAddr ByteString IO a b)

application to run over the connection

-> Socket 
-> IO (Either SomeException (Either a b)) 

connectToNode' Source #

Arguments

:: forall (muxMode :: Mode) vNumber vData fd addr a b. (Ord vNumber, Typeable vNumber, Show vNumber, HasInitiator muxMode ~ 'True) 
=> Snocket IO fd addr 
-> MakeBearer IO fd 
-> ConnectToArgs fd addr vNumber vData

a configured socket to use to connect to a remote service provider

-> Versions vNumber vData (OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)

application to run over the connection

-> fd 
-> IO (Either SomeException (Either a b)) 

Connect to a remote node using an existing socket. It is up to to caller to ensure that the socket is closed in case of an exception.

The connection will start with handshake protocol sending Versions to the remote peer. It must fit into maxTransmissionUnit (~5k bytes).

Exceptions thrown by MuxApplication are rethrown by connectTo.

connectToNodeWithMux' Source #

Arguments

:: forall (muxMode :: Mode) vNumber vData fd addr a b x. (Ord vNumber, Typeable vNumber, Show vNumber, HasInitiator muxMode ~ 'True) 
=> Snocket IO fd addr 
-> MakeBearer IO fd 
-> ConnectToArgs fd addr vNumber vData 
-> Versions vNumber vData (OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b)

application to run over the connection ^ a configured socket to use to connect to a remote service provider

-> fd 
-> (ConnectionId addr -> vNumber -> vData -> OuroborosApplicationWithMinimalCtx muxMode addr ByteString IO a b -> Mux muxMode IO -> Async IO () -> IO x)

callback which has access to ConnectionId, negotiated protocols, mux handle created for that connection and an Async handle to the thread which runs runMux. The Mux handle allows schedule mini-protocols.

NOTE: when the callback returns or errors, the mux thread will be killed.

-> IO x 

Socket configuration

configureSocket :: Socket -> Maybe SockAddr -> IO () Source #

Configure a socket. Either AF_INET or AF_INET6 socket is expected.

configureSystemdSocket :: Tracer IO SystemdSocketTracer -> Socket -> SockAddr -> IO () Source #

Configure sockets passed through systemd socket activation. Currently ReuseAddr and Linger options are not configurable with 'systemd.socket', these options are set by this function. For other socket options we only trace if they are not set.

Traces

data NetworkConnectTracers addr vNumber Source #

Tracer used by connectToNode (and derivatives, like connectTo or 'Ouroboros.Network.NodeToClient.connectTo).

Constructors

NetworkConnectTracers 

Fields

Re-export of HandshakeCallbacks

data HandshakeCallbacks vData #

A record that holds handshake callbacks.

Constructors

HandshakeCallbacks 

Fields

Re-export connection table functions

addConnection Source #

Arguments

:: forall (m :: Type -> Type) addr. (MonadSTM m, Ord addr) 
=> ConnectionTable m addr 
-> addr 
-> addr 
-> ConnectionDirection 
-> Maybe (ValencyCounter m)

Optional ValencyCounter, used by subscription worker and set to Nothing when called by a local server.

-> STM m () 

Insert a new connection into the ConnectionTable.

removeConnection :: (MonadSTM m, Ord addr) => ConnectionTable m addr -> addr -> addr -> ConnectionDirection -> m () Source #

newValencyCounter Source #

Arguments

:: forall (m :: Type -> Type) addr. MonadSTM m 
=> ConnectionTable m addr 
-> Int

Desired valency, that is number of connections a subscription worker will attempt to maintain.

-> STM m (ValencyCounter m) 

Create a new ValencyCounter

addValencyCounter :: forall (m :: Type -> Type). MonadSTM m => ValencyCounter m -> STM m () Source #

Add a connection.

remValencyCounter :: forall (m :: Type -> Type). MonadSTM m => ValencyCounter m -> STM m () Source #

Remove a connection.

waitValencyCounter :: forall (m :: Type -> Type). MonadSTM m => ValencyCounter m -> STM m () Source #

Wait until ValencyCounter becomes positive, used for detecting when we can create new connections.

readValencyCounter :: forall (m :: Type -> Type). MonadSTM m => ValencyCounter m -> STM m Int Source #

Returns current ValencyCounter value, represent the number of additional connections that can be created. May be negative.

Auxiliary functions

simpleMuxCallback :: forall (muxMode :: Mode) addr vNumber vData m a b. (Alternative (STM m), MonadAsync m, MonadSTM m, MonadThrow m, MonadThrow (STM m)) => ConnectionId addr -> vNumber -> vData -> OuroborosApplicationWithMinimalCtx muxMode addr ByteString m a b -> Mux muxMode m -> Async m () -> m (Either SomeException (Either a b)) Source #

An internal mux callback which starts all mini-protocols and blocks until the first one terminates. It returns the result (or error) of the first terminated mini-protocol.

Orphan instances

Hashable SockAddr Source # 
Instance details

Methods

hashWithSalt :: Int -> SockAddr -> Int #

hash :: SockAddr -> Int #