Xirsys.XTurn.ClientSocket (xturn v2.0.0)

Copy Markdown View Source

Outbound send handle for data and STUN replies to the TURN client.

What problem this solves

Allocations and the data plane must send ChannelData, indications, and STUN responses back to the client over UDP, TCP, DTLS, or TLS. This struct bundles the transport module, underlying socket, and default client endpoint so send paths do not duplicate transport-specific logic.

Internal note

Created per message in workers and stored on allocations; not operator-facing.

RFCs

Summary

Types

t()

Client-facing send handle.

Functions

Builds a %ClientSocket{} from an XSockets.Conn and transport module.

Builds a client send handle from transport module, socket, and client endpoint.

Types

t()

@type t() :: %Xirsys.XTurn.ClientSocket{
  client_ip: :inet.ip_address() | nil,
  client_port: pos_integer() | nil,
  socket: term(),
  transport: module()
}

Client-facing send handle.

Fields

  • :transport - XSockets.Transport.* module for send/4
  • :socket - OS port, library conn socket, PID test stub, or :fake
  • :client_ip - default destination IP (may be nil for connected TCP)
  • :client_port - default destination port

Functions

from_library_conn(conn, transport)

@spec from_library_conn(XSockets.Conn.t(), module()) :: t()

Builds a %ClientSocket{} from an XSockets.Conn and transport module.

new(transport, socket, client_ip, client_port)

@spec new(module(), term(), :inet.ip_address() | nil, pos_integer() | nil) :: t()

Builds a client send handle from transport module, socket, and client endpoint.

send(client, data, dest_ip \\ nil, dest_port \\ nil)

@spec send(t(), iodata(), :inet.ip_address() | nil, :inet.port_number() | nil) ::
  :ok | {:error, term()}

Sends data to the client.

Uses dest_ip/dest_port when provided, otherwise the stored client endpoint. PID and :fake sockets are handled for tests and worker relay paths.