Documentation
¶
Overview ¶
Package discovery wires the LAN (mDNS) and global (DHT) peer-discovery backends behind a unified Manager. FindPeer probes mDNS first for speed, then falls back to iterative DHT lookup; both backends feed a deduplicated peer channel.
DHT records are authenticated (signed) — not hash-only ¶
PeerRecord carries (node_id, address, onion_address, timestamp, dilithium_pub, signature). The Dilithium public key and a signature over the canonical record bytes were added by the signed-PeerRecord change: recipients verify the pubkey hashes to the claimed address and the signature is valid before trusting a record, so a record can no longer be spoofed for an address you don't own nor an old one replayed past its freshness window. Publishing the pubkey is safe under the post-quantum identity design — addresses are RIPEMD-160(SHA-256(dilithium_pub)) and Dilithium pubkeys are PQ-safe, so it does not weaken identity confidentiality.
The accepted cost is correlation: a full DHT scrape now yields a global (address → Dilithium pubkey) table. That is judged acceptable because the pubkey is PQ-safe and identity is re-verified on the wire at handshake time regardless. Two operational mitigations bound the surface (ticket 942315f4):
- The DHT is a routing layer, not an authorization layer. A signed record authenticates "this address announced this onion at this time"; it grants nothing. Connection authorization still happens at the handshake, where CONN_REQUEST is verified before any user prompt.
- Self-records are signed once and cached for selfRecordSignTTL rather than re-signed on every FIND_NODE (ML-DSA-65 signing is expensive and an unauthenticated peer can spam FIND_NODE — per-request signing would be a CPU-amplification DoS), and a FIND_NODE returns a co-hosted service's record only when the query targets that service's node ID, never the full co-hosted set on every request.
Note: over Tor every inbound DHT connection arrives from the local Tor daemon (loopback), so per-remote rate-limiting is not meaningful — all peers are indistinguishable at the socket. The signature cache, not a per-IP limiter, is what closes the FIND_NODE CPU-amplification vector.
Index ¶
- Constants
- func CommonPrefixLen(a, b NodeID) int
- func DefaultSeeds() []string
- func IsV3OnionAddr(s string) bool
- func ParseSeedNodes(s string) ([]string, error)
- func PeerRecordCanonicalBytes(nodeID []byte, address, onion string, timestamp int64) []byte
- type DHTDiscovery
- func (d *DHTDiscovery) AddLocalIdentity(addr, onion string, signer *identity.Identity) error
- func (d *DHTDiscovery) Announce(ctx context.Context) error
- func (d *DHTDiscovery) AnnounceIdentity(ctx context.Context, addr string) error
- func (d *DHTDiscovery) Bootstrap(ctx context.Context, onionAddr string) (int, error)
- func (d *DHTDiscovery) HandleConn(conn net.Conn)
- func (d *DHTDiscovery) HandleEnvelope(conn net.Conn, env *pb.Envelope)
- func (d *DHTDiscovery) Lookup(ctx context.Context, addr string) (*PeerInfo, error)
- func (d *DHTDiscovery) ProbeStalePeers(ctx context.Context, olderThan, recheck time.Duration, concurrency int) (alive, dead int)
- func (d *DHTDiscovery) RT() *RoutingTable
- func (d *DHTDiscovery) RemoveLocalIdentity(addr string) bool
- func (d *DHTDiscovery) SetFailureThreshold(n int)
- func (d *DHTDiscovery) SetOnRTMutation(fn func())
- func (d *DHTDiscovery) SetPutVerifyLimiter(l *rate.Limiter)
- type Dialer
- type MDNSDiscovery
- type Manager
- func (m *Manager) AddLocalIdentity(addr, onion string, signer *identity.Identity) error
- func (m *Manager) AddNode(ctx context.Context, onionAddr string) (int, error)
- func (m *Manager) EvictStale() int
- func (m *Manager) FindPeer(ctx context.Context, addr string) (*PeerInfo, error)
- func (m *Manager) ListPeers() []*PeerInfo
- func (m *Manager) MarkDirty()
- func (m *Manager) PeerChan() <-chan *PeerInfo
- func (m *Manager) RTSize() int
- func (m *Manager) RemoveLocalIdentity(addr string)
- func (m *Manager) SetRTMaxAge(d time.Duration)
- func (m *Manager) SetRTPath(path string)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) StartAnnounceLoop(ctx context.Context)
- func (m *Manager) StartPruneLoop(ctx context.Context)
- func (m *Manager) StartSaveLoop(ctx context.Context)
- func (m *Manager) Stop()
- type NodeID
- type PeerInfo
- type RoutingTable
- func (rt *RoutingTable) AddPeer(peer *PeerInfo, source NodeID) bool
- func (rt *RoutingTable) AllPeers() []*PeerInfo
- func (rt *RoutingTable) Evict(maxAge time.Duration) int
- func (rt *RoutingTable) EvictByFailures(threshold int) []*PeerInfo
- func (rt *RoutingTable) FindClosest(target NodeID, count int) []*PeerInfo
- func (rt *RoutingTable) Load(path string) error
- func (rt *RoutingTable) Local() NodeID
- func (rt *RoutingTable) PeersForProbe(olderThan, recheck time.Duration) []*PeerInfo
- func (rt *RoutingTable) RecordFailure(onionAddr string) int
- func (rt *RoutingTable) RecordFatal(onionAddr string) int
- func (rt *RoutingTable) RecordProbeOK(onionAddr string)
- func (rt *RoutingTable) RecordSuccess(onionAddr string)
- func (rt *RoutingTable) RemovePeer(addr string) bool
- func (rt *RoutingTable) Save(path string) error
- func (rt *RoutingTable) Size() int
Constants ¶
const ( // RecordTTL is the maximum age of a DHT record before it's considered expired. RecordTTL = 24 * time.Hour // LookupMaxIterations is the maximum rounds of iterative lookup. LookupMaxIterations = 20 // LookupAlpha is how many FIND_NODE queries one lookup round issues // concurrently (Kademlia's α). Sequential querying lets a handful of // dead onions (each a multi-second Tor SOCKS timeout) starve the whole // lookup — with α in flight, a dead candidate costs shared wall-clock, // not its own serial slot. Ticket 71658904. LookupAlpha = 4 // AnnounceConcurrency bounds how many PUT_RECORD dials one identity's // announce runs in parallel. Same rationale as LookupAlpha: the demo RT // had 9 dead onions and a fully sequential announce took 30s for one // identity. Bounded so a big routing table doesn't open unbounded // simultaneous Tor circuits. Ticket 71658904. AnnounceConcurrency = 8 // AnnounceFailureThreshold is the default number of consecutive announce // failures after which a peer is evicted from the routing table. AnnounceFailureThreshold = 3 // AllowedClockSkew bounds how far a record's signed timestamp may lead our // local clock before we reject it as implausibly future-dated. A record's // owner can sign any timestamp it likes; without an upper bound a // future-dated record (e.g. year 2099) has a negative age that never // crosses RecordTTL, so it would never expire and could squat a routing // bucket indefinitely (surviving restarts via the persisted RT). 5 minutes // matches the signaling-layer freshness budget. Ticket f8eb0f1f. AllowedClockSkew = 5 * time.Minute )
const ( // DefaultRTMaxAge is the default eviction window for routing-table // entries. Peers with LastSeen older than this are dropped on the next // announce-loop tick (and at startup once the routing table is loaded // from disk). DefaultRTMaxAge = 168 * time.Hour // 7 days // DefaultPruneInterval is how often the prune loop (StartPruneLoop) runs // its stale-eviction + liveness-probe pass. Deliberately much tighter // than the 15-minute announce loop: a torn-down onion should leave the // routing table in minutes, not after 3 failed announce ticks (45 min), // because every dead entry costs a full Tor SOCKS timeout to whichever // announce or lookup trips over it. Ticket 71658904. DefaultPruneInterval = 3 * time.Minute )
const ( // IDLength is the byte length of a NodeID (RIPEMD-160 output). IDLength = 20 // NumBuckets is the number of K-buckets (one per bit of NodeID). NumBuckets = 160 // K is the maximum number of peers per bucket. K = 20 )
Variables ¶
This section is empty.
Functions ¶
func CommonPrefixLen ¶
CommonPrefixLen returns the number of leading bits in common between two NodeIDs.
func DefaultSeeds ¶
func DefaultSeeds() []string
DefaultSeeds returns a copy of the built-in bootstrap onion list. Callers must not mutate the result; returning a copy keeps the package-level list immune to accidental edits from tests or operator overrides.
func IsV3OnionAddr ¶
IsV3OnionAddr is the strict v3-onion shape check: 56 chars of lowercase base32 (a-z + 2-7) followed by ".onion". Unlike looksLikeOnionV3, an empty string is rejected — callers like the hardcoded-seed list want a typo to fail at init time, not be silently treated as a legacy-empty entry.
func ParseSeedNodes ¶
ParseSeedNodes splits a comma-separated list of v3 onion addresses (as supplied via --seed-nodes or ENSEMBLE_SEED_NODES) into a validated slice. Whitespace around entries is trimmed; empty entries are skipped so trailing commas are tolerated. The first invalid entry returns an error with the offending value so misconfiguration is loud at startup.
func PeerRecordCanonicalBytes ¶
PeerRecordCanonicalBytes returns the deterministic byte sequence a peer's Dilithium key signs to authenticate a DHT PeerRecord. Any reimplementation MUST reproduce this layout byte-for-byte or signatures won't verify.
Layout (byte-exact):
peerRecordCanonicalLabel ("ensemble.v1.peerrecord", 22 bytes)
0x00 (label terminator)
uint16 big-endian (len(nodeID), always 20)
nodeID (raw bytes)
uint16 big-endian (len(address))
address (ASCII bytes)
uint16 big-endian (len(onion))
onion (ASCII bytes)
int64 big-endian (timestamp, Unix millis)
Length-prefixing every variable-length field prevents canonicalisation ambiguity between adjacent fields. The dilithium_pub is deliberately NOT in the signed bytes: it is bound to the record because the verifier checks AddressFromDilithiumPub(pub) == address, and address IS signed. Swapping the pubkey would change the derived address and break that check.
Types ¶
type DHTDiscovery ¶
type DHTDiscovery struct {
// contains filtered or unexported fields
}
DHTDiscovery handles peer announcement and lookup over the DHT. DHT records are authenticated, not hash-only: each carries the announcer's Dilithium public key + a signature, verified before a record is trusted. The DHT is still a routing layer, not an authorization layer — connection authorization happens on the wire at handshake time, not here. See doc.go for the full rationale and the correlation/CPU mitigations (ticket 942315f4).
func NewDHTDiscovery ¶
func NewDHTDiscovery(rt *RoutingTable, localPeer *PeerInfo, localSigner *identity.Identity, dialer Dialer) *DHTDiscovery
NewDHTDiscovery creates a new DHT discovery instance. localSigner is the Dilithium identity that signs records published for localPeer; it must own localPeer.Address (its pubkey hashes to it). A nil signer is tolerated for tests that never announce, but Announce/handleFindNode will skip the primary identity with a logged error if it can't sign.
func (*DHTDiscovery) AddLocalIdentity ¶
func (d *DHTDiscovery) AddLocalIdentity(addr, onion string, signer *identity.Identity) error
AddLocalIdentity registers an additional identity (per-service onion) hosted by this daemon. handleFindNode will return it for matching lookups, and Announce will publish it to the DHT alongside the primary localPeer. signer is the service's Dilithium identity, used to sign the records we publish for it; its pubkey must hash to addr. Calls for an address that matches localPeer are a no-op (the primary is already covered). Calls with a duplicate address replace the existing onion + signer.
func (*DHTDiscovery) Announce ¶
func (d *DHTDiscovery) Announce(ctx context.Context) error
Announce pushes our PeerRecord(s) to the K closest nodes in the routing table. The primary localPeer is always announced; any registered local identities (per-service onions) are announced too so external peers can resolve service addresses via DHT lookup.
func (*DHTDiscovery) AnnounceIdentity ¶
func (d *DHTDiscovery) AnnounceIdentity(ctx context.Context, addr string) error
AnnounceIdentity announces a single local identity (by address) to its K closest routing-table peers, immediately. This is the announce-on-bind path: a per-service identity registered mid-session (AddLocalIdentity) would otherwise wait for the 15-minute periodic announce, during which no other node can resolve it — an introduced peer dialing a freshly-bound PugPong player service got "peer not found" for up to 15 minutes. Ticket 71658904.
func (*DHTDiscovery) Bootstrap ¶
Bootstrap dials a seed node and performs a FindNode(self) to populate the routing table. The seed includes itself in the response, so the caller always learns the seed's identity and can later announce to it. Returns the number of new peers added to the routing table.
func (*DHTDiscovery) HandleConn ¶
func (d *DHTDiscovery) HandleConn(conn net.Conn)
HandleConn processes an incoming DHT connection (one request-response per conn).
func (*DHTDiscovery) HandleEnvelope ¶
func (d *DHTDiscovery) HandleEnvelope(conn net.Conn, env *pb.Envelope)
HandleEnvelope processes a pre-read DHT envelope on an existing connection.
func (*DHTDiscovery) Lookup ¶
Lookup performs an iterative DHT lookup for the given address. Returns the PeerInfo if found, or an error if not found.
func (*DHTDiscovery) ProbeStalePeers ¶
func (d *DHTDiscovery) ProbeStalePeers(ctx context.Context, olderThan, recheck time.Duration, concurrency int) (alive, dead int)
ProbeStalePeers liveness-probes routing-table peers whose record timestamp is older than olderThan and whose last successful probe is older than recheck, dialing up to concurrency of them in parallel (FIND_NODE for our own ID — any well-formed response proves the onion is alive). A failed probe feeds the same consecutive-failure counter as a failed announce; peers crossing the threshold are evicted. This is what gets a torn-down onion out of the table in minutes — previously a dead peer was only dialed by the 15-minute announce loop, so it took 3 ticks (45 min) to evict and meanwhile starved every sequential announce/lookup that tripped over it. Probe state lives beside the record (PeerInfo.LastProbeOK), NOT in LastSeen — LastSeen is the peer's signed record timestamp and must be relayed bit-for-bit. Returns (alive, dead) probe counts. Ticket 71658904.
func (*DHTDiscovery) RT ¶
func (d *DHTDiscovery) RT() *RoutingTable
RT returns the underlying routing table.
func (*DHTDiscovery) RemoveLocalIdentity ¶
func (d *DHTDiscovery) RemoveLocalIdentity(addr string) bool
RemoveLocalIdentity removes a previously-added local identity. Returns true if the identity was present.
func (*DHTDiscovery) SetFailureThreshold ¶
func (d *DHTDiscovery) SetFailureThreshold(n int)
SetFailureThreshold overrides the default consecutive-failure eviction threshold. Pass 0 to disable failure-based eviction.
func (*DHTDiscovery) SetOnRTMutation ¶
func (d *DHTDiscovery) SetOnRTMutation(fn func())
SetOnRTMutation registers a callback fired on every routing-table mutation performed by this DHT (AddPeer in bootstrap/lookup/handlePutRecord, plus failure-based evictions in Announce). The callback must not block — the Manager uses this to schedule a debounced disk save. Passing nil unwires the hook.
func (*DHTDiscovery) SetPutVerifyLimiter ¶
func (d *DHTDiscovery) SetPutVerifyLimiter(l *rate.Limiter)
SetPutVerifyLimiter overrides the inbound-verify rate limiter. Test-only; production uses the default constructed in NewDHTDiscovery. Pass nil to disable throttling. W3 #cfffd8a4.
type MDNSDiscovery ¶
type MDNSDiscovery struct {
// contains filtered or unexported fields
}
MDNSDiscovery discovers ensemble peers on the local network via mDNS.
func NewMDNSDiscovery ¶
func NewMDNSDiscovery(localAddr, onionAddr string) *MDNSDiscovery
NewMDNSDiscovery creates a new mDNS discovery instance.
func (*MDNSDiscovery) OnPeerFound ¶
func (m *MDNSDiscovery) OnPeerFound(cb func(*PeerInfo))
OnPeerFound sets the callback invoked when a peer is discovered via mDNS.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates peer discovery across mDNS (LAN) and DHT (global). FindPeer tries mDNS first for speed, then falls back to DHT.
func NewManager ¶
func NewManager(dht *DHTDiscovery, mdns *MDNSDiscovery) *Manager
NewManager creates a discovery manager with DHT and optional mDNS backends. mdns may be nil if LAN discovery is disabled.
func (*Manager) AddLocalIdentity ¶
AddLocalIdentity registers an additional locally-hosted identity (a per-service onion) with the DHT layer so it is advertised on Announce and returned by handleFindNode. signer is the service's Dilithium identity, used to sign the records published for it.
The new identity is also announced to the DHT immediately (async): a service bound mid-session would otherwise stay unresolvable until the 15-minute periodic announce, which broke introduced-peer dials to freshly-bound services (PugPong: both players' dials returned "peer not found" for the whole match window). Ticket 71658904.
func (*Manager) AddNode ¶
AddNode bootstraps the DHT by dialing a known seed node's onion address. Returns the number of new peers discovered.
func (*Manager) EvictStale ¶
EvictStale walks the routing table and drops peers older than the configured max age. Returns the number evicted. Safe to call concurrently with the announce loop. Exposed primarily for the daemon's startup eviction pass.
func (*Manager) FindPeer ¶
FindPeer looks up a peer by address. Tries mDNS first (fast, LAN), then DHT (slower, global).
func (*Manager) MarkDirty ¶
func (m *Manager) MarkDirty()
MarkDirty schedules a debounced save of the routing table. Safe to call from any goroutine and from hot DHT handler paths — never blocks; the actual write happens in startSaveLoop. No-op until the save loop is started via StartSaveLoop.
func (*Manager) RemoveLocalIdentity ¶
RemoveLocalIdentity removes a local identity previously added via AddLocalIdentity.
func (*Manager) SetRTMaxAge ¶
SetRTMaxAge sets the routing-table eviction window. Peers with LastSeen older than this are dropped on the next announce-loop tick. Pass 0 to disable time-based eviction (failure-counter eviction still applies).
func (*Manager) StartAnnounceLoop ¶
StartAnnounceLoop runs a background goroutine that announces to the DHT and saves the routing table periodically. Stops when ctx is cancelled.
func (*Manager) StartPruneLoop ¶
StartPruneLoop runs a background goroutine that keeps the routing table clean on a tight cadence (DefaultPruneInterval), independently of the 15-minute announce loop: each tick evicts entries past the stale window (SetRTMaxAge) and liveness-probes peers we haven't heard from recently, evicting any that cross the consecutive-failure threshold. Dead onions otherwise linger for 3 announce ticks (45 min), and every sequential operation that trips over one burns a full Tor SOCKS timeout — the demo RT carried 9 corpses from prior runs' ephemeral service identities. The pass runs synchronously in the loop goroutine, so a slow probe round cannot overlap the next one. Stops when ctx is cancelled. Ticket 71658904.
func (*Manager) StartSaveLoop ¶
StartSaveLoop launches a goroutine that listens for dirty signals (via MarkDirty) and persists the routing table after a short coalesce window. Stops when ctx is cancelled. Idempotent against duplicate dirty signals during the coalesce window — additional signals are drained. Called once at daemon startup after SetRTPath.
type NodeID ¶
NodeID is a 20-byte identifier derived from a public key's RIPEMD-160(SHA-256) hash.
func NodeIDFromAddress ¶
NodeIDFromAddress extracts the 20-byte hash from a Base58Check address. The address is fully validated (version byte + checksum) via identity.Validate before any bytes are extracted — otherwise any 25-byte Base58-decodable blob would yield a "valid-looking" NodeID and bypass identity-layer checks.
type PeerInfo ¶
type PeerInfo struct {
ID NodeID `json:"id"`
Address string `json:"address"`
OnionAddr string `json:"onion_addr"`
LastSeen time.Time `json:"last_seen"`
// DilithiumPub + Signature are the authentication material that came in
// with this peer's signed PeerRecord. They are carried through the
// routing table (and persisted) so a node relaying this record in a
// FIND_NODE / PUT_RECORD response re-emits the EXACT signed bytes the
// announcer produced — a relaying node never re-signs (it doesn't hold
// the peer's key) and must not be able to forge. The signed timestamp is
// LastSeen.UnixMilli(): recordToPeerInfo sets LastSeen from the record
// timestamp, so the round-trip reproduces it bit-for-bit. Empty for our
// own primary identity until Announce signs it fresh per round.
DilithiumPub []byte `json:"dilithium_pub,omitempty"`
Signature []byte `json:"signature,omitempty"`
// Failures counts consecutive announce failures observed by the
// announcing node. Reset to 0 on a successful announce, incremented on
// each failure. Intentionally not persisted: a daemon restart should
// give every peer a fresh shot regardless of the previous run's
// outcomes (Tor or local network may have been the problem). The DHT
// announce loop drops peers whose Failures cross a configured
// threshold.
Failures int `json:"-"`
// LastProbeOK is when a liveness probe of this peer last succeeded
// (prune loop, ticket 71658904). In-memory bookkeeping only — it must
// NOT be folded into LastSeen, which is the peer's signed record
// timestamp and has to be reproduced bit-for-bit when the record is
// relayed. Not persisted for the same reason Failures isn't: each run
// re-establishes liveness itself. Zero means never probed.
LastProbeOK time.Time `json:"-"`
}
PeerInfo represents a peer in the routing table.
func ParseMDNSEntry ¶
ParseMDNSEntry is exported for testing — converts TXT records to PeerInfo.
type RoutingTable ¶
type RoutingTable struct {
// Anti-Sybil configuration (exported for testing).
MaxPerSource int
RateLimit int
RateWindow time.Duration
// OnionRotationCooldown is the minimum time that must elapse between
// changing the OnionAddr of a cached peer record. The DHT is open
// (no authentication on PUT_RECORD) and the per-source rate-limit is
// keyed on the announced NodeID — which an attacker chooses freely
// to match the victim's address. Without a cooldown, any DHT peer
// can overwrite a victim's onion on every announce, redirecting
// lookups to an attacker-chosen onion (eclipse / targeted DoS).
// Trust-on-first-use: the first onion observed for a NodeID is
// cached; subsequent records with a DIFFERENT onion are rejected
// until OnionRotationCooldown has elapsed since the first sighting.
// Re-announces with the same onion always refresh LastSeen. Legit
// identity rotation is rare (and requires regenerating the master
// seed) so the cooldown only mildly delays legitimate cases while
// blocking the active poisoning vector. Ticket 3397f457; the
// full-fix Option C (Dilithium-signed PeerRecord) supersedes this
// when it ships.
OnionRotationCooldown time.Duration
// contains filtered or unexported fields
}
RoutingTable is a Kademlia-style routing table with 160 K-buckets.
func NewRoutingTable ¶
func NewRoutingTable(local NodeID) *RoutingTable
NewRoutingTable creates a routing table centered on the given local node ID.
func (*RoutingTable) AddPeer ¶
func (rt *RoutingTable) AddPeer(peer *PeerInfo, source NodeID) bool
AddPeer adds or updates a peer in the routing table. source is the NodeID that told us about this peer (use the peer's own ID for self-announcements). Returns true if the peer was added or updated, false if rejected.
func (*RoutingTable) AllPeers ¶
func (rt *RoutingTable) AllPeers() []*PeerInfo
AllPeers returns a copy of all peers in the routing table.
func (*RoutingTable) Evict ¶
func (rt *RoutingTable) Evict(maxAge time.Duration) int
Evict removes peers whose LastSeen is older than maxAge, and any peer with a zero LastSeen (treated as ancient — see PeerInfo.LastSeen invariant). Returns the number of peers evicted. maxAge <= 0 disables the time-based pass.
func (*RoutingTable) EvictByFailures ¶
func (rt *RoutingTable) EvictByFailures(threshold int) []*PeerInfo
EvictByFailures removes peers whose in-memory failure counter is at or above the given threshold. Returns the number evicted. threshold <= 0 disables the pass.
func (*RoutingTable) FindClosest ¶
func (rt *RoutingTable) FindClosest(target NodeID, count int) []*PeerInfo
FindClosest returns up to count peers closest to target by XOR distance.
func (*RoutingTable) Load ¶
func (rt *RoutingTable) Load(path string) error
Load restores peers from a JSON file into the routing table. Missing file is not an error (fresh start). Peers are added without rate limiting.
func (*RoutingTable) Local ¶
func (rt *RoutingTable) Local() NodeID
Local returns the local node's ID.
func (*RoutingTable) PeersForProbe ¶
func (rt *RoutingTable) PeersForProbe(olderThan, recheck time.Duration) []*PeerInfo
PeersForProbe returns copies of peers that are due a liveness probe: record timestamp (LastSeen) older than olderThan — a peer we've recently heard from is alive by definition — and last successful probe older than recheck, so a quiet-but-alive peer is probed at most once per recheck window rather than every prune tick.
func (*RoutingTable) RecordFailure ¶
func (rt *RoutingTable) RecordFailure(onionAddr string) int
RecordFailure increments the in-memory failure counter for the peer with the given onion address. Returns the new failure count, or 0 if the peer is no longer in the routing table.
func (*RoutingTable) RecordFatal ¶
func (rt *RoutingTable) RecordFatal(onionAddr string) int
RecordFatal marks the peer with the given onion address as permanently unusable: its failure counter jumps past any eviction threshold so the next EvictByFailures prunes it immediately. Returns the new count, or 0 if the peer is no longer in the routing table.
func (*RoutingTable) RecordProbeOK ¶
func (rt *RoutingTable) RecordProbeOK(onionAddr string)
RecordProbeOK marks a successful liveness probe of the peer with the given onion address: clears the failure counter and stamps LastProbeOK so the prune loop doesn't re-probe a confirmed-alive peer every tick. No-op if the peer is no longer in the routing table.
func (*RoutingTable) RecordSuccess ¶
func (rt *RoutingTable) RecordSuccess(onionAddr string)
RecordSuccess clears the in-memory failure counter for the peer with the given onion address. No-op if the peer is not in the routing table.
func (*RoutingTable) RemovePeer ¶
func (rt *RoutingTable) RemovePeer(addr string) bool
RemovePeer removes a peer by ensemble address. Returns true if found.
func (*RoutingTable) Save ¶
func (rt *RoutingTable) Save(path string) error
Save persists the routing table to a JSON file at the given path.
func (*RoutingTable) Size ¶
func (rt *RoutingTable) Size() int
Size returns the total number of peers in the routing table.