diff --git a/Tun/Context/SDLContextActor.swift b/Tun/Context/SDLContextActor.swift index 55a32ac..117ab3d 100644 --- a/Tun/Context/SDLContextActor.swift +++ b/Tun/Context/SDLContextActor.swift @@ -469,7 +469,7 @@ extension SDLContextActor { // MARK: 处理和Super之间的通讯 extension SDLContextActor { - private func handleSuperMessage(message: SDLQUICInboundMessage) async { + private func handleSuperMessage(message: SDLSuperMessage) async { switch message { case .welcome(let welcome): SDLLogger.log("[SDLContext] quic welcome: \(welcome)") diff --git a/Tun/Protobuf/SDLMessage.swift b/Tun/Protobuf/SDLMessage.swift index b5ac52d..f03c54e 100644 --- a/Tun/Protobuf/SDLMessage.swift +++ b/Tun/Protobuf/SDLMessage.swift @@ -127,23 +127,6 @@ extension SDLStunProbeReply { } -enum SDLQUICInboundMessage { - // 欢迎消息 - case welcome(SDLWelcome) - - case pong - - // 注册相关 - case registerSuperAck(SDLRegisterSuperAck) - case registerSuperNak(SDLRegisterSuperNak) - - case peerInfo(SDLPeerInfo) - case event(SDLEvent) - case policyReponse(SDLPolicyResponse) - case exposedServiceResponse(SDLExposedServiceResponse) - - case arpResponse(SDLArpResponse) -} // 命令类型 enum SDLEventType: UInt8 { diff --git a/Tun/Super/SDLSuperClient.swift b/Tun/Super/SDLSuperClient.swift index c294b0b..816758e 100644 --- a/Tun/Super/SDLSuperClient.swift +++ b/Tun/Super/SDLSuperClient.swift @@ -11,8 +11,8 @@ import Network final class SDLSuperClient: @unchecked Sendable { private let queue = DispatchQueue(label: "com.sdl.SuperClient.queue") // 专用队列保证线程安全 // 数据流 - public let messageStream: AsyncThrowingStream - private let messageCont: AsyncThrowingStream.Continuation + public let messageStream: AsyncThrowingStream + private let messageCont: AsyncThrowingStream.Continuation private let stateLock = NSLock() private var isStarted = false @@ -25,7 +25,7 @@ final class SDLSuperClient: @unchecked Sendable { init(serverEndpoint: SDLConfiguration.ResolvedServerEndpoint, port: UInt16, maxBufferSize: Int = 2 * 1024 * 1024) { self.maxBufferSize = maxBufferSize - let pairs = AsyncThrowingStream.makeStream(of: SDLQUICInboundMessage.self) + let pairs = AsyncThrowingStream.makeStream(of: SDLSuperMessage.self) self.messageStream = pairs.stream self.messageCont = pairs.continuation diff --git a/Tun/Super/SDLSuperCodec.swift b/Tun/Super/SDLSuperCodec.swift index 9c6b4ce..13c4661 100644 --- a/Tun/Super/SDLSuperCodec.swift +++ b/Tun/Super/SDLSuperCodec.swift @@ -8,7 +8,7 @@ import Foundation import NIOCore enum SDLSuperCodec { - public static func decode(frame: ByteBuffer) -> SDLQUICInboundMessage? { + public static func decode(frame: ByteBuffer) -> SDLSuperMessage? { var buffer = frame guard let type = buffer.readInteger(as: UInt8.self), let packetType = SDLPacketType(rawValue: type) else { diff --git a/Tun/Super/SDLSuperMessage.swift b/Tun/Super/SDLSuperMessage.swift new file mode 100644 index 0000000..db4b0eb --- /dev/null +++ b/Tun/Super/SDLSuperMessage.swift @@ -0,0 +1,25 @@ +// +// SDLQUICInboundMessage.swift +// punchnet +// +// Created by 安礼成 on 2026/5/27. +// +import Foundation + +enum SDLSuperMessage { + // 欢迎消息 + case welcome(SDLWelcome) + + case pong + + // 注册相关 + case registerSuperAck(SDLRegisterSuperAck) + case registerSuperNak(SDLRegisterSuperNak) + + case peerInfo(SDLPeerInfo) + case event(SDLEvent) + case policyReponse(SDLPolicyResponse) + case exposedServiceResponse(SDLExposedServiceResponse) + + case arpResponse(SDLArpResponse) +} diff --git a/Tun/Super/SDLSuperService.swift b/Tun/Super/SDLSuperService.swift index acf6772..ceb65f5 100644 --- a/Tun/Super/SDLSuperService.swift +++ b/Tun/Super/SDLSuperService.swift @@ -1,7 +1,7 @@ import Foundation actor SDLSuperService { - typealias MessageHandler = @Sendable (SDLQUICInboundMessage) async -> Void + typealias MessageHandler = @Sendable (SDLSuperMessage) async -> Void private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint private let port: UInt16 @@ -74,7 +74,7 @@ actor SDLSuperService { } } - private func handleMessage(_ message: SDLQUICInboundMessage, generation: UInt64) async { + private func handleMessage(_ message: SDLSuperMessage, generation: UInt64) async { guard self.generation == generation else { return } diff --git a/Tun/Super/SDLSuperSession.swift b/Tun/Super/SDLSuperSession.swift index 7fb633c..bb3444f 100644 --- a/Tun/Super/SDLSuperSession.swift +++ b/Tun/Super/SDLSuperSession.swift @@ -7,7 +7,7 @@ import Foundation final class SDLSuperSession: @unchecked Sendable { - typealias MessageHandler = @Sendable (SDLQUICInboundMessage) async -> Void + typealias MessageHandler = @Sendable (SDLSuperMessage) async -> Void private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint private let port: UInt16