macula_routing_server (macula v0.7.29)

View Source

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

Summary

Functions

Add node to routing table.

Find k closest nodes to target.

Find value in DHT using iterative lookup. Returns {ok, Value} if found, {nodes, Nodes} if not found.

Get value from local storage.

Get routing table snapshot.

Handle incoming DHT message and return reply.

Get number of nodes in routing table.

Start routing server with registered name macula_routing_server.

Store value locally.

Functions

add_node(Pid, NodeInfo)

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

Add node to routing table.

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 using iterative lookup. Returns {ok, Value} if found, {nodes, Nodes} if not found.

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.

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_local(Pid, Key, Value)

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

Store value locally.