Net: 8 s health-check timeout, show a dead proxy only after two misses
AmneziaWG 3 tunnels idle for a while need 5+ s for the first handshake, so the 4-5 s checks marked working connections as dead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,16 @@ final class NetCore: ObservableObject {
|
||||
|
||||
/// Delays measured by the group test (covers the subscription nodes too).
|
||||
private var measured: [String: Int] = [:]
|
||||
/// Failed checks in a row per proxy. An AmneziaWG 3 tunnel idle for a while can miss one
|
||||
/// check while its handshake warms up, so «нет ответа» is shown only after two misses.
|
||||
private var misses: [String: Int] = [:]
|
||||
|
||||
private func record(_ name: String, _ delay: Int) {
|
||||
if delay > 0 { misses[name] = 0; measured[name] = delay; return }
|
||||
let n = (misses[name] ?? 0) + 1
|
||||
misses[name] = n
|
||||
if n >= 2 { measured[name] = 0 } // first miss: keep the previous result
|
||||
}
|
||||
|
||||
static let clientInfo: [String: (title: String, subnet: String)] = [
|
||||
"saga": ("Сага", "192.168.8.0/24"),
|
||||
@@ -143,6 +153,8 @@ final class NetCore: ObservableObject {
|
||||
awgNames.sort()
|
||||
func lastDelay(_ name: String) -> Int? {
|
||||
if let d = measured[name] { return d }
|
||||
// One miss so far: the core's history already says 0, don't show it yet.
|
||||
if misses[name] == 1 { return nil }
|
||||
if let h = proxies[name]?["history"] as? [[String: Any]], let d = h.last?["delay"] as? Int { return d }
|
||||
return providerDelay[name]
|
||||
}
|
||||
@@ -186,17 +198,17 @@ final class NetCore: ObservableObject {
|
||||
func measure() async {
|
||||
busy = true
|
||||
if let m = (await call(["cmd": "delay", "group": "ai-out"], timeout: 15))?["delays"] as? [String: Int] {
|
||||
measured = m
|
||||
// Members that didn't answer are missing from the map: mark them dead.
|
||||
for e in exits where e.id != "auto" && m[e.id] == nil { measured[e.id] = 0 }
|
||||
for (k, v) in m { record(k, v) }
|
||||
// Members that didn't answer are missing from the map: count a miss.
|
||||
for e in exits where e.id != "auto" && m[e.id] == nil { record(e.id, 0) }
|
||||
}
|
||||
if let m = (await call(["cmd": "delay", "group": "amnezia"], timeout: 15))?["delays"] as? [String: Int] {
|
||||
for (k, v) in m { measured[k] = v }
|
||||
for c in amneziaConns where c.id != "amnezia-auto" && m[c.id] == nil { measured[c.id] = 0 }
|
||||
for (k, v) in m { record(k, v) }
|
||||
for c in amneziaConns where c.id != "amnezia-auto" && m[c.id] == nil { record(c.id, 0) }
|
||||
}
|
||||
for c in clients where c.on {
|
||||
if let m = (await call(["cmd": "delay", "proxy": c.id], timeout: 15))?["delays"] as? [String: Int] {
|
||||
for (k, v) in m { measured[k] = v }
|
||||
for (k, v) in m { record(k, v) }
|
||||
}
|
||||
}
|
||||
await refresh()
|
||||
@@ -216,7 +228,7 @@ final class NetCore: ObservableObject {
|
||||
_ = await call(["cmd": "select", "group": "\(id)-sw", "name": on ? id : off])
|
||||
SoundEngine.shared.play(on ? "pop" : "close")
|
||||
if on, let m = (await call(["cmd": "delay", "proxy": id], timeout: 15))?["delays"] as? [String: Int] {
|
||||
for (k, v) in m { measured[k] = v }
|
||||
for (k, v) in m { record(k, v) }
|
||||
}
|
||||
await refresh()
|
||||
}
|
||||
@@ -267,7 +279,7 @@ final class NetCore: ObservableObject {
|
||||
busy = false
|
||||
if r?["ok"] as? Bool == true {
|
||||
lastError = nil
|
||||
measured.removeValue(forKey: name)
|
||||
measured.removeValue(forKey: name); misses.removeValue(forKey: name)
|
||||
SoundEngine.shared.play(cmd == "hide" ? "close" : "pop")
|
||||
} else {
|
||||
lastError = "Не получилось: \(r?["error"] as? String ?? "помощник не ответил")."
|
||||
|
||||
Reference in New Issue
Block a user