libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.Yamux.Session

Description

Yamux session management: create, openStream, acceptStream, ping, goaway.

Implements the session-level Yamux protocol per HashiCorp yamux spec.md. The session manages a collection of multiplexed streams over a single underlying transport connection.

Two background loops run per session: recvLoop: reads 12-byte headers from transport, dispatches to streams sendLoop: dequeues from ysessSendCh, writes to transport

Synopsis

Documentation

newSession :: SessionRole -> (ByteString -> IO ()) -> (Int -> IO ByteString) -> IO YamuxSession Source #

Create a new Yamux session over a transport connection. Client uses odd stream IDs starting at 1, server uses even starting at 2.

closeSession :: YamuxSession -> IO () Source #

Gracefully close the session by sending GoAway Normal.

openStream :: YamuxSession -> IO (Either YamuxError YamuxStream) Source #

Open a new outbound stream. Allocates the next stream ID and sends SYN. Returns YamuxSessionShutdown after a local GoAway, or YamuxGoAway with the received code after a remote GoAway.

acceptStream :: YamuxSession -> IO (Either YamuxError YamuxStream) Source #

Accept an inbound stream. Blocks until a remote SYN arrives. Returns YamuxSessionShutdown if the session is shut down.

ping :: YamuxSession -> IO (Either YamuxError ()) Source #

Send a Ping and wait for the ACK response. Ping uses StreamID 0 and the Length field carries an opaque value.

sendGoAway :: YamuxSession -> GoAwayCode -> IO () Source #

Send a GoAway frame with the specified error code. Sets ysessShutdown to True so no new streams can be opened.

recvLoop :: YamuxSession -> IO () Source #

Receive loop: reads 12-byte headers from transport and dispatches frames. This loop runs until the transport connection is closed or an error occurs.

Whenever the loop terminates -- transport EOF or error (ysessRead throws), a fatal protocol error, or cancellation -- the session is torn down via failSession so that no reader, writer or ping waiter is left blocked forever on a session that can no longer make progress.

sendLoop :: YamuxSession -> IO () Source #

Send loop: dequeues frames from ysessSendCh and writes to transport.

acceptBacklog :: Natural Source #

Maximum number of inbound streams buffered while the application is not accepting (go-yamux AcceptBacklog). The spec requires this buffer to be bounded to mitigate DoS; excess SYNs are reset.