// // SDLPuncherActor.swift // Tun // // Created by 安礼成 on 2026/1/7. // import Foundation import NIOCore actor PolicyRequesterActor { nonisolated private let cooldown: Duration = .seconds(5) // identityId private var coolingDown: Set = [] // 处理各个请求的版本问题, map[identityId] = version private var versions: [UInt32: UInt32] = [:] // 处理holer nonisolated private let querySocketAddress: SocketAddress init(querySocketAddress: SocketAddress) { self.querySocketAddress = querySocketAddress } // 提交权限请求 func submitPolicyRequest(using quicClient: SDLQUICClient?, request: inout SDLPolicyRequest) { let identityId = request.srcIdentityID guard let quicClient, !coolingDown.contains(identityId) else { return } // 触发一次打洞 coolingDown.insert(identityId) let version = self.versions[identityId, default: 1] request.version = version // 更新请求的版本问题 self.versions[identityId] = version + 1 // 发送请求 if let queryData = try? request.serializedData() { quicClient.send(type: .policyRequest, data: queryData) } Task { // 启动冷却期 try? await Task.sleep(for: .seconds(5)) self.endCooldown(for: identityId) } } private func endCooldown(for key: UInt32) { self.coolingDown.remove(key) } }