Xirsys.XTurn.ListenRegistry (xturn v2.0.0)

Copy Markdown View Source

Stable {transport, socket} lookup per bound {ip, port} endpoint.

What problem this solves

With SO_REUSEPORT, multiple UDP listener processes bind the same port. RFC 5780 CHANGE-REQUEST replies must come from a predictable socket on the alternate address or port. The first shard to bind registers in this ETS table; later shards forward traffic but are not chosen as 5780 reply sources.

Internal note

Populated at listener startup by DatagramListener; not configured directly.

RFCs

  • RFC 5780 (alternate source for Binding replies)

Summary

Functions

Creates the public ETS table if it does not exist.

Looks up {transport, socket} for endpoint, or :error if unset.

Records the first {transport, socket} bound to endpoint.

Removes the registry entry for endpoint.

Functions

ensure!()

@spec ensure!() :: :ok

Creates the public ETS table if it does not exist.

lookup(endpoint)

@spec lookup({:inet.ip_address(), :inet.port_number()}) ::
  {:ok, {module(), term()}} | :error

Looks up {transport, socket} for endpoint, or :error if unset.

register(endpoint, arg)

@spec register({:inet.ip_address(), :inet.port_number()}, {module(), term()}) :: :ok

Records the first {transport, socket} bound to endpoint.

Uses :ets.insert_new/2 so only the first registrant wins (RFC 5780 stable source).

unregister(endpoint)

@spec unregister({:inet.ip_address(), :inet.port_number()}) :: :ok

Removes the registry entry for endpoint.