Skip to content

Commit a06e838

Browse files
committed
Fix network stability: enable Mux and TCP Keep-Alive in VLESS config, fix proxy sidecar bootstrap retention, optimize status ping timeout
1 parent 12abbd9 commit a06e838

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎submodules/TelegramCore/Sources/Network/ProxyServersStatuses.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum ProxyServerStatus: Equatable {
1212
case available(Double)
1313
}
1414

15-
private let proxyStatusPingTimeout: Double = 15.0
15+
private let proxyStatusPingTimeout: Double = 7.0
1616

1717
private func pingProxyStatus(context: MTContext, datacenterId: Int, settings: MTSocksProxySettings) -> Signal<ProxyServerStatus, NoError> {
1818
return Signal { subscriber in

‎submodules/TelegramCore/Sources/Settings/ProxySettings.swift‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,20 @@ func applySharedProxySettingsToNetwork(settings: ProxySettings, network: Network
139139

140140
network.context.updateApiEnvironment { environment in
141141
let current = environment?.socksProxySettings
142-
let updated = resolvedProxySettings
142+
let updated: MTSocksProxySettings?
143+
if isActiveWebProxy || isActiveVlessProxy {
144+
if let resolvedProxySettings = resolvedProxySettings {
145+
updated = resolvedProxySettings
146+
} else if let current = current {
147+
// Sidecar not ready yet (bootstrap / resume) — keep the previous endpoint
148+
// rather than falling back to a direct connection.
149+
updated = current
150+
} else {
151+
updated = nil
152+
}
153+
} else {
154+
updated = resolvedProxySettings
155+
}
143156
let updateNetwork: Bool
144157
if previousForceLocalDNS != settings.useLocalDNSForProxyHosts {
145158
updateNetwork = true

‎submodules/TelegramVLESS/Sources/TelegramVLESS/VlessXrayConfig.swift‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ public enum VlessXrayConfig {
4444
"security": profile.security.rawValue,
4545
]
4646

47-
var sockopt: [String: Any] = [:]
47+
var sockopt: [String: Any] = [
48+
"tcpKeepAliveInterval": 15
49+
]
4850
if let downFrame = profile.sockoptDownFrame {
4951
sockopt["downFrame"] = downFrame
5052
}
5153
if let scStream = profile.sockoptScStreamDownServerSecs {
5254
sockopt["scStreamDownServerSecs"] = scStream
5355
}
54-
if !sockopt.isEmpty {
55-
stream["sockopt"] = sockopt
56-
}
56+
stream["sockopt"] = sockopt
5757
switch profile.transport {
5858
case .tcp:
5959
break
@@ -186,6 +186,10 @@ public enum VlessXrayConfig {
186186
],
187187
],
188188
"streamSettings": stream,
189+
"mux": [
190+
"enabled": true,
191+
"concurrency": 8
192+
]
189193
],
190194
],
191195
]

‎submodules/TelegramVLESS/Tests/TelegramVLESSTests/VlessTests.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ final class VlessTests: XCTestCase {
8686
for inbound in json["inbounds"] as! [[String: Any]] {
8787
XCTAssertEqual(inbound["listen"] as? String, "127.0.0.1")
8888
}
89+
let outbounds = json["outbounds"] as! [[String: Any]]
90+
let vlessOut = outbounds[0]
91+
let mux = vlessOut["mux"] as! [String: Any]
92+
XCTAssertEqual(mux["enabled"] as? Bool, true)
93+
XCTAssertEqual(mux["concurrency"] as? Int, 8)
8994
XCTAssertNil(VlessXrayConfig.configJSON(profile: profile, socks: socks, http: socks))
9095
}
9196
}

0 commit comments

Comments
 (0)