From 4e4a6d745c37b2a16fedcbceaaa7f9cffb762ece Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 01:26:36 -0700 Subject: [PATCH] control-channel: a matrix change resets the dial budget --- Sources/MWBNet/ControlChannel.swift | 13 ++++++++++--- docs/features/control-channel/README.md | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Sources/MWBNet/ControlChannel.swift b/Sources/MWBNet/ControlChannel.swift index 52ab313..021f367 100644 --- a/Sources/MWBNet/ControlChannel.swift +++ b/Sources/MWBNet/ControlChannel.swift @@ -128,12 +128,19 @@ public final class ControlChannel: @unchecked Sendable { public func reconfigure(_ new: ChannelConfig) { queue.async { [self] in let full = new.needsFullReopen(comparedTo: config) + let matrixChanged = new.matrixNames != config.matrixNames config = new - if full { + guard !full else { reopen() - } else { - updateClients(now: monotonicNow()) + return } + if matrixChanged { + // Editing the matrix is a reconnect trigger: a name added after + // the connect budget expired must get its own 30 s to answer. + dialers.removeAll() + dialDeadline = monotonicNow() + ControlChannel.connectTimeout + } + updateClients(now: monotonicNow()) } } diff --git a/docs/features/control-channel/README.md b/docs/features/control-channel/README.md index 7cf36d1..aab54e2 100644 --- a/docs/features/control-channel/README.md +++ b/docs/features/control-channel/README.md @@ -67,7 +67,10 @@ No packet is interpreted here. - **Reconnect triggers** (ยง3.3): `NWPathMonitor` status change, an explicit `reopenAll()` (the app calls it on wake, display change and the reconnect hotkey), a connection reset, and the settings change of - key/port/matrix (the app calls `reconfigure(_:)`). + key/port/matrix (the app calls `reconfigure(_:)`). A key, port, local + name or local id change reopens everything; a matrix change clears the + dial state and grants a fresh 30 s budget, so a slot edited after the + budget expired is actually dialled. - **Ticks**: the channel runs one 100 ms `DispatchSourceTimer` that calls `Session.tick(now:userActive:)` on every connection (the app reports `userActive` via `noteUserActivity()`), drains outboxes and