From 5cb8e4646c4b12771e79496cd2b73f77a86c926c Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 21 May 2026 14:01:22 +0800 Subject: [PATCH] fix FlowSession --- ...FlowSessionManager.swift => FlowSessionTable.swift} | 6 +++--- Tun/Punchnet/Policy/PolicyRuntime.swift | 10 +++++----- Tun/Punchnet/Policy/PolicyService.swift | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) rename Tun/Punchnet/Policy/{SDLFlowSessionManager.swift => FlowSessionTable.swift} (96%) diff --git a/Tun/Punchnet/Policy/SDLFlowSessionManager.swift b/Tun/Punchnet/Policy/FlowSessionTable.swift similarity index 96% rename from Tun/Punchnet/Policy/SDLFlowSessionManager.swift rename to Tun/Punchnet/Policy/FlowSessionTable.swift index 113b2aa..f02580d 100644 --- a/Tun/Punchnet/Policy/SDLFlowSessionManager.swift +++ b/Tun/Punchnet/Policy/FlowSessionTable.swift @@ -1,5 +1,5 @@ // -// FiveTuple.swift +// FlowSessionTable.swift // punchnet // tcp/udp Flow流管理 // Created by 安礼成 on 2026/3/10. @@ -42,8 +42,8 @@ struct FlowSession: Hashable { } -// MARK: - 会话管理器 -final class SDLFlowSessionManager: @unchecked Sendable { +// MARK: - 会话表 +final class FlowSessionTable: @unchecked Sendable { private var sessions: [FlowSession: TimeInterval] = [:] private let lock = NSLock() private let sessionTimeout: TimeInterval diff --git a/Tun/Punchnet/Policy/PolicyRuntime.swift b/Tun/Punchnet/Policy/PolicyRuntime.swift index f7a5322..d6c1055 100644 --- a/Tun/Punchnet/Policy/PolicyRuntime.swift +++ b/Tun/Punchnet/Policy/PolicyRuntime.swift @@ -9,17 +9,17 @@ import Foundation struct PolicyRuntime: @unchecked Sendable { private let policyRuleSnapshot: PolicyRuleSnapshot - private let flowSessionManager: SDLFlowSessionManager + private let flowSessionTable: FlowSessionTable - init(policyRuleSnapshot: PolicyRuleSnapshot, flowSessionManager: SDLFlowSessionManager) { + init(policyRuleSnapshot: PolicyRuleSnapshot, flowSessionTable: FlowSessionTable) { self.policyRuleSnapshot = policyRuleSnapshot - self.flowSessionManager = flowSessionManager + self.flowSessionTable = flowSessionTable } func allowsInbound(srcIdentityID: UInt32, ipPacket: IPPacket) -> Bool { if let reverseFlowSession = ipPacket.flowSession()?.reverse(), - self.flowSessionManager.hasSession(reverseFlowSession) { - self.flowSessionManager.updateSession(reverseFlowSession) + self.flowSessionTable.hasSession(reverseFlowSession) { + self.flowSessionTable.updateSession(reverseFlowSession) return true } diff --git a/Tun/Punchnet/Policy/PolicyService.swift b/Tun/Punchnet/Policy/PolicyService.swift index e82fe22..2a72c72 100644 --- a/Tun/Punchnet/Policy/PolicyService.swift +++ b/Tun/Punchnet/Policy/PolicyService.swift @@ -13,7 +13,7 @@ actor PolicyService { nonisolated private let snapshotPublisher: SnapshotPublisher // Flow流会话管理, 过期时间为: 180秒 - nonisolated private let flowSessionManager = SDLFlowSessionManager(sessionTimeout: 180) + nonisolated private let flowSessionTable = FlowSessionTable(sessionTimeout: 180) // 当前节点的identityId值 let identityId: UInt32 @@ -27,7 +27,7 @@ actor PolicyService { } nonisolated func policyRuntime() -> PolicyRuntime { - return PolicyRuntime(policyRuleSnapshot: self.snapshotPublisher.current(), flowSessionManager: self.flowSessionManager) + return PolicyRuntime(policyRuleSnapshot: self.snapshotPublisher.current(), flowSessionTable: self.flowSessionTable) } nonisolated func recordOutboundFlow(ipPacket: IPPacket) { @@ -35,7 +35,7 @@ actor PolicyService { return } - self.flowSessionManager.updateSession(flowSession) + self.flowSessionTable.updateSession(flowSession) } func makePolicyRequest(srcIdentityID: UInt32) async -> Data? { @@ -59,7 +59,7 @@ actor PolicyService { } func clear() async { - self.flowSessionManager.clear() + self.flowSessionTable.clear() await self.policyRuleStore.clear() }