macula_rpc_dht (macula v0.14.3)

View Source

DHT integration for finding RPC service providers. Uses Kademlia DHT to publish and discover RPC registrations. Wraps macula_discovery with RPC-specific types.

Summary

Functions

Filter providers to only available ones (based on last_seen TTL).

Find service providers for a URI via DHT.

Find providers with cache (default TTL: 300 seconds).

Find providers with cache and custom TTL.

Remove local registration from DHT.

Types

address/0

-type address() :: {inet:ip_address(), inet:port_number()}.

dht_lookup_fun/0

-type dht_lookup_fun() :: fun((uri()) -> {ok, [provider_info()]} | {error, term()}).

dht_publish_fun/0

-type dht_publish_fun() :: fun((uri(), node_id(), address(), map()) -> ok | {error, term()}).

dht_unpublish_fun/0

-type dht_unpublish_fun() :: fun((uri(), node_id()) -> ok | {error, term()}).

node_id/0

-type node_id() :: binary().

provider_info/0

-type provider_info() ::
          #{node_id := node_id(), address := address(), metadata := map(), last_seen := integer()}.

uri/0

-type uri() :: binary().

Functions

announce(Uri, LocalNodeId, LocalAddress, Metadata, DhtPublishFun)

-spec announce(uri(), node_id(), address(), map(), dht_publish_fun()) -> ok | {error, term()}.

Announce local registration to DHT.

filter_available(Providers, TTL)

-spec filter_available([provider_info()], pos_integer()) -> [provider_info()].

Filter providers to only available ones (based on last_seen TTL).

find_providers(Uri, DhtLookupFun)

-spec find_providers(uri(), dht_lookup_fun()) -> {ok, [provider_info()]} | {error, term()}.

Find service providers for a URI via DHT.

find_with_cache(Uri, Cache, DhtLookupFun)

-spec find_with_cache(uri(), macula_cache:cache(), dht_lookup_fun()) ->
                         {ok, [provider_info()], macula_cache:cache()} |
                         {error, term(), macula_cache:cache()}.

Find providers with cache (default TTL: 300 seconds).

find_with_cache(Uri, Cache, DhtLookupFun, TTL)

-spec find_with_cache(uri(), macula_cache:cache(), dht_lookup_fun(), pos_integer()) ->
                         {ok, [provider_info()], macula_cache:cache()} |
                         {error, term(), macula_cache:cache()}.

Find providers with cache and custom TTL.

unannounce(Uri, LocalNodeId, DhtUnpublishFun)

-spec unannounce(uri(), node_id(), dht_unpublish_fun()) -> ok | {error, term()}.

Remove local registration from DHT.