macula_routing_table (macula v0.20.3)
View SourceRouting table for Kademlia DHT. Manages 256 k-buckets organized by XOR distance.
Summary
Functions
Add a node to the routing table. Calculates bucket index and adds to appropriate bucket.
Get size of a specific bucket.
Find k closest nodes to target.
Get all nodes from all buckets.
Get bucket by index.
Get k (bucket capacity).
Get local node ID.
Create a new routing table.
Remove a node from the routing table.
Get total number of nodes in routing table.
Update timestamp for a node (moves to tail in its bucket).
Types
-type routing_table() :: #{local_node_id := binary(), k := pos_integer(), buckets := #{0..255 => macula_routing_bucket:bucket()}}.
Functions
-spec add_node(routing_table(), macula_routing_bucket:node_info()) -> routing_table().
Add a node to the routing table. Calculates bucket index and adds to appropriate bucket.
-spec bucket_size(routing_table(), 0..255) -> non_neg_integer().
Get size of a specific bucket.
-spec find_closest(routing_table(), binary(), pos_integer()) -> [macula_routing_bucket:node_info()].
Find k closest nodes to target.
-spec get_all_nodes(routing_table()) -> [macula_routing_bucket:node_info()].
Get all nodes from all buckets.
-spec get_bucket(routing_table(), 0..255) -> macula_routing_bucket:bucket().
Get bucket by index.
-spec k(routing_table()) -> pos_integer().
Get k (bucket capacity).
-spec local_node_id(routing_table()) -> binary().
Get local node ID.
-spec new(binary(), pos_integer()) -> routing_table().
Create a new routing table.
-spec remove_node(routing_table(), binary()) -> routing_table().
Remove a node from the routing table.
-spec size(routing_table()) -> non_neg_integer().
Get total number of nodes in routing table.
-spec update_timestamp(routing_table(), binary()) -> routing_table().
Update timestamp for a node (moves to tail in its bucket).