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

LibP2P.NAT.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 LibP2P.NAT.Relay

Eq RelayConfig Source # 
Instance details

Defined in LibP2P.NAT.Relay

data RelayState Source #

Mutable relay server state.

Constructors

RelayState 

Fields

data ActiveReservation Source #

An active reservation for a peer.

Constructors

ActiveReservation 

Fields

data HopContext Source #

Per-request context for the hop handlers: the relay's own identity (used to sign reservation vouchers), its public addresses (advertised in the reservation), and the address the requesting connection arrived over (used to refuse requests over already-relayed connections).

Constructors

HopContext 

Fields

Configuration

defaultRelayConfig :: RelayConfig Source #

Default relay configuration.

State management

newRelayState :: RelayConfig -> IO RelayState Source #

Create new relay state from configuration.

Handlers

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

Handle a RESERVE request from a peer.

handleConnect :: RelayState -> HopContext -> 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, then closes both streams so neither end is left with a half-open circuit.

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 whether raw multiaddr bytes describe a relayed connection. Decodes the bytes structurally: the p2p-circuit byte pattern occurring inside another component (e.g. a peer ID) does not count, unlike the previous substring heuristic. Undecodable bytes are not relayed.

isRelayedAddr :: Multiaddr -> Bool Source #

Check whether a multiaddr contains a p2p-circuit component.

Voucher constants

relayRsvpDomain :: ByteString Source #

Domain separation string for reservation voucher envelopes (circuit-v2).

relayRsvpPayloadType :: ByteString Source #

Multicodec payload type for reservation vouchers (0x0302).