5. 分配
所有 TURN 操作都围绕 allocation (分配) 展开, 并且所有 TURN 消息都与某个 allocation 相关联. 从概念上讲, 一个 allocation 包含以下状态数据:
-
relayed transport address (中继传输地址)
-
5-tuple (五元组): (client 的 IP 地址, client 的端口, server IP 地址, server 端口, transport protocol)
-
认证信息
-
time-to-expiry (到期剩余时间)
-
permission (权限) 列表
-
channel 到 peer 的绑定列表
relayed transport address 是 server 为与 peer 通信而分配的 transport address, 而 5-tuple 描述 client 与 server 之间的通信路径. 在 client 上, 5-tuple 使用 client 的 host transport address; 在 server 上, 5-tuple 使用 client 的 server-reflexive transport address.
relayed transport address 和 5-tuple 在所有 allocation 中都必须唯一, 因此任意一个都可以用来唯一标识 allocation.
认证信息 (例如 username, password, realm, 和 nonce) 同时用于验证后续请求, 以及计算响应的 message integrity (消息完整性). username, realm, 和 nonce 的初始值来自创建该 allocation 的已认证 Allocate request, 但 server 可以在 allocation 生命周期内通过 438 (Stale Nonce) 响应改变 nonce 值. 注意, 出于安全原因, server 可能更适合存储 key 值, 而不是显式存储 password; 该 key 是对 username, realm, 和 password 计算得到的 MD5 hash (见 [RFC5389]).
time-to-expiry 是 allocation 过期前剩余的秒数. 每个 Allocate 或 Refresh transaction 都会设置此计时器, 随后计时器向 0 递减. 默认情况下, 每个 Allocate 或 Refresh transaction 都会将此计时器重置为默认 lifetime 值 600 秒 (10 分钟), 但 client 可以在 Allocate 和 Refresh request 中请求不同的值. allocation 只能使用 Refresh request 刷新; 向 peer 发送数据不会刷新 allocation. 当 allocation 过期时, 可以释放与该 allocation 关联的状态数据.
permission 列表在第 8 章描述, channel 列表在第 11 章描述.