| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- newSession :: SessionRole -> (ByteString -> IO ()) -> (Int -> IO ByteString) -> IO YamuxSession
- closeSession :: YamuxSession -> IO ()
- openStream :: YamuxSession -> IO (Either YamuxError YamuxStream)
- acceptStream :: YamuxSession -> IO (Either YamuxError YamuxStream)
- ping :: YamuxSession -> IO (Either YamuxError ())
- sendGoAway :: YamuxSession -> GoAwayCode -> IO ()
- recvLoop :: YamuxSession -> IO ()
- sendLoop :: YamuxSession -> IO ()
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.