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

LibP2P.NAT.Relay.Limit

Description

Client-side enforcement of a relay-advertised circuit budget.

specsrelaycircuit-v2: the relay counts bytes on the relayed connection itself (the byte stream after the hop or stop handshake), separately in each direction, and resets both sides when either direction exceeds data or the circuit has been open for duration. A component of 0, or an absent component, is unlimited. An omitted limit means the relay applies none.

This wrapper charges that same stream. A write that does not fit is not sent. A read never consumes a byte past the cap. Once either budget is exhausted the underlying stream is closed and every later read or write throws RelayCircuitExhausted, rather than waiting for the relay's reset to surface as an opaque transport failure.

Synopsis

Documentation

toRelayCircuitLimit :: RelayLimit -> RelayCircuitLimit Source #

Copy a relay protobuf limit into the transport-level budget.

enforceRelayCircuitLimit :: Maybe RelayCircuitLimit -> StreamIO -> IO StreamIO Source #

Charge stream against mLimit. A missing or inactive budget (every component 0 or absent) is returned unchanged. The duration clock starts when this returns, which is when the hop or stop handshake has completed and the stream has become the circuit.