Search documentation of macula

# macula_routing_storage (macula v0.44.2)

View Source

Pure functional helpers for DHT provider storage operations. Extracted from macula_routing_server to reduce module size. Handles provider lists, deduplication, expiry, and ETS mirroring.

# Summary

## Functions

deduplicate_providers(Providers)

Deduplicate providers by node_id -- keeps first occurrence.

delete_provider_from_storage(Key, NodeId, Storage)

Delete a specific provider from storage by node_id.

ensure_provider_list(List)

Ensure value is a list for multi-provider storage.

find_provider_index(NodeId, ProviderList)

Find index of provider with matching node_id in provider list.

format_node_id(B)

Format node_id for logging.

format_storage_value(Value)

Format storage value for get_local response.

get_node_endpoint(_)

Extract endpoint from node info.

get_node_id_from_value(Value)

Extract node_id from value map, handling both atom and binary keys.

is_provider_expired(Provider, Now)

Check if a provider entry is expired based on its stored_at timestamp.

mirror_delete_to_ets(Ets, Key, Storage)

Mirror a delete operation to ETS.

mirror_to_ets(Ets, Key, Providers)

Mirror a key-value update to ETS for concurrent reads.

upsert_provider(NodeId, Value, ProviderList)

Insert or update a provider in the list. Stamps every entry with stored_at for expiry tracking.

# Functions

# deduplicate_providers(Providers)

    -spec deduplicate_providers([map()]) -> [map()].

Deduplicate providers by node_id -- keeps first occurrence.

# delete_provider_from_storage(Key, NodeId, Storage)

    -spec delete_provider_from_storage(binary(), binary(), map()) -> map().

Delete a specific provider from storage by node_id.

# ensure_provider_list(List)

    -spec ensure_provider_list(term()) -> [term()].

Ensure value is a list for multi-provider storage.

# find_provider_index(NodeId, ProviderList)

    -spec find_provider_index(binary(), [map()]) -> pos_integer() | not_found.

Find index of provider with matching node_id in provider list.

# format_node_id(B)

    -spec format_node_id(binary() | undefined) -> binary().

Format node_id for logging.

# format_storage_value(Value)

    -spec format_storage_value(undefined | term()) -> not_found | {ok, [term()]}.

Format storage value for get_local response.

# get_node_endpoint(_)

    -spec get_node_endpoint(map()) -> binary() | undefined.

Extract endpoint from node info.

# get_node_id_from_value(Value)

    -spec get_node_id_from_value(map()) -> binary() | undefined.

Extract node_id from value map, handling both atom and binary keys.

# is_provider_expired(Provider, Now)

    -spec is_provider_expired(map(), integer()) -> boolean().

Check if a provider entry is expired based on its stored_at timestamp.

# mirror_delete_to_ets(Ets, Key, Storage)

    -spec mirror_delete_to_ets(atom() | ets:tid() | undefined, binary(), map()) -> ok.

Mirror a delete operation to ETS.

# mirror_to_ets(Ets, Key, Providers)

    -spec mirror_to_ets(atom() | ets:tid() | undefined, binary(), [term()]) -> ok.

Mirror a key-value update to ETS for concurrent reads.

# upsert_provider(NodeId, Value, ProviderList)

    -spec upsert_provider(binary() | undefined, map(), [map()]) -> [map()].

Insert or update a provider in the list. Stamps every entry with stored_at for expiry tracking.