Xirsys.XTurn.TimedEntry (xturn v2.0.0)

Copy Markdown View Source

Map of values with per-key expiry timers.

What problem this solves

TURN permissions and channel bindings expire unless refreshed. Each allocation tracks many peers and channels, each with its own lifetime. This module wraps a map with Process.send_after/3 so inserting or replacing a key cancels the old timer and schedules a new expiry message to the owning process.

Internal note

Used inside allocation GenServers; not configured by operators.

RFCs

  • RFC 5766 (permission and channel lifetimes)

Summary

Functions

Cancels every timer in the map and returns an empty map.

Fetches the value stored under key, ignoring the timer reference.

Returns whether key exists in the timed-entry map.

Returns all keys in the timed-entry map.

Inserts value under key, scheduling expire_msg to owner after lifetime_ms.

Removes key from the map, cancelling its timer when present.

Functions

cancel_all(map)

Cancels every timer in the map and returns an empty map.

Parameters

  • map - timed-entry map

fetch(map, key)

Fetches the value stored under key, ignoring the timer reference.

has_key?(map, key)

Returns whether key exists in the timed-entry map.

keys(map)

Returns all keys in the timed-entry map.

Parameters

  • map - timed-entry map

Examples

iex> ref = make_ref()
iex> map = %{"a" => {ref, 1}, "b" => {ref, 2}}
iex> Xirsys.XTurn.TimedEntry.keys(map)
["a", "b"]

put(map, key, value, lifetime_ms, owner, expire_msg)

Inserts value under key, scheduling expire_msg to owner after lifetime_ms.

Any existing entry for key is removed (and its timer cancelled) first.

Parameters

  • map - timed-entry map
  • key - map key (typically peer IP or channel number)
  • value - stored payload
  • lifetime_ms - milliseconds until expiry message is sent
  • owner - process that receives expire_msg
  • expire_msg - message sent when the timer fires

remove(map, key)

Removes key from the map, cancelling its timer when present.

Parameters

  • map - timed-entry map
  • key - map key