| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.NAT.AutoNAT
Description
AutoNAT v1 service: detect NAT status by asking remote peers to dial back.
Protocol: libp2pautonat/1.0.0 Flow: Client sends DIAL with addresses, server dials back, responds with result.
Security rules (from specs/autonat): - Server MUST NOT dial addresses unless they match the requester's observed IP (both IPv4 and IPv6; if the observed IP cannot be determined, refuse) - Server MUST NOT accept dial requests over relayed connections - Server rejects requests whose claimed peer id differs from the authenticated peer id of the connection
Synopsis
- data NATStatus
- data AutoNATConfig = AutoNATConfig {
- natThreshold :: !Int
- natDialBack :: !(PeerId -> [Multiaddr] -> IO (Either String Multiaddr))
- maxDialBackAddrs :: Int
- handleAutoNAT :: AutoNATConfig -> StreamIO -> PeerId -> Multiaddr -> IO ()
- requestAutoNAT :: StreamIO -> PeerId -> [Multiaddr] -> IO (Either String AutoNATDialResponse)
- probeNATStatusPure :: Int -> [Either String AutoNATDialResponse] -> NATStatus
Types
Detected NAT status.
Constructors
| NATPublic | |
| NATPrivate | |
| NATUnknown |
data AutoNATConfig Source #
AutoNAT configuration.
Constructors
| AutoNATConfig | |
Fields
| |
maxDialBackAddrs :: Int Source #
Maximum number of addresses dialled back per request. Bounds the work a single request can trigger (go-libp2p applies a similar per-request address cap).
Server
handleAutoNAT :: AutoNATConfig -> StreamIO -> PeerId -> Multiaddr -> IO () Source #
Server handler: receive DIAL, validate, dial back, respond.
Security: - Rejects requests from relayed connections (P2PCircuit in observed addr) - Filters dial-back addresses to match observed IP
AutoNAT is a one-shot exchange, so the stream is closed on every exit path (go-libp2p's handleStream uses defer s.Close()).
Client
requestAutoNAT :: StreamIO -> PeerId -> [Multiaddr] -> IO (Either String AutoNATDialResponse) Source #
Client: send DIAL with local addresses, receive response.
One-shot: the stream is closed after the exchange on every exit path, matching go-libp2p's AutoNAT client (defer s.Close()).
NAT status aggregation
probeNATStatusPure :: Int -> [Either String AutoNATDialResponse] -> NATStatus Source #
Pure aggregation of AutoNAT results into a NAT status.
Only a remote dial report counts as a vote: StatusOK is public,
EDialError is private. Local failures (Left), refusals, and
malformed responses are abstentions (specs/autonat: infer from
successful or unsuccessful *dial reports*). A decision requires
strictly more than threshold agreeing votes.