From 45c701e90f8eef119f61759b733a046efc028752 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Tue, 15 Jul 2025 00:59:11 +0800 Subject: [PATCH] fix channel --- Sources/sdlan/LayerPacket.swift | 1 - Sources/sdlan/NetworkInterface.swift | 2 +- Sources/sdlan/SDLContext.swift | 3 ++- Sources/sdlan/SDLNatProber.swift | 1 + Sources/sdlan/SDLNoticeClient.swift | 6 ++++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/sdlan/LayerPacket.swift b/Sources/sdlan/LayerPacket.swift index 3237acd..5657f52 100644 --- a/Sources/sdlan/LayerPacket.swift +++ b/Sources/sdlan/LayerPacket.swift @@ -19,7 +19,6 @@ struct LayerPacket { enum LayerPacketError: Error { case invalidLength - case crcError case invaldPacketType } diff --git a/Sources/sdlan/NetworkInterface.swift b/Sources/sdlan/NetworkInterface.swift index e54ff91..99c3910 100644 --- a/Sources/sdlan/NetworkInterface.swift +++ b/Sources/sdlan/NetworkInterface.swift @@ -44,7 +44,7 @@ struct NetworkInterfaceManager { if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count), nil, socklen_t(0), NI_NUMERICHOST) == 0) { let address = String(cString: hostname) - + let name = ptr!.pointee.ifa_name! let ifname = String(cString: name) diff --git a/Sources/sdlan/SDLContext.swift b/Sources/sdlan/SDLContext.swift index bbd4390..d89dbe0 100644 --- a/Sources/sdlan/SDLContext.swift +++ b/Sources/sdlan/SDLContext.swift @@ -457,7 +457,8 @@ class SDLContext: @unchecked Sendable { self.udpHole?.sendPacket(context: self, session: session, data: encodedPacket) await self.flowTracer.inc(num: data.count, type: .p2p) - } else { + } + else { // 通过super_node进行转发 self.udpHole?.forwardPacket(context: self, dst_mac: dstMac, data: encodedPacket) // 流量统计 diff --git a/Sources/sdlan/SDLNatProber.swift b/Sources/sdlan/SDLNatProber.swift index 37675e2..5201b89 100644 --- a/Sources/sdlan/SDLNatProber.swift +++ b/Sources/sdlan/SDLNatProber.swift @@ -10,6 +10,7 @@ import NIOCore // 网络类型探测器 struct SDLNatProber { + // 定义nat类型 enum NatType: UInt8, Encodable { case blocked = 0 diff --git a/Sources/sdlan/SDLNoticeClient.swift b/Sources/sdlan/SDLNoticeClient.swift index 77b29f6..6073670 100644 --- a/Sources/sdlan/SDLNoticeClient.swift +++ b/Sources/sdlan/SDLNoticeClient.swift @@ -77,8 +77,10 @@ class SDLNoticeClient: ChannelInboundHandler, @unchecked Sendable { } let remoteAddress = self.remoteAddress - context.eventLoop.execute { - let buffer = context.channel.allocator.buffer(bytes: data) + let allocator = context.channel.allocator + + context.eventLoop.execute { [allocator] in + let buffer = allocator.buffer(bytes: data) let envelope = AddressedEnvelope(remoteAddress: remoteAddress, data: buffer) context.writeAndFlush(self.wrapOutboundOut(envelope), promise: nil) }