natsense

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package natsense implements observed address consensus (spec Phase 2a: ≥3 distinct reporters). For tests or small networks, set MinAgreeingPeers to 1.

Index

Constants

View Source
const (
	NATUnknown      uint8 = 0
	NATFullCone     uint8 = 1
	NATRestricted   uint8 = 2
	NATPortRestrict uint8 = 3
	NATSymmetric    uint8 = 4
)

NAT type constants (mirror protocol.NAT* for convenience).

Variables

This section is empty.

Functions

This section is empty.

Types

type Sense

type Sense struct {
	// contains filtered or unexported fields
}

Sense tracks distinct peers that reported the same reflected UDP endpoint (wire bytes) and infers NAT type from both passive mapping observation and active probe results.

func NewSense

func NewSense(minAgreeingPeers int) *Sense

NewSense returns a consensus tracker. If minAgreeingPeers <= 0, default 3 is used.

func (*Sense) ClearProbeResult added in v0.1.4

func (s *Sense) ClearProbeResult()

ClearProbeResult discards cached active-probe classification so the next probe result is used immediately after network changes.

func (*Sense) InferNATType

func (s *Sense) InferNATType() uint8

InferNATType returns the current best NAT classification for hole-punch strategy.

Decision flow:

  1. Public bind (QUIC socket on a WAN IP) → NATFullCone (wire-compatible; host exposes IsBindPublic() for UI to show "public" separately).
  2. Symmetric mapping: ≥2 well-supported observed ports → NATSymmetric.
  3. Insufficient passive evidence → NATUnknown.
  4. Active probe result (RecordProbeResult): reachable=true → NATFullCone (any peer can initiate; Full Cone or cloud NAT) reachable=false → NATRestricted
  5. No probe result yet → NATRestricted (conservative default).

func (*Sense) InvalidateObservations added in v0.1.4

func (s *Sense) InvalidateObservations()

InvalidateObservations clears passive observed_addr votes after confirmed network changes so old mappings do not bias the next consensus cycle.

func (*Sense) IsBindPublic added in v0.1.4

func (s *Sense) IsBindPublic() bool

IsBindPublic returns true when the local socket has a direct public WAN IP.

func (*Sense) MinAgreeing

func (s *Sense) MinAgreeing() int

MinAgreeing returns the configured threshold.

func (*Sense) Record

func (s *Sense) Record(reporter a2al.NodeID, observed []byte)

Record adds one vote: reporter saw our endpoint as observed (wire encoding).

func (*Sense) RecordBindPublic added in v0.1.4

func (s *Sense) RecordBindPublic(isPublic bool)

RecordBindPublic records whether the local UDP socket is bound to a public WAN IP. Called by host.RunNATProbe after inspecting the QUIC listen address.

func (*Sense) RecordProbeResult added in v0.1.4

func (s *Sense) RecordProbeResult(reachable bool)

RecordProbeResult records the outcome of an active AutoNAT-style reachability probe. reachable=true means at least one remote peer successfully sent an echo to our claimed external address (Full Cone or equivalent); false means Restricted.

func (*Sense) SetMinAgreeing

func (s *Sense) SetMinAgreeing(n int)

SetMinAgreeing updates the threshold (e.g. 1 for integration tests).

func (*Sense) TrustedUDP

func (s *Sense) TrustedUDP() (host string, port uint16, ok bool)

TrustedUDP returns host and port if some observed key has >= min distinct reporters whose votes are younger than voteTTL.

func (*Sense) TrustedWire

func (s *Sense) TrustedWire() ([]byte, bool)

TrustedWire returns the first trusted observed_addr wire form (6 or 18 bytes).

Jump to

Keyboard shortcuts

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