quic_discovery behaviour (quic v1.3.1)

View Source

Behaviour definition for node discovery backends.

Discovery modules are used to locate nodes in a QUIC cluster without requiring EPMD. Implementations can use:

- Static configuration - DNS SRV records - Consul/etcd/Kubernetes service discovery - Custom protocols

Implementing a Backend

   -module(my_discovery).
   -behaviour(quic_discovery).
  
   -export([init/1, register/3, lookup/2, list_nodes/1]).
  
   init(Opts) ->
       %% Initialize backend state
       {ok, State}.
  
   register(NodeName, Port, State) ->
       %% Register this node
       {ok, State}.
  
   lookup(NodeName, Host) ->
       %% Find a node's address
       {ok, {IP, Port}} | {error, not_found}.
  
   list_nodes(Host) ->
       %% List all known nodes
       {ok, [{NodeName, Port}]}.

Summary

Functions

List all known nodes.

Look up a node's address using the configured discovery module.

Register this node with the discovery backend.

Callbacks

init/1

(optional)
-callback init(Opts :: proplists:proplist() | map()) -> {ok, State :: term()} | {error, Reason :: term()}.

list_nodes/1

(optional)
-callback list_nodes(Host :: string()) ->
                        {ok, [{NodeName :: atom(), inet:port_number()}]} | {error, Reason :: term()}.

lookup/2

-callback lookup(NodeName :: atom(), Host :: string()) ->
                    {ok, {inet:ip_address() | string(), inet:port_number()}} | {error, Reason :: term()}.

register/3

(optional)
-callback register(NodeName :: atom(), Port :: inet:port_number(), State :: term()) ->
                      {ok, State :: term()} | {error, Reason :: term()}.

Functions

list_nodes(Host)

-spec list_nodes(Host :: string()) -> {ok, [{atom(), inet:port_number()}]} | {error, term()}.

List all known nodes.

lookup(Node, Host)

-spec lookup(Node :: node(), Host :: string()) ->
                {ok, {inet:ip_address() | string(), inet:port_number()}} | {error, term()}.

Look up a node's address using the configured discovery module.

register_node(NodeName, Port, Opts)

-spec register_node(NodeName :: atom(), Port :: inet:port_number(), Opts :: proplists:proplist()) ->
                       ok | {error, term()}.

Register this node with the discovery backend.