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
- type Sense
- func (s *Sense) ClearProbeResult()
- func (s *Sense) InferNATType() uint8
- func (s *Sense) InvalidateObservations()
- func (s *Sense) IsBindPublic() bool
- func (s *Sense) MinAgreeing() int
- func (s *Sense) Record(reporter a2al.NodeID, observed []byte)
- func (s *Sense) RecordBindPublic(isPublic bool)
- func (s *Sense) RecordProbeResult(reachable bool)
- func (s *Sense) SetMinAgreeing(n int)
- func (s *Sense) TrustedUDP() (host string, port uint16, ok bool)
- func (s *Sense) TrustedWire() ([]byte, bool)
Constants ¶
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 (*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 ¶
InferNATType returns the current best NAT classification for hole-punch strategy.
Decision flow:
- Public bind (QUIC socket on a WAN IP) → NATFullCone (wire-compatible; host exposes IsBindPublic() for UI to show "public" separately).
- Symmetric mapping: ≥2 well-supported observed ports → NATSymmetric.
- Insufficient passive evidence → NATUnknown.
- Active probe result (RecordProbeResult): reachable=true → NATFullCone (any peer can initiate; Full Cone or cloud NAT) reachable=false → NATRestricted
- 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
IsBindPublic returns true when the local socket has a direct public WAN IP.
func (*Sense) MinAgreeing ¶
MinAgreeing returns the configured threshold.
func (*Sense) RecordBindPublic ¶ added in v0.1.4
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
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 ¶
SetMinAgreeing updates the threshold (e.g. 1 for integration tests).
func (*Sense) TrustedUDP ¶
TrustedUDP returns host and port if some observed key has >= min distinct reporters whose votes are younger than voteTTL.
func (*Sense) TrustedWire ¶
TrustedWire returns the first trusted observed_addr wire form (6 or 18 bytes).