Search documentation of macula

# macula_routing_server (macula v0.44.2)

View Source

GenServer managing Kademlia DHT routing table and operations. Integrates all routing components: table, DHT algorithms, protocol.

Pure functional helpers are in macula_routing_storage. Network transport and escalation are in macula_routing_network.

# Summary

## Functions

add_node(Pid, NodeInfo)

Add node to routing table (async - does not block caller).

delete_local(Pid, Key, NodeId)

Delete value from local storage.

find_closest(Pid, Target, K)

Find k closest nodes to target.

find_value(Pid, Key, K)

Find value in DHT -- goes through gen_server for full iterative lookup. For local-only reads (answering peer queries), use find_value_local/2.

find_value_local(Key, K)

Fast local-only lookup via ETS -- for answering incoming FIND_VALUE from peers. Does NOT query the network. Returns only locally stored values.

get_all_keys(Pid)

Get all keys from local storage.

get_local(Pid, Key)

Get value from local storage.

get_routing_table(Pid)

Get routing table snapshot.

handle_message(Pid, Message)

Handle incoming DHT message and return reply.

handle_message_async(Pid, Message)

Handle incoming DHT message asynchronously (fire-and-forget). Use for STORE messages where no reply is needed.

remove_node(Pid, NodeId)

Remove node from routing table (async - does not block caller).

size(Pid)

Get number of nodes in routing table.

start_link(LocalNodeId, Config)

Start routing server with registered name macula_routing_server.

store(Pid, Key, Value)

Store value in DHT by propagating to k closest nodes. Stores locally first, then sends STORE messages to k closest peers.

store_local(Pid, Key, Value)

Store value locally.

# Functions

# add_node(Pid, NodeInfo)

    -spec add_node(pid(), macula_routing_bucket:node_info()) -> ok.

Add node to routing table (async - does not block caller).

# delete_local(Pid, Key, NodeId)

    -spec delete_local(pid(), binary(), binary()) -> ok.

Delete value from local storage.

# find_closest(Pid, Target, K)

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

Find k closest nodes to target.

# find_value(Pid, Key, K)

    -spec find_value(pid(), binary(), pos_integer()) ->
                        {ok, term()} | {nodes, [macula_routing_bucket:node_info()]} | {error, term()}.

Find value in DHT -- goes through gen_server for full iterative lookup. For local-only reads (answering peer queries), use find_value_local/2.

# find_value_local(Key, K)

    -spec find_value_local(binary(), pos_integer()) -> {ok, term()} | {error, not_found}.

Fast local-only lookup via ETS -- for answering incoming FIND_VALUE from peers. Does NOT query the network. Returns only locally stored values.

# get_all_keys(Pid)

    -spec get_all_keys(pid()) -> {ok, [binary()]} | {error, term()}.

Get all keys from local storage.

# get_local(Pid, Key)

    -spec get_local(pid(), binary()) -> {ok, term()} | not_found.

Get value from local storage.

# get_routing_table(Pid)

    -spec get_routing_table(pid()) -> macula_routing_table:routing_table().

Get routing table snapshot.

# handle_message(Pid, Message)

    -spec handle_message(pid(), map()) -> map().

Handle incoming DHT message and return reply.

# handle_message_async(Pid, Message)

    -spec handle_message_async(pid(), map()) -> ok.

Handle incoming DHT message asynchronously (fire-and-forget). Use for STORE messages where no reply is needed.

# remove_node(Pid, NodeId)

    -spec remove_node(pid(), binary()) -> ok.

Remove node from routing table (async - does not block caller).

# size(Pid)

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

Get number of nodes in routing table.

# start_link(LocalNodeId, Config)

    -spec start_link(binary(), map()) -> {ok, pid()} | {error, term()}.

Start routing server with registered name macula_routing_server.

# store(Pid, Key, Value)

    -spec store(pid(), binary(), term()) -> ok.

Store value in DHT by propagating to k closest nodes. Stores locally first, then sends STORE messages to k closest peers.

# store_local(Pid, Key, Value)

    -spec store_local(pid(), binary(), term()) -> ok.

Store value locally.