barrel_server_sig_cache (barrel_server v1.2.1)

View Source

Replay cache for signed sync requests.

A bounded, public ETS set keyed by {KeyId, Ts, Sig}. The verifier (barrel_server_auth) calls check_and_insert/2 on the hot path: a first sighting inserts and returns ok; a repeat within the window returns {error, replayed}. This closes the replay gap the retired barrel_memory peer-auth scheme left open (it had only a timestamp window).

This gen_server owns the table and sweeps expired entries; the atomic ets:insert_new/2 means the check needs no server round-trip. If the table is absent (server not started), the check fails closed.

Summary

Functions

Record a request signature. TtlMs bounds how long the entry is retained (use twice the accepted skew). Returns ok the first time a Key is seen, {error, replayed} on a repeat, and {error, no_cache} if the cache is not running (fail closed).

Functions

check_and_insert(Key, TtlMs)

-spec check_and_insert(term(), pos_integer()) -> ok | {error, replayed | no_cache}.

Record a request signature. TtlMs bounds how long the entry is retained (use twice the accepted skew). Returns ok the first time a Key is seen, {error, replayed} on a repeat, and {error, no_cache} if the cache is not running (fail closed).

handle_call(Req, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

start_link()

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