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