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

LibP2P.Yamux.Types

Description

Shared types for Yamux session management.

Types follow the HashiCorp yamux spec.md. SessionRole determines stream ID parity, StreamState tracks the stream lifecycle state machine, and YamuxSession/YamuxStream hold per-session/per-stream mutable state via STM.

Synopsis

Documentation

data SessionRole Source #

SessionRole determines stream ID parity (spec.md §Stream Identification). Client uses odd IDs (1, 3, 5, ...), Server uses even IDs (2, 4, 6, ...).

Constructors

RoleClient 
RoleServer 

Instances

Instances details
Show SessionRole Source # 
Instance details

Defined in LibP2P.Yamux.Types

Eq SessionRole Source # 
Instance details

Defined in LibP2P.Yamux.Types

data StreamState Source #

Stream state machine (spec.md §Stream OpenCloseReset). States map to the spec's lifecycle: SYN sentreceived -> Established -> FIN sentreceived -> Closed

Constructors

StreamSYNSent

SYN sent, awaiting ACK (initiator)

StreamSYNReceived

SYN received, awaiting local ACK (responder)

StreamEstablished

Both SYN/ACK exchanged, data flows

StreamLocalClose

Local FIN sent (half-closed)

StreamRemoteClose

Remote FIN received (half-closed)

StreamClosed

Both FIN'd

StreamReset

RST sent or received

Instances

Instances details
Show StreamState Source # 
Instance details

Defined in LibP2P.Yamux.Types

Eq StreamState Source # 
Instance details

Defined in LibP2P.Yamux.Types

data YamuxError Source #

Errors map to spec-defined conditions.

Constructors

YamuxProtocolError !String

Spec violation (e.g., invalid version, unknown frame type)

YamuxStreamClosed

Write/read on closed stream

YamuxStreamReset

RST received

YamuxSessionShutdown

GoAway received or session closed

YamuxGoAway !GoAwayCode

Remote sent GoAway with specific code

YamuxPingTimeout

Ping SYN not written, or its ACK not received, in time

YamuxResourceLimit !ResourceError

Stream buffer reservation failed

Instances

Instances details
Show YamuxError Source # 
Instance details

Defined in LibP2P.Yamux.Types

Eq YamuxError Source # 
Instance details

Defined in LibP2P.Yamux.Types

data YamuxStream Source #

Per-stream state (spec.md §Flow Control: per-stream windows only).

Constructors

YamuxStream 

Fields

data YamuxSession Source #

Session state.

Constructors

YamuxSession 

Fields

type PingWaiter = TMVar (Either YamuxError ()) Source #

Result delivered to a pending ping waiter: Right on a matching ACK, Left when the session dies before the ACK arrives.

data Micros Source #

A strictly positive duration in microseconds.

Instances

Instances details
Show Micros Source # 
Instance details

Defined in LibP2P.Yamux.Types

Eq Micros Source # 
Instance details

Defined in LibP2P.Yamux.Types

Methods

(==) :: Micros -> Micros -> Bool #

(/=) :: Micros -> Micros -> Bool #

Ord Micros Source # 
Instance details

Defined in LibP2P.Yamux.Types

mkMicros :: Int -> Maybe Micros Source #

Accept a positive number of microseconds, reject anything else.

microsToInt :: Micros -> Int Source #

The duration in microseconds, as System.Timeout.timeout takes it.

data YamuxConfig Source #

Session tunables that spec.md leaves to the implementation.

Constructors

YamuxConfig 

Fields

Instances

Instances details
Show YamuxConfig Source # 
Instance details

Defined in LibP2P.Yamux.Types

Eq YamuxConfig Source # 
Instance details

Defined in LibP2P.Yamux.Types

enqueueFrame :: YamuxSession -> YamuxHeader -> ByteString -> STM () Source #

Queue a frame for sendLoop to write. Every outbound frame goes through here, so this is the one place that sees each frame as it enters the send queue.

enqueueDataFrame :: YamuxSession -> MemoryAccount -> YamuxHeader -> ByteString -> STM (Either ResourceError Word64) Source #

Reserve a payload while it waits in the outbound queue.

enqueueFrameNumbered :: YamuxSession -> YamuxHeader -> ByteString -> STM Word64 Source #

Like enqueueFrame, returning the frame's number. Frames are numbered from 1 in queue order, in the same transaction that queues them, so the number also tells how many frames sendLoop must write before this one is out (see awaitFrameWritten).

The counters are Word64, which cannot wrap in practice (about 58,000 years at 10M frames/s), so frame numbers are compared directly.

awaitFrameWritten :: YamuxSession -> Word64 -> STM () Source #

Block until sendLoop has finished writing the frame with the given number to the transport.