修复休眠恢复的问题

This commit is contained in:
anlicheng 2026-05-04 20:45:12 +08:00
parent dcbaffe70e
commit ad6f7a8c42
3 changed files with 24 additions and 39 deletions

View File

@ -28,22 +28,22 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
return
}
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
completionHandler(err)
}))
if self.runtimeEnv == nil {
let rsaCipher = try! CCRSACipher(keySize: 1024)
self.runtimeEnv = SDLRuntimeEnvironment(config: config, rsaCipher: rsaCipher, provider: self)
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: {
completionHandler()
}))
}
self.runtimeEnv?.submitCommand(command: .stop(completion: {
completionHandler()
}))
}
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
@ -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: {
SDLLogger.log("[PacketTunnelProvider] sleep")
}))
}
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
SDLLogger.log("[PacketTunnelProvider] wakeup and try start")
}))
}
//
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
}

View File

@ -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()
}
self.prepareTunnelNotifier()
// arp
await self.puncherActor.start()

View File

@ -5,12 +5,12 @@ enum SDLRuntimeEnvironmentCommand {
case stop(completion: @Sendable () -> Void)
}
actor SDLRuntimeEnvironment {
final class SDLRuntimeEnvironment {
private enum State {
case idle
case running
}
private var state: State = .idle
private var contextActor: SDLContextActor?
@ -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()
}
}