Documentation
¶
Index ¶
- Constants
- func BucketIndex(self, peer a2al.NodeID) int
- func LessXORDistance(a, b, target a2al.NodeID) bool
- type PeerDebugRow
- type PingFunc
- type Table
- func (t *Table) Add(n protocol.NodeInfo) bool
- func (t *Table) AllPeers() []protocol.NodeInfo
- func (t *Table) BucketIndexOf(peer a2al.NodeID) int
- func (t *Table) Contains(id a2al.NodeID) bool
- func (t *Table) DebugPeerRows() []PeerDebugRow
- func (t *Table) Len() int
- func (t *Table) NearestN(target a2al.NodeID, n int) []protocol.NodeInfo
- func (t *Table) OldestInBucket(peer a2al.NodeID) (protocol.NodeInfo, bool)
- func (t *Table) PeerBucketLen(peer a2al.NodeID) int
- func (t *Table) Remove(id a2al.NodeID)
- func (t *Table) Self() a2al.NodeID
Constants ¶
const K = 16
Variables ¶
This section is empty.
Functions ¶
func BucketIndex ¶
BucketIndex is the K-bucket slot for peer relative to self: shared MSB prefix length in [0,255]. Returns -1 if peer equals self (spec §4.1, Step 5).
func LessXORDistance ¶
LessXORDistance reports whether a is strictly closer to target than b under XOR metric (lexicographic compare of Distance(a,target) vs Distance(b,target)).
Types ¶
type PeerDebugRow ¶
type PeerDebugRow struct {
Bucket int `json:"bucket"`
XORDistToSelf string `json:"xor_distance_to_self_hex"`
AddressHex string `json:"address_hex"`
NodeIDHex string `json:"node_id_hex"`
IP string `json:"ip"`
Port uint16 `json:"port"`
}
PeerDebugRow is a JSON-friendly routing row (spec §3.6).
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a 256-bucket Kademlia routing table (Phase 1: single LRU zone per bucket).
func NewTable ¶
NewTable constructs an empty table for the local node. ping may be nil (treated as always true on eviction probe).
func (*Table) Add ¶
Add inserts or refreshes a peer. Returns false if the peer is self, invalid, or rejected when the bucket is full and the LRU peer answers PING.
func (*Table) AllPeers ¶
AllPeers returns every distinct peer in the table (unordered). Excludes self.
func (*Table) BucketIndexOf ¶
BucketIndexOf returns BucketIndex(t.self, peer).
func (*Table) DebugPeerRows ¶
func (t *Table) DebugPeerRows() []PeerDebugRow
DebugPeerRows returns a flat list of peers with bucket index and XOR distance to local self (read-only snapshot; caller must serialize table access if concurrent).
func (*Table) NearestN ¶
NearestN returns up to n peers with smallest XOR distance to target (excluding self). Results sorted closest-first.
func (*Table) OldestInBucket ¶
OldestInBucket returns the LRU entry in the bucket that would hold peer (may be nil slice if empty).
func (*Table) PeerBucketLen ¶
PeerBucketLen is for tests / debug: number of entries in the bucket for peer's CPL slot.