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

Network.LibP2P.NAT.Relay.Relay

Description

Circuit Relay v2 server: manage reservations and bridge streams.

Protocols: libp2pcircuitrelay0.2.0/hop (client ↔ relay)

Provides: - Reservation management (with expiration and limits) - Stream bridging between source and target - Resource limits (max reservations, max circuits, data/duration limits)

Synopsis

Types

data RelayConfig Source #

Relay server configuration.

Constructors

RelayConfig 

Fields

Instances

Instances details
Show RelayConfig Source # 
Instance details

Defined in Network.LibP2P.NAT.Relay.Relay

Eq RelayConfig Source # 
Instance details

Defined in Network.LibP2P.NAT.Relay.Relay

data RelayState Source #

Mutable relay server state.

data ActiveReservation Source #

An active reservation for a peer.

Constructors

ActiveReservation 

Fields

Configuration

defaultRelayConfig :: RelayConfig Source #

Default relay configuration.

State management

newRelayState :: RelayConfig -> IO RelayState Source #

Create new relay state from configuration.

Handlers

handleReserve :: RelayState -> StreamIO -> PeerId -> IO () Source #

Handle a RESERVE request from a peer.

handleConnect :: RelayState -> StreamIO -> PeerId -> HopMessage -> (PeerId -> IO (Maybe StreamIO)) -> IO () Source #

Handle a CONNECT request from a peer. The openStopStream callback is used to open a stop stream to the target.

Stream bridging

bridgeStreams :: Maybe RelayLimit -> StreamIO -> StreamIO -> IO () Source #

Bridge two streams bidirectionally with optional data/duration limits. Terminates when either direction closes or limits are exceeded.

Relay address helpers

buildRelayAddrBytes :: ByteString -> ByteString -> ByteString -> ByteString Source #

Build a relay multiaddr in binary format. Format: relayAddrp2prelayIdp2p-circuitp2p/targetId

isRelayedConnection :: ByteString -> Bool Source #

Check if raw multiaddr bytes contain P2PCircuit (code 290). Simple heuristic: look for the varint encoding of 290.