macula_cache_route (macula v4.2.8)

View Source

TTL-bounded route cache for macula-net.

Phase 2 (PLAN_MACULA_NET_PHASE2.md §4.3). Replaces Phase 1's static station table in macula_route_packet: route_packet consults this cache first, falls back to macula_resolve_address on miss, and inserts the result.

Lookups are O(1) on an ETS set keyed by macula-net IPv6 address. A periodic sweep (gen_server timer) evicts entries whose expires_at has passed; lookups also expire-on-read so a stale entry never escapes.

Summary

Functions

Look up a route. Returns {ok, Entry} for a live cache hit, expired if the entry was found but past its TTL (also evicted), or miss if no entry was present.

Force a sweep right now. Useful for tests.

Types

lookup_result/0

-type lookup_result() :: {ok, route_entry()} | miss | expired.

route_entry/0

-type route_entry() ::
          #{station_pubkey := <<_:256>>,
            host := binary(),
            port := 1..65535,
            expires_at := pos_integer()}.

Functions

code_change(OldVsn, State, Extra)

handle_call(Other, From, State)

handle_cast(Msg, State)

handle_info(Other, State)

init(Opts)

insert(Addr, Entry)

-spec insert(<<_:128>>, route_entry()) -> ok.

invalidate(Addr)

-spec invalidate(<<_:128>>) -> ok.

lookup(Addr)

-spec lookup(<<_:128>>) -> lookup_result().

Look up a route. Returns {ok, Entry} for a live cache hit, expired if the entry was found but past its TTL (also evicted), or miss if no entry was present.

size()

-spec size() -> non_neg_integer().

start_link()

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

start_link(Opts)

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

stop()

-spec stop() -> ok.

sweep()

-spec sweep() -> ok.

Force a sweep right now. Useful for tests.

terminate(Reason, State)