natsense

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MPL-2.0 Imports: 5 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 a basic NAT type from observed port consistency.

func NewSense

func NewSense(minAgreeingPeers int) *Sense

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

func (*Sense) InferNATType

func (s *Sense) InferNATType() uint8

InferNATType returns a basic NAT type inference based on observed port consistency across reporters (spec Phase 2a):

  • All reporters saw the same port → endpoint-independent mapping (FullCone/Restricted)
  • Different ports → NATSymmetric
  • Insufficient data → NATUnknown

Distinguishing FullCone from Restricted requires active probing (Phase 2b).

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) 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.

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