macula_routing_bucket (macula v0.20.3)
View SourceK-bucket for Kademlia routing table. Stores up to k nodes with LRU eviction policy.
Summary
Functions
Add a node to the bucket. If node exists, move to tail (most recent). If bucket full, return {error, bucket_full}.
Get bucket capacity.
Find n closest nodes to target (sorted by XOR distance).
Find a node by ID.
Get all nodes in the bucket (ordered: oldest first).
Check if bucket contains node.
Create a new bucket with capacity k.
Remove a node from the bucket.
Get number of nodes in bucket.
Update node's last_seen timestamp (moves to tail).
Types
-type bucket() :: #{capacity := pos_integer(), nodes := [node_info()]}.
-type node_info() :: #{node_id := binary(), address := {inet:ip_address(), inet:port_number()}, last_seen => integer()}.
Functions
Add a node to the bucket. If node exists, move to tail (most recent). If bucket full, return {error, bucket_full}.
-spec capacity(bucket()) -> pos_integer().
Get bucket capacity.
-spec find_closest(bucket(), binary(), pos_integer()) -> [node_info()].
Find n closest nodes to target (sorted by XOR distance).
Find a node by ID.
Get all nodes in the bucket (ordered: oldest first).
Check if bucket contains node.
-spec new(pos_integer()) -> bucket().
Create a new bucket with capacity k.
Remove a node from the bucket.
-spec size(bucket()) -> non_neg_integer().
Get number of nodes in bucket.
Update node's last_seen timestamp (moves to tail).