6. ICE Candidate 处理
本节描述 ICE agent 如何处理从对等方收到的 candidate 信息.
6.1. 完整实现的过程
6.1.1. 确定角色
对于每个会话, 每个 ICE agent 都承担一个角色. 共有两种角色 -- controlling 和 controlled. Controlling agent 负责选择最终用于通信的 candidate pair.
启动 ICE 处理的发起 agent MUST 承担 controlling 角色, 另一个 agent MUST 承担 controlled 角色.
6.1.2. 形成 Candidate Pair
ICE agent 通过将自己的 candidate (local candidate) 与从对等方收到的 candidate (remote candidate) 配对来形成 candidate pair.
6.1.3. 计算 Pair Priority 并排序 Pair
Candidate pair 的 priority 使用以下公式计算:
pair priority = 2^32 * MIN(G,D) + 2 * MAX(G,D) + (G>D?1:0)
其中 G 是 controlling agent 的 candidate 的 priority, D 是 controlled agent 的 candidate 的 priority.
6.1.4. 剪除 Pair
Agent 将剪除 candidate pair 列表, 以消除冗余并限制要执行的 connectivity check 数量.