Xirsys.Sockets.Conn (xturn_sockets v2.2.1)

View Source

Transport-level connection context passed to handlers.

Built by Connection (streams) or DatagramServer (datagrams). Handlers read addresses and assigns; they do not own the socket.

iex> conn = %Xirsys.Sockets.Conn{client_ip: {127, 0, 0, 1}, client_port: 3478}
iex> conn.client_port
3478
iex> conn.assigns
%{}

What problem this solves

Handler callbacks need peer and local 5-tuple data plus caller metadata without exposing raw socket ownership. %Conn{} is the stable read-only view XTurn handlers use for logging, rate limits, and reply routing.

RFCs

Addresses and ports align with ICE/STUN/TURN endpoint identifiers:

  • RFC 8489 (STUN server reflexive / mapped address)
  • RFC 8656 (TURN 5-tuple allocation)
  • RFC 8445 (ICE candidate transport address)

Summary

Types

t()

Connection context passed to Xirsys.Sockets.Handler callbacks.

Types

t()

@type t() :: %Xirsys.Sockets.Conn{
  assigns: map(),
  client_ip: :inet.ip_address() | nil,
  client_port: :inet.port_number() | nil,
  listener: pid() | nil,
  server_ip: :inet.ip_address() | nil,
  server_port: :inet.port_number() | nil,
  socket: term()
}

Connection context passed to Xirsys.Sockets.Handler callbacks.

Fields

  • :listener - Acceptor or DatagramServer pid, if any
  • :socket - opaque transport socket handle
  • :client_ip - peer IP; updated per datagram on UDP
  • :client_port - peer port; updated per datagram on UDP
  • :server_ip - local bind IP
  • :server_port - local bind port
  • :assigns - caller-supplied map; unchanged by the engine