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

LibP2P.NAT

Description

NAT traversal handler registration (specsautonat, specsrelay, specsrelayDCUtR).

Wires the AutoNAT, Circuit Relay v2, and DCUtR module implementations into the Switch protocol registry, in the style of registerIdentifyHandlers:

libp2pautonat/1.0.0 — AutoNAT dial-back server libp2pcircuitrelay0.2.0/hop — Circuit Relay v2 relay server libp2pcircuitrelay0.2.0/stop — Circuit Relay v2 target (inbound relayed streams) libp2pdcutr — DCUtR hole-punch coordination (handler side)

Synopsis

Configuration

data NATConfig Source #

Configuration for the NAT traversal handlers.

Constructors

NATConfig 

Fields

  • ncRelayConfig :: !RelayConfig

    Resource limits for the Circuit Relay v2 server side

  • ncOnRelayedStream :: !(PeerId -> Maybe RelayLimit -> StreamIO -> IO ())

    Invoked when a relay delivers an inbound relayed stream (stop protocol) after the CONNECT/OK exchange: source peer, limit advertised by the relay, and the relayed stream. The application owns the stream from this point (e.g. to run DCUtR over it).

defaultNATConfig :: NATConfig Source #

Default NAT configuration: default relay limits, and inbound relayed streams are left to the remote end (no local consumer).

Registration

registerNATHandlers :: Switch -> NATConfig -> IO RelayState Source #

Register all four NAT protocol handlers on the Switch.

Creates the relay server state from ncRelayConfig and returns it so callers can inspect reservations/circuits.

registerAutoNATHandler :: Switch -> IO () Source #

Register the AutoNAT server handler (libp2pautonat/1.0.0).

The dial-back deliberately bypasses the connection pool: reusing the requester's existing connection would always report success. Instead a fresh transport dial + upgrade verifies both reachability and identity, and the probe connection is closed immediately (go-libp2p uses a separate dialer host for the same reason).

registerRelayHopHandler :: Switch -> RelayState -> IO () Source #

Register the Circuit Relay v2 hop handler (libp2pcircuitrelay0.2.0/hop): serve RESERVE and CONNECT requests.

registerRelayStopHandler :: Switch -> (PeerId -> Maybe RelayLimit -> StreamIO -> IO ()) -> IO () Source #

Register the Circuit Relay v2 stop handler (libp2pcircuitrelay0.2.0/stop): accept inbound relayed streams and hand them to the application callback.

registerDCUtRHandler :: Switch -> IO () Source #

Register the DCUtR handler (libp2pdcutr).

Answers the CONNECT/SYNC exchange with our listen addresses and dials the initiator's addresses through the Switch for the hole punch.