natmap

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MPL-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package natmap provides optional NAT helpers (Phase 2b: UPnP IGD port mapping). TURN and other relays are out of scope until Phase 3+.

IPv6 note: UPnP IGD is an IPv4 NAT mechanism. Nodes with a globally routable IPv6 address are directly reachable without any port mapping and do not use this package. UPnP mapping is only attempted when the node's public address is obtained via STUN or natsense and the socket is behind an IPv4 NAT.

Index

Constants

View Source
const Description = "a2al-quic"

Description is written into PortMappingDescription so we can verify ownership before DeletePortMapping (IGD delete is keyed only by ext-port + protocol).

View Source
const LeaseSeconds = 3600

LeaseSeconds is the IGD lease duration requested on AddPortMapping.

Variables

This section is empty.

Functions

func LocalIPv4ForUPnP

func LocalIPv4ForUPnP() string

LocalIPv4ForUPnP returns an IPv4 address suitable as IGD "internal client" (typically the LAN address used for outbound UDP).

func Ours added in v0.3.1

func Ours(wantInternalPort int, wantClient string, gotInternalPort uint16, gotClient string, enabled bool, desc string) bool

Ours reports whether a GetSpecificPortMappingEntry result is owned by this process's registration (same client, internal port, and a2al description). Empty description → not ours (strict: never delete unverified entries).

func QUICURL

func QUICURL(host string, port int) string

QUICURL builds a quic:// URL for an endpoint string (host + port).

func RenewUDPPort added in v0.3.1

func RenewUDPPort(ctx context.Context, extPort, internalPort int, internalClient string) (externalIP string, lease time.Duration, err error)

RenewUDPPort refreshes an existing mapping on extPort (same internal binding) and returns the current IGD external IP plus lease duration.

Types

type Mapping added in v0.3.1

type Mapping struct {
	ExternalIP     string
	ExternalPort   int
	InternalPort   int
	InternalClient string
	Lease          time.Duration
	// contains filtered or unexported fields
}

Mapping is one successfully registered UDP port forward on the LAN IGD.

func MapUDPPort

func MapUDPPort(ctx context.Context, internalPort int, internalClient string) (*Mapping, error)

MapUDPPort asks the LAN IGD to forward UDP externalPort -> internalClient:internalPort using the same port number on the WAN side when possible (predictable QUIC URLs). Cleanup verifies ownership before DeletePortMapping.

func (*Mapping) Cleanup added in v0.3.1

func (m *Mapping) Cleanup()

Cleanup deletes this mapping only after verifying it is still ours. Safe to call multiple times.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL