fix
This commit is contained in:
parent
9a76b61ff0
commit
3ce4e05613
@ -134,23 +134,25 @@ public class SDLContext: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.addTask {
|
||||||
|
// 启动网络监控
|
||||||
|
self.monitorCancel = self.monitor.eventFlow.sink { event in
|
||||||
|
switch event {
|
||||||
|
case .changed:
|
||||||
|
// 需要重新探测网络的nat类型
|
||||||
|
Task {
|
||||||
|
self.natType = await SDLNatProber.getNatType(udpHole: self.udpHole, config: self.config)
|
||||||
|
NSLog("didNetworkPathChanged, nat type is: \(self.natType)")
|
||||||
|
}
|
||||||
|
case .unreachable:
|
||||||
|
NSLog("didNetworkPathUnreachable")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.monitor.start()
|
||||||
|
}
|
||||||
|
|
||||||
try await group.waitForAll()
|
try await group.waitForAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启动网络监控
|
|
||||||
self.monitorCancel = self.monitor.eventFlow.sink { event in
|
|
||||||
switch event {
|
|
||||||
case .changed:
|
|
||||||
// 需要重新探测网络的nat类型
|
|
||||||
Task {
|
|
||||||
self.natType = await SDLNatProber.getNatType(udpHole: self.udpHole, config: self.config)
|
|
||||||
NSLog("didNetworkPathChanged, nat type is: \(self.natType)")
|
|
||||||
}
|
|
||||||
case .unreachable:
|
|
||||||
NSLog("didNetworkPathUnreachable")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.monitor.start()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func stop() async {
|
public func stop() async {
|
||||||
@ -376,18 +378,18 @@ public class SDLContext: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 流量统计
|
// 流量统计
|
||||||
public func flowReportTask() {
|
// public func flowReportTask() {
|
||||||
Task {
|
// Task {
|
||||||
// 每分钟汇报一次
|
// // 每分钟汇报一次
|
||||||
self.flowTracerCancel = Timer.publish(every: 60.0, on: .main, in: .common).autoconnect()
|
// self.flowTracerCancel = Timer.publish(every: 60.0, on: .main, in: .common).autoconnect()
|
||||||
.sink { _ in
|
// .sink { _ in
|
||||||
Task {
|
// Task {
|
||||||
let (forwardNum, p2pNum, inboundNum) = await self.flowTracer.reset()
|
// let (forwardNum, p2pNum, inboundNum) = await self.flowTracer.reset()
|
||||||
await self.superClient?.flowReport(forwardNum: forwardNum, p2pNum: p2pNum, inboundNum: inboundNum)
|
// await self.superClient?.flowReport(forwardNum: forwardNum, p2pNum: p2pNum, inboundNum: inboundNum)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 网络改变时需要重新配置网络信息
|
// 网络改变时需要重新配置网络信息
|
||||||
private func didNetworkConfigChanged(devAddr: SDLDevAddr, dnsServers: [String]? = nil) async {
|
private func didNetworkConfigChanged(devAddr: SDLDevAddr, dnsServers: [String]? = nil) async {
|
||||||
@ -406,7 +408,7 @@ public class SDLContext: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSLog("[SDLContext] Tun started at network ip: \(netAddress.ipAddress), mask: \(netAddress.maskAddress)")
|
NSLog("[SDLContext] Tun started at network ip: \(netAddress.ipAddress), mask: \(netAddress.maskAddress)")
|
||||||
|
|
||||||
let ipv4Settings = NEIPv4Settings(addresses: [netAddress.ipAddress], subnetMasks: [netAddress.maskAddress])
|
let ipv4Settings = NEIPv4Settings(addresses: [netAddress.ipAddress], subnetMasks: [netAddress.maskAddress])
|
||||||
// 设置路由表
|
// 设置路由表
|
||||||
//NEIPv4Route.default()
|
//NEIPv4Route.default()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user