修复休眠恢复的问题
This commit is contained in:
parent
dcbaffe70e
commit
ad6f7a8c42
@ -28,22 +28,22 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let rsaCipher = try! CCRSACipher(keySize: 1024)
|
if self.runtimeEnv == nil {
|
||||||
self.runtimeEnv = SDLRuntimeEnvironment(config: config, rsaCipher: rsaCipher, provider: self)
|
let rsaCipher = try! CCRSACipher(keySize: 1024)
|
||||||
Task {
|
self.runtimeEnv = SDLRuntimeEnvironment(config: config, rsaCipher: rsaCipher, provider: self)
|
||||||
await self.runtimeEnv?.submitCommand(command: .start(completion: { err in
|
self.runtimeEnv?.run()
|
||||||
completionHandler(err)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.runtimeEnv?.submitCommand(command: .start(completion: { err in
|
||||||
|
completionHandler(err)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||||
// Add code here to start the process of stopping the tunnel.
|
// Add code here to start the process of stopping the tunnel.
|
||||||
Task {
|
self.runtimeEnv?.submitCommand(command: .stop(completion: {
|
||||||
await self.runtimeEnv?.submitCommand(command: .stop(completion: {
|
completionHandler()
|
||||||
completionHandler()
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
|
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
|
||||||
@ -66,27 +66,23 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
|
|
||||||
override func sleep(completionHandler: @escaping () -> Void) {
|
override func sleep(completionHandler: @escaping () -> Void) {
|
||||||
// Add code here to get ready to sleep.
|
// Add code here to get ready to sleep.
|
||||||
Task {
|
self.runtimeEnv?.submitCommand(command: .stop(completion: {
|
||||||
await self.runtimeEnv?.submitCommand(command: .stop(completion: {
|
SDLLogger.log("[PacketTunnelProvider] sleep")
|
||||||
SDLLogger.log("[PacketTunnelProvider] sleep")
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
completionHandler()
|
completionHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func wake() {
|
override func wake() {
|
||||||
SDLLogger.log("[PacketTunnelProvider] wake up!!!!!!!")
|
SDLLogger.log("[PacketTunnelProvider] wake up!!!!!!!")
|
||||||
// Add code here to wake up.
|
// Add code here to wake up.
|
||||||
Task {
|
// 重新启动
|
||||||
// 重新启动
|
self.runtimeEnv?.submitCommand(command: .start(completion: { err in
|
||||||
await self.runtimeEnv?.submitCommand(command: .start(completion: { err in
|
SDLLogger.log("[PacketTunnelProvider] wakeup and try start")
|
||||||
SDLLogger.log("[PacketTunnelProvider] wakeup and try start")
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleAppRequest(message: AppRequest) async throws -> Data? {
|
private func handleAppRequest(message: AppRequest) async throws -> Data? {
|
||||||
guard let contextActor = await self.runtimeEnv?.getContextActor() else {
|
guard let contextActor = self.runtimeEnv?.getContextActor() else {
|
||||||
throw TunnelError.invalidContext
|
throw TunnelError.invalidContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ actor SDLContextActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var config: SDLConfiguration
|
private var config: SDLConfiguration
|
||||||
// nat的网络类型
|
// nat的网络类型
|
||||||
var natType: SDLNATProberActor.NatType = .blocked
|
var natType: SDLNATProberActor.NatType = .blocked
|
||||||
|
|
||||||
@ -119,13 +119,7 @@ actor SDLContextActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func start() async {
|
public func start() async {
|
||||||
await self.startRuntime(resetNotifier: true)
|
self.prepareTunnelNotifier()
|
||||||
}
|
|
||||||
|
|
||||||
private func startRuntime(resetNotifier: Bool) async {
|
|
||||||
if resetNotifier {
|
|
||||||
self.prepareTunnelNotifier()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 启动arp的定时清理任务
|
// 启动arp的定时清理任务
|
||||||
await self.puncherActor.start()
|
await self.puncherActor.start()
|
||||||
|
|||||||
@ -5,7 +5,7 @@ enum SDLRuntimeEnvironmentCommand {
|
|||||||
case stop(completion: @Sendable () -> Void)
|
case stop(completion: @Sendable () -> Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
actor SDLRuntimeEnvironment {
|
final class SDLRuntimeEnvironment {
|
||||||
private enum State {
|
private enum State {
|
||||||
case idle
|
case idle
|
||||||
case running
|
case running
|
||||||
@ -104,14 +104,9 @@ actor SDLRuntimeEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shutdown() {
|
deinit {
|
||||||
self.commandCont.finish()
|
self.commandCont.finish()
|
||||||
self.commandTask?.cancel()
|
self.commandTask?.cancel()
|
||||||
self.commandTask = nil
|
self.commandTask = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
|
||||||
self.commandCont.finish()
|
|
||||||
self.commandTask?.cancel()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user