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
- func LocalIPv4ForUPnP() string
- func Ours(wantInternalPort int, wantClient string, gotInternalPort uint16, ...) bool
- func QUICURL(host string, port int) string
- func RenewUDPPort(ctx context.Context, extPort, internalPort int, internalClient string) (externalIP string, lease time.Duration, err error)
- type Mapping
Constants ¶
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).
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 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 ¶
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.