Service Discovering

Registrar

The Service Discovering mechanism allows nodes to automatically find other nodes and determine connection parameters.

Each node has a Registrar that starts during the node's initialization and operates in either server or client mode. In Ergo Framework, the default Registrar implementation is available in the package ergo.services/ergo/net/registrar. If you are using Saturn, you need to use the corresponding client available in ergo.services/registrar/saturn. For communication with Erlang nodes, you should use the implementation from ergo.services/proto/erlang23/epmd.

The default Registrar, when running in server mode, opens a TCP socket on localhost:4499 to register other nodes on the host and a UDP socket on *:4499 to handle resolve requests from other nodes, including remote ones. If the Registrar fails to start in server mode, it switches to client mode and registers with the Registrar on the other node at same host which is running in server-mode.

When a node starts, it establishes a TCP connection with the Registrar server, which remains open until the node terminates. During registration, your node communicates its name, information about all acceptors, and their parameters (port number, Handshake/Proto version, TLS flag) to the Registrar. If using Saturn, additional information about running applications on the node is also communicated (this functionality is not supported by the built-in Registrar).

When a node running the Registrar in server mode terminates, other nodes on the same host automatically attempt to switch to server mode. The node that first successfully opens the TCP socket on localhost:4499 will switch to server mode, while the remaining nodes on the host will continue to operate in client mode and automatically register with the new Registrar in server node.

Node names must be unique within the same host. If a node attempts to register with a name that has already been registered by another node, the Registrar will return the error gen.ErrTaken.

When a node attempts to establish a network connection with another node, it first sends a resolve request (a UDP packet) to the Registrar, using the host name of the target node and port 4499. In response to this request, the Registrar returns a list of acceptors along with their parameters needed to establish the connection:

  • The port number where the acceptor is running.

  • The version of the Handshake protocol.

  • The version of the Proto protocol.

  • The TLS flag, which indicates whether TLS encryption is required for this connection.

Using these parameters, the node then establishes the network connection to the target node.

By default, the built-in network stack of Ergo Framework (ergo.services/ergo/net) is used for both incoming and outgoing connections. However, the node can work with multiple network stacks simultaneously (e.g., for compatibility with Erlang's network stack).

You can create multiple acceptors with different sets of parameters for handling incoming connections. For outgoing connections, you can manage the connection parameters using the Static Routes functionality, which allows you to control how connections are established with various nodes.

Last updated