| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- data SessionRole
- data StreamState
- data YamuxError
- data YamuxStream = YamuxStream {
- ysStreamId :: !Word32
- ysState :: !(TVar StreamState)
- ysSendWindow :: !(TVar Word32)
- ysRecvWindow :: !(TVar Word32)
- ysRecvBuf :: !(TQueue ByteString)
- ysSendNotify :: !(TMVar ())
- ysMemoryAccount :: !MemoryAccount
- ysSession :: !YamuxSession
- data YamuxSession = YamuxSession {
- ysessConfig :: !YamuxConfig
- ysessRole :: !SessionRole
- ysessNextStreamId :: !(TVar Word32)
- ysessStreams :: !(TVar (Map Word32 YamuxStream))
- ysessAcceptCh :: !(TBQueue YamuxStream)
- ysessSendCh :: !(TQueue (YamuxHeader, ByteString, Maybe MemoryAccount))
- ysessConnectionMemory :: !MemoryAccount
- ysessInboundMemory :: !(STM (Either ResourceError MemoryAccount))
- ysessOutboundMemory :: !(STM (Either ResourceError MemoryAccount))
- ysessShutdown :: !(TVar Bool)
- ysessRemoteGoAway :: !(TVar (Maybe GoAwayCode))
- ysessPings :: !(TVar (Map Word32 PingWaiter))
- ysessNextPingId :: !(TVar Word32)
- ysessQueuedCount :: !(TVar Word64)
- ysessSentCount :: !(TVar Word64)
- ysessRecvCount :: !(TVar Word64)
- ysessWrite :: !(ByteString -> IO ())
- ysessRead :: !(Int -> IO ByteString)
- type PingWaiter = TMVar (Either YamuxError ())
- data Micros
- mkMicros :: Int -> Maybe Micros
- microsToInt :: Micros -> Int
- data YamuxConfig = YamuxConfig {
- ycKeepAlive :: !(Maybe Micros)
- ycPingTimeout :: !Micros
- defaultYamuxConfig :: YamuxConfig
- enqueueFrame :: YamuxSession -> YamuxHeader -> ByteString -> STM ()
- enqueueDataFrame :: YamuxSession -> MemoryAccount -> YamuxHeader -> ByteString -> STM (Either ResourceError Word64)
- enqueueFrameNumbered :: YamuxSession -> YamuxHeader -> ByteString -> STM Word64
- awaitFrameWritten :: YamuxSession -> Word64 -> STM ()
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
| Show SessionRole Source # | |
Defined in LibP2P.Yamux.Types Methods showsPrec :: Int -> SessionRole -> ShowS # show :: SessionRole -> String # showList :: [SessionRole] -> ShowS # | |
| Eq SessionRole Source # | |
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
| Show StreamState Source # | |
Defined in LibP2P.Yamux.Types Methods showsPrec :: Int -> StreamState -> ShowS # show :: StreamState -> String # showList :: [StreamState] -> ShowS # | |
| Eq StreamState Source # | |
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
| Show YamuxError Source # | |
Defined in LibP2P.Yamux.Types Methods showsPrec :: Int -> YamuxError -> ShowS # show :: YamuxError -> String # showList :: [YamuxError] -> ShowS # | |
| Eq YamuxError Source # | |
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.
A strictly positive duration in microseconds.
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
| Show YamuxConfig Source # | |
Defined in LibP2P.Yamux.Types Methods showsPrec :: Int -> YamuxConfig -> ShowS # show :: YamuxConfig -> String # showList :: [YamuxConfig] -> ShowS # | |
| Eq YamuxConfig Source # | |
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.