macula_pubsub_discovery (macula v0.14.3)

View Source

DHT integration for finding remote subscribers. Uses Kademlia DHT to publish and discover subscriptions. Wraps macula_discovery with pub/sub-specific types.

Summary

Functions

Find remote subscribers for a pattern via DHT.

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

Find subscribers with cache and custom TTL.

Remove local subscription from DHT.

Types

address/0

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

dht_lookup_fun/0

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

dht_publish_fun/0

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

dht_unpublish_fun/0

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

node_id/0

-type node_id() :: binary().

pattern/0

-type pattern() :: binary().

subscriber/0

-type subscriber() :: #{node_id := node_id(), address := address()}.

Functions

announce(Pattern, LocalNodeId, LocalAddress, DhtPublishFun)

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

Announce local subscription to DHT.

find_subscribers(Pattern, DhtLookupFun)

-spec find_subscribers(pattern(), dht_lookup_fun()) -> {ok, [subscriber()]} | {error, term()}.

Find remote subscribers for a pattern via DHT.

find_with_cache(Pattern, Cache, DhtLookupFun)

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

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

find_with_cache(Pattern, Cache, DhtLookupFun, TTL)

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

Find subscribers with cache and custom TTL.

unannounce(Pattern, LocalNodeId, DhtUnpublishFun)

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

Remove local subscription from DHT.