Xirsys.XTurn.AddressFamily (xturn v2.0.0)

Copy Markdown View Source

IPv4/IPv6 address-family constants for TURN Allocate and Refresh.

What problem this solves

Dual-stack TURN clients request relay addresses in a specific IP version via REQUESTED-ADDRESS-FAMILY and related attributes. The server must compare those four-byte values, map Erlang IP tuples to internal family ids (4 / 8), and encode ADDRESS-ERROR-CODE when a family cannot be honored.

Internal note

Used by allocation and action handlers; not an operator API.

RFCs

  • RFC 8656 (REQUESTED-ADDRESS-FAMILY, ADDITIONAL-ADDRESS-FAMILY, ADDRESS-ERROR-CODE)
  • RFC 5766 (base TURN allocation)

Summary

Functions

Builds an ADDRESS-ERROR-CODE attribute binary.

Returns whether attrs carry an ADDITIONAL-ADDRESS-FAMILY of IPv6.

Maps an IP tuple to relay family 4, 8, or nil when unrecognized.

Four-byte REQUESTED-ADDRESS-FAMILY value for IPv4 (0x01).

Four-byte REQUESTED-ADDRESS-FAMILY value for IPv6 (0x02).

Returns whether Allocate attrs request an IPv6 relay address.

Functions

address_error_code(family_byte, err_no, reason)

Builds an ADDRESS-ERROR-CODE attribute binary.

Parameters

  • family_byte - address-family byte (e.g. 1 for IPv4)
  • err_no - three-digit STUN error number (class * 100 + number)
  • reason - UTF-8 reason phrase

dual_additional?(attrs)

Returns whether attrs carry an ADDITIONAL-ADDRESS-FAMILY of IPv6.

Used for dual-stack Allocate requests per RFC 8656.

Parameters

  • attrs - decoded STUN attribute map (may include :additional_address_family)

family_of(arg1)

Maps an IP tuple to relay family 4, 8, or nil when unrecognized.

Examples

iex> Xirsys.XTurn.AddressFamily.family_of({127, 0, 0, 1})
4

iex> Xirsys.XTurn.AddressFamily.family_of({0, 0, 0, 0, 0, 0, 0, 1})
8

iex> Xirsys.XTurn.AddressFamily.family_of(:not_an_address)
nil

ipv4()

Four-byte REQUESTED-ADDRESS-FAMILY value for IPv4 (0x01).

ipv6()

Four-byte REQUESTED-ADDRESS-FAMILY value for IPv6 (0x02).

ipv6_requested?(attrs)

Returns whether Allocate attrs request an IPv6 relay address.

Examples

iex> alias Xirsys.XTurn.AddressFamily
iex> AddressFamily.ipv6_requested?(%{requested_address_type: AddressFamily.ipv6()})
true

iex> Xirsys.XTurn.AddressFamily.ipv6_requested?(%{})
false