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

Network.LibP2P.Mux.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 ysSendCh, 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 if the session has sent or received 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 ysShutdown 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.

sendLoop :: YamuxSession -> IO () Source #

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