fix super message
This commit is contained in:
parent
32014d9634
commit
78ec74a0cb
@ -469,7 +469,7 @@ extension SDLContextActor {
|
|||||||
// MARK: 处理和Super之间的通讯
|
// MARK: 处理和Super之间的通讯
|
||||||
extension SDLContextActor {
|
extension SDLContextActor {
|
||||||
|
|
||||||
private func handleSuperMessage(message: SDLQUICInboundMessage) async {
|
private func handleSuperMessage(message: SDLSuperMessage) async {
|
||||||
switch message {
|
switch message {
|
||||||
case .welcome(let welcome):
|
case .welcome(let welcome):
|
||||||
SDLLogger.log("[SDLContext] quic welcome: \(welcome)")
|
SDLLogger.log("[SDLContext] quic welcome: \(welcome)")
|
||||||
|
|||||||
@ -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 {
|
enum SDLEventType: UInt8 {
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import Network
|
|||||||
final class SDLSuperClient: @unchecked Sendable {
|
final class SDLSuperClient: @unchecked Sendable {
|
||||||
private let queue = DispatchQueue(label: "com.sdl.SuperClient.queue") // 专用队列保证线程安全
|
private let queue = DispatchQueue(label: "com.sdl.SuperClient.queue") // 专用队列保证线程安全
|
||||||
// 数据流
|
// 数据流
|
||||||
public let messageStream: AsyncThrowingStream<SDLQUICInboundMessage, Error>
|
public let messageStream: AsyncThrowingStream<SDLSuperMessage, Error>
|
||||||
private let messageCont: AsyncThrowingStream<SDLQUICInboundMessage, Error>.Continuation
|
private let messageCont: AsyncThrowingStream<SDLSuperMessage, Error>.Continuation
|
||||||
|
|
||||||
private let stateLock = NSLock()
|
private let stateLock = NSLock()
|
||||||
private var isStarted = false
|
private var isStarted = false
|
||||||
@ -25,7 +25,7 @@ final class SDLSuperClient: @unchecked Sendable {
|
|||||||
init(serverEndpoint: SDLConfiguration.ResolvedServerEndpoint, port: UInt16, maxBufferSize: Int = 2 * 1024 * 1024) {
|
init(serverEndpoint: SDLConfiguration.ResolvedServerEndpoint, port: UInt16, maxBufferSize: Int = 2 * 1024 * 1024) {
|
||||||
self.maxBufferSize = maxBufferSize
|
self.maxBufferSize = maxBufferSize
|
||||||
|
|
||||||
let pairs = AsyncThrowingStream.makeStream(of: SDLQUICInboundMessage.self)
|
let pairs = AsyncThrowingStream.makeStream(of: SDLSuperMessage.self)
|
||||||
self.messageStream = pairs.stream
|
self.messageStream = pairs.stream
|
||||||
self.messageCont = pairs.continuation
|
self.messageCont = pairs.continuation
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import Foundation
|
|||||||
import NIOCore
|
import NIOCore
|
||||||
|
|
||||||
enum SDLSuperCodec {
|
enum SDLSuperCodec {
|
||||||
public static func decode(frame: ByteBuffer) -> SDLQUICInboundMessage? {
|
public static func decode(frame: ByteBuffer) -> SDLSuperMessage? {
|
||||||
var buffer = frame
|
var buffer = frame
|
||||||
guard let type = buffer.readInteger(as: UInt8.self),
|
guard let type = buffer.readInteger(as: UInt8.self),
|
||||||
let packetType = SDLPacketType(rawValue: type) else {
|
let packetType = SDLPacketType(rawValue: type) else {
|
||||||
|
|||||||
25
Tun/Super/SDLSuperMessage.swift
Normal file
25
Tun/Super/SDLSuperMessage.swift
Normal file
@ -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)
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
actor SDLSuperService {
|
actor SDLSuperService {
|
||||||
typealias MessageHandler = @Sendable (SDLQUICInboundMessage) async -> Void
|
typealias MessageHandler = @Sendable (SDLSuperMessage) async -> Void
|
||||||
|
|
||||||
private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint
|
private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint
|
||||||
private let port: UInt16
|
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 {
|
guard self.generation == generation else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class SDLSuperSession: @unchecked Sendable {
|
final class SDLSuperSession: @unchecked Sendable {
|
||||||
typealias MessageHandler = @Sendable (SDLQUICInboundMessage) async -> Void
|
typealias MessageHandler = @Sendable (SDLSuperMessage) async -> Void
|
||||||
|
|
||||||
private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint
|
private let serverEndpoint: SDLConfiguration.ResolvedServerEndpoint
|
||||||
private let port: UInt16
|
private let port: UInt16
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user