Xirsys.XTurn.Plugin.Lifecycle (xturn v2.0.0)

Copy Markdown View Source

Attaches and detaches relay plugins when allocations start and end.

What problem this solves

Plugins must bind to a specific TURN allocation for their lifetime: active modules run inline on each frame; passive modules get a dedicated GenServer. This module builds the per-allocation Plugin.Chain from configured modules, writes it to Plugin.Table, registers monitors via Plugin.Manager, and tears down passive instances with the allocation's actual exit reason.

Called from allocation setup and owner monitor paths. Errors are logged and never fail the underlying Allocate.

RFCs

  • RFC 5766 (TURN allocations plugins follow)
  • RFC 8656 (updated TURN allocation lifecycle)

Summary

Functions

Detaches plugins and stops passive instances for a ended allocation.

Attaches plugins for a new allocation and registers teardown monitors.

Functions

allocation_ended(tuple5, reason)

Detaches plugins and stops passive instances for a ended allocation.

Atomically claims the chain row via Table.take/1 so concurrent teardown paths cannot both act on the same instances.

allocation_started(allocation)

Attaches plugins for a new allocation and registers teardown monitors.

Writes the plugin chain to Plugin.Table before registering monitors so a concurrent :DOWN cannot arrive before the row exists.