From d70549d85de7dbaa820a048e7a02358932c1506c Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 16 Apr 2026 15:28:50 +0800 Subject: [PATCH] fix --- Tun/Punchnet/Actors/SDLContextActor.swift | 2 + Tun/Punchnet/Protobuf/SDLMessage.pb.swift | 134 +++++++++++++++++++++- 2 files changed, 135 insertions(+), 1 deletion(-) diff --git a/Tun/Punchnet/Actors/SDLContextActor.swift b/Tun/Punchnet/Actors/SDLContextActor.swift index dea948c..777bffa 100644 --- a/Tun/Punchnet/Actors/SDLContextActor.swift +++ b/Tun/Punchnet/Actors/SDLContextActor.swift @@ -463,6 +463,8 @@ actor SDLContextActor { stunRequest.mac = self.config.networkAddress.mac stunRequest.natType = UInt32(self.natType.rawValue) stunRequest.sessionToken = sessionToken + + if let v6Info = self.makeCurrentV6Info() { stunRequest.v6Info = v6Info } diff --git a/Tun/Punchnet/Protobuf/SDLMessage.pb.swift b/Tun/Punchnet/Protobuf/SDLMessage.pb.swift index 51edb8f..f18ceb9 100644 --- a/Tun/Punchnet/Protobuf/SDLMessage.pb.swift +++ b/Tun/Punchnet/Protobuf/SDLMessage.pb.swift @@ -51,7 +51,41 @@ struct SDLV6Info: @unchecked Sendable { init() {} } -struct SDLWelcome: Sendable { +/// ipv6 assist相关 +struct SDLV6AssistProbe: @unchecked Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + var assistToken: Data = Data() + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} +} + +struct SDLV6AssistProbeReply: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + var v6Info: SDLV6Info { + get {return _v6Info ?? SDLV6Info()} + set {_v6Info = newValue} + } + /// Returns true if `v6Info` has been explicitly set. + var hasV6Info: Bool {return self._v6Info != nil} + /// Clears the value of `v6Info`. Subsequent reads from it will return its default value. + mutating func clearV6Info() {self._v6Info = nil} + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} + + fileprivate var _v6Info: SDLV6Info? = nil +} + +struct SDLWelcome: @unchecked Sendable { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. @@ -67,9 +101,23 @@ struct SDLWelcome: Sendable { /// 心跳包的间隔 var heartbeatSec: UInt32 = 0 + /// ipv6辅助器地址 + var ipv6Assist: SDLV6Info { + get {return _ipv6Assist ?? SDLV6Info()} + set {_ipv6Assist = newValue} + } + /// Returns true if `ipv6Assist` has been explicitly set. + var hasIpv6Assist: Bool {return self._ipv6Assist != nil} + /// Clears the value of `ipv6Assist`. Subsequent reads from it will return its default value. + mutating func clearIpv6Assist() {self._ipv6Assist = nil} + + var assistToken: Data = Data() + var unknownFields = SwiftProtobuf.UnknownStorage() init() {} + + fileprivate var _ipv6Assist: SDLV6Info? = nil } /// 这里修改成了扁平的结构, 否则有些字段不好找放的位置 @@ -648,6 +696,74 @@ extension SDLV6Info: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation } } +extension SDLV6AssistProbe: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = "SDLV6AssistProbe" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "assist_token"), + ] + + mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.assistToken) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if !self.assistToken.isEmpty { + try visitor.visitSingularBytesField(value: self.assistToken, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: SDLV6AssistProbe, rhs: SDLV6AssistProbe) -> Bool { + if lhs.assistToken != rhs.assistToken {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension SDLV6AssistProbeReply: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = "SDLV6AssistProbeReply" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "v6_info"), + ] + + mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._v6Info) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._v6Info { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: SDLV6AssistProbeReply, rhs: SDLV6AssistProbeReply) -> Bool { + if lhs._v6Info != rhs._v6Info {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + extension SDLWelcome: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "SDLWelcome" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ @@ -655,6 +771,8 @@ extension SDLWelcome: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 2: .standard(proto: "max_bidi_streams"), 3: .standard(proto: "max_packet_size"), 4: .standard(proto: "heartbeat_sec"), + 5: .standard(proto: "ipv6_assist"), + 6: .standard(proto: "assist_token"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -667,12 +785,18 @@ extension SDLWelcome: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio case 2: try { try decoder.decodeSingularUInt32Field(value: &self.maxBidiStreams) }() case 3: try { try decoder.decodeSingularUInt32Field(value: &self.maxPacketSize) }() case 4: try { try decoder.decodeSingularUInt32Field(value: &self.heartbeatSec) }() + case 5: try { try decoder.decodeSingularMessageField(value: &self._ipv6Assist) }() + case 6: try { try decoder.decodeSingularBytesField(value: &self.assistToken) }() default: break } } } func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 if self.version != 0 { try visitor.visitSingularUInt32Field(value: self.version, fieldNumber: 1) } @@ -685,6 +809,12 @@ extension SDLWelcome: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if self.heartbeatSec != 0 { try visitor.visitSingularUInt32Field(value: self.heartbeatSec, fieldNumber: 4) } + try { if let v = self._ipv6Assist { + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + } }() + if !self.assistToken.isEmpty { + try visitor.visitSingularBytesField(value: self.assistToken, fieldNumber: 6) + } try unknownFields.traverse(visitor: &visitor) } @@ -693,6 +823,8 @@ extension SDLWelcome: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if lhs.maxBidiStreams != rhs.maxBidiStreams {return false} if lhs.maxPacketSize != rhs.maxPacketSize {return false} if lhs.heartbeatSec != rhs.heartbeatSec {return false} + if lhs._ipv6Assist != rhs._ipv6Assist {return false} + if lhs.assistToken != rhs.assistToken {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true }