Erlang -- How to Implement an Alternative Service Discovery for Erlang Distribution

Erlang Run-Time System Application (ERTS)

User's Guide

Version 10.6

- User's Guide
- Reference Manual
- Internal Documentation
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Chapters

- Introduction
  - Top of chapter
  - Scope
  - Prerequisites
- Communication in Erlang
  - Top of chapter
  - Passing of Signals
  - Synchronous Communication
  - Implementation
- Time and Time Correction in Erlang
  - Top of chapter
  - New Extended Time Functionality
  - Terminology
  - Introduction
  - Time Correction
  - Time Warp Safe Code
  - Time Warp Modes
  - New Time API
  - Support of Both New and Old OTP Releases
- Match Specifications in Erlang
  - Top of chapter
  - Grammar
  - Function Descriptions
  - Match target
  - Variables and Literals
  - Execution of the Match
  - Differences between Match Specifications in ETS and Tracing
  - Tracing Examples
  - ETS Examples
- How to Interpret the Erlang Crash Dumps
  - Top of chapter
  - General Information
  - Scheduler Information
  - Memory Information
  - Internal Table Information
  - Allocated Areas
  - Allocator
  - Process Information
  - Port Information
  - ETS Tables
  - Timers
  - Distribution Information
  - Loaded Module Information
  - Fun Information
  - Process Data
  - Atoms
  - Disclaimer
- How to Implement an Alternative Carrier for the Erlang Distribution
  - Top of chapter
  - Introduction
  - Distribution Module
  - The Driver
  - Putting It All Together
- How to Implement an Alternative Service Discovery for Erlang Distribution
  - Top of chapter
  - Introduction
  - Discovery module
- The Abstract Format
  - Top of chapter
  - Module Declarations and Forms
  - Atomic Literals
  - Patterns
  - Expressions
  - Clauses
  - Guards
  - Types
  - The Abstract Format after Preprocessing
- tty - A Command-Line Interface
  - Top of chapter
  - Normal Mode
  - Shell Break Mode
- How to Implement a Driver
  - Top of chapter
  - Introduction
  - Sample Driver
  - Compiling and Linking the Sample Driver
  - Calling a Driver as a Port in Erlang
  - Sample Asynchronous Driver
  - An Asynchronous Driver Using driver_async
- Inet Configuration
  - Top of chapter
  - Introduction
  - Configuration Data
  - User Configuration Example
- Socket Usage
  - Top of chapter
  - Introduction
  - Socket Options
- External Term Format
  - Top of chapter
  - Introduction
  - Distribution Header
  - ATOM_CACHE_REF
  - SMALL_INTEGER_EXT
  - INTEGER_EXT
  - FLOAT_EXT
  - PORT_EXT
  - NEW_PORT_EXT
  - PID_EXT
  - NEW_PID_EXT
  - SMALL_TUPLE_EXT
  - LARGE_TUPLE_EXT
  - MAP_EXT
  - NIL_EXT
  - STRING_EXT
  - LIST_EXT
  - BINARY_EXT
  - SMALL_BIG_EXT
  - LARGE_BIG_EXT
  - REFERENCE_EXT (deprecated)
  - NEW_REFERENCE_EXT
  - NEWER_REFERENCE_EXT
  - FUN_EXT
  - NEW_FUN_EXT
  - EXPORT_EXT
  - BIT_BINARY_EXT
  - NEW_FLOAT_EXT
  - ATOM_UTF8_EXT
  - SMALL_ATOM_UTF8_EXT
  - ATOM_EXT (deprecated)
  - SMALL_ATOM_EXT (deprecated)
- Distribution Protocol
  - Top of chapter
  - EPMD Protocol
  - Distribution Handshake
  - Protocol between Connected Nodes
  - New Ctrlmessages for distrvsn = 1 (Erlang/OTP R4)
  - New Ctrlmessages for distrvsn = 2
  - New Ctrlmessages for distrvsn = 3 (Erlang/OTP R5C)
  - New Ctrlmessages for distrvsn = 4 (Erlang/OTP R6)
  - New Ctrlmessages for Erlang/OTP 21
  - New Ctrlmessages for Erlang/OTP 22

# 7 How to Implement an Alternative Service Discovery for Erlang Distribution

This section describes how to implement an alternative discovery mechanism for Erlang distribution. Discovery is normally done using DNS and the Erlang Port Mapper Daemon (EPMD) for port discovery.

Note

Support for alternative service discovery mechanisms was added in Erlang/OTP 21.

### 7.1 Introduction

To implement your own service discovery module you have to write your own EPMD module. The EPMD module is responsible for providing the location of another node. The distribution modules (inet_tcp_dist/inet_tls_dist) call the EPMD module to get the IP address and port of the other node. The EPMD module that is part of Erlang/OTP will resolve the hostname using DNS and uses the EPMD unix process to get the port of another node. The EPMD unix process does this by connecting to the other node on a well-known port, port 4369.

### 7.2 Discovery module

The discovery module needs to implement the same API as the regular EPMD module. However, instead of communicating with EPMD you can connect to any service to find out connection details of other nodes. A discovery module is enabled by setting -epmd_module when starting erlang. The discovery module must implement the following callbacks:

start_link/0
  Start any processes needed by the discovery module.
names/1
  Return node names held by the registrar for the given host.
register_node/2
  Register the given node name with the registrar.
port_please/3
  Return the distribution port used by the given node.

The discovery module may implement the following callback:

address_please/3

  Return the address of the given node. If not implemented, erl_epmd:address_please/3 will be used instead.

  This callback may also return the port of the given node. In that case port_please/3 may be omitted.