macula_direct_routing (macula v0.20.5)

View Source

Direct Routing Table - Bypass bootstrap for known subscriber endpoints.

Problem: Every publish goes through bootstrap even for known subscribers. Solution: Cache {NodeId, Endpoint} mappings and route directly via QUIC.

Design: - ETS table for O(1) lookup by NodeId - TTL-based expiration (default 5 minutes) - Automatic cleanup of stale entries - Thread-safe concurrent reads

Expected improvement: - 3-5x latency reduction for messages to known subscribers - Reduced load on bootstrap gateway

Configuration Options: - ttl_ms: Route entry TTL (default: 300000ms = 5 minutes) - cleanup_interval_ms: How often to clean stale entries (default: 60000ms)

Summary

Functions

Clear all routing entries.

Look up endpoint for a node ID. Returns {ok, Endpoint} on hit, or miss on cache miss/expired.

Remove routing entry for a node ID.

Start the direct routing table with default options.

Start the direct routing table with options. Options: - ttl_ms: Route entry TTL in milliseconds (default: 300000) - cleanup_interval_ms: Cleanup interval (default: 60000)

Get routing table statistics.

Store endpoint for a node ID. Entry will expire after TTL.

Store routing info from a subscriber map (from DHT lookup). Extracts node_id and endpoint from subscriber info.

Functions

clear_all()

-spec clear_all() -> ok.

Clear all routing entries.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(Opts)

lookup(NodeId)

-spec lookup(binary()) -> {ok, binary()} | miss.

Look up endpoint for a node ID. Returns {ok, Endpoint} on hit, or miss on cache miss/expired.

remove(NodeId)

-spec remove(binary()) -> ok.

Remove routing entry for a node ID.

start_link()

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

Start the direct routing table with default options.

start_link(Opts)

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

Start the direct routing table with options. Options: - ttl_ms: Route entry TTL in milliseconds (default: 300000) - cleanup_interval_ms: Cleanup interval (default: 60000)

stats()

-spec stats() -> map().

Get routing table statistics.

store(NodeId, Endpoint)

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

Store endpoint for a node ID. Entry will expire after TTL.

store_from_subscriber(_)

-spec store_from_subscriber(map()) -> ok.

Store routing info from a subscriber map (from DHT lookup). Extracts node_id and endpoint from subscriber info.

terminate(Reason, State)