macula_routing_table (macula v0.20.3)

View Source

Routing 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

routing_table/0

-type routing_table() ::
          #{local_node_id := binary(),
            k := pos_integer(),
            buckets := #{0..255 => macula_routing_bucket:bucket()}}.

Functions

add_node(Table, NodeInfo)

Add a node to the routing table. Calculates bucket index and adds to appropriate bucket.

bucket_size(Table, BucketIndex)

-spec bucket_size(routing_table(), 0..255) -> non_neg_integer().

Get size of a specific bucket.

find_closest(_, Target, K)

-spec find_closest(routing_table(), binary(), pos_integer()) -> [macula_routing_bucket:node_info()].

Find k closest nodes to target.

get_all_nodes(_)

-spec get_all_nodes(routing_table()) -> [macula_routing_bucket:node_info()].

Get all nodes from all buckets.

get_bucket(_, BucketIndex)

-spec get_bucket(routing_table(), 0..255) -> macula_routing_bucket:bucket().

Get bucket by index.

k(_)

-spec k(routing_table()) -> pos_integer().

Get k (bucket capacity).

local_node_id(_)

-spec local_node_id(routing_table()) -> binary().

Get local node ID.

new(LocalNodeId, K)

-spec new(binary(), pos_integer()) -> routing_table().

Create a new routing table.

remove_node(Table, NodeId)

-spec remove_node(routing_table(), binary()) -> routing_table().

Remove a node from the routing table.

size(_)

-spec size(routing_table()) -> non_neg_integer().

Get total number of nodes in routing table.

update_timestamp(Table, NodeId)

-spec update_timestamp(routing_table(), binary()) -> routing_table().

Update timestamp for a node (moves to tail in its bucket).