From 1f629a58a0dd46a8fe36ce6732a902b95edde6b4 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 1 Aug 2025 12:03:26 +0800 Subject: [PATCH] fix --- Sources/Punchnet/SDLContext.swift | 12 ++++++------ Sources/Punchnet/SDLNatProber.swift | 4 ++-- ...DLSuperClientActor.swift => SDLSuperClient.swift} | 2 +- .../{SDLUDPHoleActor.swift => SDLUDPHole.swift} | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) rename Sources/Punchnet/{SDLSuperClientActor.swift => SDLSuperClient.swift} (99%) rename Sources/Punchnet/{SDLUDPHoleActor.swift => SDLUDPHole.swift} (99%) diff --git a/Sources/Punchnet/SDLContext.swift b/Sources/Punchnet/SDLContext.swift index 42b6db6..ddab91e 100644 --- a/Sources/Punchnet/SDLContext.swift +++ b/Sources/Punchnet/SDLContext.swift @@ -47,8 +47,8 @@ public class SDLContext: @unchecked Sendable { let rsaCipher: RSACipher // 依赖的变量 - var udpHoleActor: SDLUDPHoleActor? - var superClientActor: SDLSuperClientActor? + var udpHoleActor: SDLUDPHole? + var superClientActor: SDLSuperClient? // 数据包读取任务 private var readTask: Task<(), Never>? @@ -93,8 +93,8 @@ public class SDLContext: @unchecked Sendable { } public func start() async throws { - self.udpHoleActor = try await SDLUDPHoleActor() - self.superClientActor = try await SDLSuperClientActor(host: self.config.superHost, port: self.config.superPort) + self.udpHoleActor = try await SDLUDPHole() + self.superClientActor = try await SDLSuperClient(host: self.config.superHost, port: self.config.superPort) self.noticeClient = try await SDLNoticeClient() try await withThrowingTaskGroup(of: Void.self) { group in @@ -160,7 +160,7 @@ public class SDLContext: @unchecked Sendable { self.readTask?.cancel() } - private func handleSuperEvent(event: SDLSuperClientActor.SuperEvent) async throws { + private func handleSuperEvent(event: SDLSuperClient.SuperEvent) async throws { switch event { case .ready: NSLog("[SDLContext] get registerSuper, mac address: \(Self.formatMacAddress(mac: self.devAddr.mac))") @@ -273,7 +273,7 @@ public class SDLContext: @unchecked Sendable { // try await self.udpHole?.start() } - private func handleUDPEvent(event: SDLUDPHoleActor.UDPEvent) async throws { + private func handleUDPEvent(event: SDLUDPHole.UDPEvent) async throws { switch event { case .ready: // 获取当前网络的类型 diff --git a/Sources/Punchnet/SDLNatProber.swift b/Sources/Punchnet/SDLNatProber.swift index 18710d7..c27eb55 100644 --- a/Sources/Punchnet/SDLNatProber.swift +++ b/Sources/Punchnet/SDLNatProber.swift @@ -22,7 +22,7 @@ struct SDLNatProber { } // 获取当前所处的网络的nat类型 - static func getNatType(udpHole: SDLUDPHoleActor?, config: SDLConfiguration) async -> NatType { + static func getNatType(udpHole: SDLUDPHole?, config: SDLConfiguration) async -> NatType { guard let udpHole else { return .blocked } @@ -67,7 +67,7 @@ struct SDLNatProber { } } - private static func getNatAddress(_ udpHole: SDLUDPHoleActor, remoteAddress: SocketAddress, attr: SDLProbeAttr) async -> SocketAddress? { + private static func getNatAddress(_ udpHole: SDLUDPHole, remoteAddress: SocketAddress, attr: SDLProbeAttr) async -> SocketAddress? { let stunProbeReply = try? await udpHole.stunProbe(remoteAddress: remoteAddress, attr: attr, timeout: 5) return stunProbeReply?.socketAddress() diff --git a/Sources/Punchnet/SDLSuperClientActor.swift b/Sources/Punchnet/SDLSuperClient.swift similarity index 99% rename from Sources/Punchnet/SDLSuperClientActor.swift rename to Sources/Punchnet/SDLSuperClient.swift index 0995cfa..5a0999b 100644 --- a/Sources/Punchnet/SDLSuperClientActor.swift +++ b/Sources/Punchnet/SDLSuperClient.swift @@ -10,7 +10,7 @@ import NIOCore import NIOPosix // --MARK: 和SuperNode的客户端 -actor SDLSuperClientActor { +actor SDLSuperClient { private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) private let asyncChannel: NIOAsyncChannel private let (writeStream, writeContinuation) = AsyncStream.makeStream(of: TcpMessage.self, bufferingPolicy: .unbounded) diff --git a/Sources/Punchnet/SDLUDPHoleActor.swift b/Sources/Punchnet/SDLUDPHole.swift similarity index 99% rename from Sources/Punchnet/SDLUDPHoleActor.swift rename to Sources/Punchnet/SDLUDPHole.swift index c4ec640..a6db05b 100644 --- a/Sources/Punchnet/SDLUDPHoleActor.swift +++ b/Sources/Punchnet/SDLUDPHole.swift @@ -16,7 +16,7 @@ struct UDPMessage { } // 处理和sn-server服务器之间的通讯 -actor SDLUDPHoleActor { +actor SDLUDPHole { private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) private let asyncChannel: NIOAsyncChannel, AddressedEnvelope> private let (writeStream, continuation) = AsyncStream.makeStream(of: UDPMessage.self, bufferingPolicy: .unbounded)