macula_gateway_dht (macula v0.7.29)

View Source

DHT Query Handler Module - handles DHT message forwarding to routing server.

Responsibilities: - Forward DHT STORE messages to routing server - Forward DHT FIND_VALUE messages to routing server, send encoded replies - Forward DHT FIND_NODE messages to routing server, send encoded replies - Handle DHT queries from process messages - Encode replies using protocol encoder - Handle errors gracefully

Pattern: Stateless delegation module - No GenServer (no state to manage) - Pure functions forwarding to routing server - Consistent error handling ({ok, Result} | {error, Reason})

Extracted from macula_gateway.erl (Phase 10)

Summary

Functions

Handle DHT FIND_NODE message. Forwards to routing server and sends encoded reply over stream. Crashes on routing server or encoding failures - exposes DHT/protocol bugs.

Handle DHT FIND_VALUE message. Forwards to routing server and sends encoded reply over stream. Crashes on routing server or encoding failures - exposes DHT/protocol bugs.

Handle DHT query from process message. Decodes query, forwards to routing server, encodes reply, sends to requesting process. Crashes on decode or routing failures - exposes protocol/DHT bugs.

Handle DHT STORE message. Forwards to routing server (no reply sent back). Crashes on routing server failures - this exposes DHT issues immediately.

Look up a value from the DHT by key. Synchronous lookup from local DHT storage. Returns list of subscribers for the given key.

Functions

handle_find_node(Stream, FindNodeMsg)

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

Handle DHT FIND_NODE message. Forwards to routing server and sends encoded reply over stream. Crashes on routing server or encoding failures - exposes DHT/protocol bugs.

handle_find_value(Stream, FindValueMsg)

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

Handle DHT FIND_VALUE message. Forwards to routing server and sends encoded reply over stream. Crashes on routing server or encoding failures - exposes DHT/protocol bugs.

handle_query(FromPid, QueryType, QueryData)

-spec handle_query(pid(), atom(), binary()) -> ok.

Handle DHT query from process message. Decodes query, forwards to routing server, encodes reply, sends to requesting process. Crashes on decode or routing failures - exposes protocol/DHT bugs.

handle_store(Stream, StoreMsg)

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

Handle DHT STORE message. Forwards to routing server (no reply sent back). Crashes on routing server failures - this exposes DHT issues immediately.

lookup_value(Key)

-spec lookup_value(binary()) -> {ok, list()} | {error, not_found}.

Look up a value from the DHT by key. Synchronous lookup from local DHT storage. Returns list of subscribers for the given key.