Phase 4:RFC 3261 §17 四个事务 FSM + 时间轮 + 事务表 - #9
Draft
lixuanqun wants to merge 1 commit into
Draft
Conversation
模块结构 - Timing:RFC §A 全部 11 个定时器 (T1/T2/T4, Timer A/B/D/E/F/G/H/I/J/K) · timerA/E/G(attempt) 指数退避(封顶 T2/T1 的 2^n) - TimerScheduler:单线程 scheduler + 虚拟线程派发的简洁实现 · 回调跑在虚拟线程上,不阻塞 timer wheel · 可换成 HashedWheelTimer 而不影响调用方 - TransactionKey:RFC §17.1.3/§17.2.3 三元组 (branch, sent-by, method) · 强制 RFC 3261 magic cookie 'z9hG4bK' · ACK 匹配可覆盖 method=INVITE - TransactionTable:ConcurrentHashMap<TransactionKey, Transaction> - MessageSender:发送 SPI(解耦事务层与 transport,便于单测) 四个 FSM(RFC §17) - NonInviteClientTransaction (§17.1.2) · Trying → Proceeding → Completed → Terminated · Timer E 重传(UDP 才有)、Timer F 超时、Timer K 完成等待 - NonInviteServerTransaction (§17.2.2) · Trying → Proceeding → Completed → Terminated · Timer J 寿命;重传请求时重放上一响应 - InviteClientTransaction (§17.1.1) · Calling → Proceeding → (Completed | Terminated) · Timer A 重传(指数退避)、Timer B 超时、Timer D 完成等待 · 2xx → 立即 Terminated(TU 负责 ACK) · 3xx-6xx → 自动发 ACK(§17.1.1.3);重传 final → 重发 ACK - InviteServerTransaction (§17.2.1) · Proceeding → Completed → Confirmed → Terminated · 2xx → 立即 Terminated(TU 接管) · 3xx-6xx → Timer G 重传、Timer H 超时等 ACK;ACK → Confirmed · Timer I 在 Confirmed 等吸收重传 ACK 测试覆盖(18 个) - TransactionKeyTest:4 个(成功派生、缺 branch、缺 magic cookie、ACK 重写) - NonInviteClientTransactionTest:4 个(200 OK、Provisional+Final、retransmit absorb、Timer E) - NonInviteServerTransactionTest:3 个(初次请求、完成态、retransmit 重发响应) - InviteClientTransactionTest:4 个(2xx 立即 Terminate、非 2xx → ACK、retransmit 重发 ACK、方法校验) - InviteServerTransactionTest:3 个(2xx 立即 Terminate、非 2xx → ACK → Confirmed、retransmit INVITE) RecordingSender 通用测试 fixture 让 FSM 完全可测,无需真实 transport。 mvn verify:9 模块 SUCCESS,总 140 tests。 Co-authored-by: li xuanqun <793005378@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
实装 RFC 3261 §17 全部四个事务 FSM 以及配套基础设施。这是协议栈的核心机器。
设计
TimerScheduler——ScheduledExecutorService+ 虚拟线程派发HashedWheelTimer不动调用方Timing—— RFC §A 11 个定时器常量T1=500ms / T2=4s / T4=5sTimer A / E / G用timerN(attempt)实现指数退避(封顶 T2)Timer B = F = H = 64*T1 = 32sTimer D/I/J/K= 0(立即终结)TransactionKey——(branch, sent-by, method)三元组z9hG4bKoverrideMethod=INVITE(让 ACK 命中原 INVITE 服务端事务)TransactionTable——ConcurrentHashMapMessageSender—— 单方法 SPI(send(message, peer) → CompletableFuture<Void>)RecordingSender四个 FSM
NonInviteClientTransactionNonInviteServerTransactionInviteClientTransactionInviteServerTransaction关键 RFC 行为
测试
5 个测试类,18 个 dynamic-test items:
TransactionKeyTest— 4 个(成功派生 / 缺 branch / 缺 magic cookie / ACK 重写)NonInviteClientTransactionTest— 4 个NonInviteServerTransactionTest— 3 个InviteClientTransactionTest— 4 个(含自动 ACK 生成、retransmit ACK 重发)InviteServerTransactionTest— 3 个RecordingSender测试 fixture 让所有 FSM 在 1.5 秒内跑完,无需真实网络。验证