Search documentation of macula

# macula_routing_table (macula v0.44.2)

View Source

Routing table for Kademlia DHT. Manages 256 k-buckets organized by XOR distance.

# Summary

## Types

routing_table/0

## Functions

add_node(Table, NodeInfo)

Add a node to the routing table. Removes any ghost entries (same endpoint, different node_id) across ALL buckets before adding, since a restarted node may land in a different bucket.

bucket_size(Table, BucketIndex)

Get size of a specific bucket.

evict_stale(Table, StaleThreshold)

Remove nodes not seen since StaleThreshold (millisecond timestamp) from all buckets.

find_closest(_, Target, K)

Find k closest nodes to target.

get_all_nodes(_)

Get all nodes from all buckets.

get_bucket(_, BucketIndex)

Get bucket by index.

k(_)

Get k (bucket capacity).

local_node_id(_)

Get local node ID.

new(LocalNodeId, K)

Create a new routing table.

remove_by_endpoint(Table, Endpoint)

Remove all nodes matching an endpoint from all buckets.

remove_node(Table, NodeId)

Remove a node from the routing table.

size(_)

Get total number of nodes in routing table.

update_timestamp(Table, NodeId)

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)

    -spec add_node(routing_table(), macula_routing_bucket:node_info()) -> routing_table().

Add a node to the routing table. Removes any ghost entries (same endpoint, different node_id) across ALL buckets before adding, since a restarted node may land in a different bucket.

# bucket_size(Table, BucketIndex)

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

Get size of a specific bucket.

# evict_stale(Table, StaleThreshold)

    -spec evict_stale(routing_table(), integer()) -> routing_table().

Remove nodes not seen since StaleThreshold (millisecond timestamp) from all buckets.

# 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_by_endpoint(Table, Endpoint)

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

Remove all nodes matching an endpoint from all buckets.

# 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).