fix FlowSession

This commit is contained in:
anlicheng 2026-05-21 14:01:22 +08:00
parent 3cfe139512
commit 5cb8e4646c
3 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
// //
// FiveTuple.swift // FlowSessionTable.swift
// punchnet // punchnet
// tcp/udp Flow // tcp/udp Flow
// Created by on 2026/3/10. // Created by on 2026/3/10.
@ -42,8 +42,8 @@ struct FlowSession: Hashable {
} }
// MARK: - // MARK: -
final class SDLFlowSessionManager: @unchecked Sendable { final class FlowSessionTable: @unchecked Sendable {
private var sessions: [FlowSession: TimeInterval] = [:] private var sessions: [FlowSession: TimeInterval] = [:]
private let lock = NSLock() private let lock = NSLock()
private let sessionTimeout: TimeInterval private let sessionTimeout: TimeInterval

View File

@ -9,17 +9,17 @@ import Foundation
struct PolicyRuntime: @unchecked Sendable { struct PolicyRuntime: @unchecked Sendable {
private let policyRuleSnapshot: PolicyRuleSnapshot 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.policyRuleSnapshot = policyRuleSnapshot
self.flowSessionManager = flowSessionManager self.flowSessionTable = flowSessionTable
} }
func allowsInbound(srcIdentityID: UInt32, ipPacket: IPPacket) -> Bool { func allowsInbound(srcIdentityID: UInt32, ipPacket: IPPacket) -> Bool {
if let reverseFlowSession = ipPacket.flowSession()?.reverse(), if let reverseFlowSession = ipPacket.flowSession()?.reverse(),
self.flowSessionManager.hasSession(reverseFlowSession) { self.flowSessionTable.hasSession(reverseFlowSession) {
self.flowSessionManager.updateSession(reverseFlowSession) self.flowSessionTable.updateSession(reverseFlowSession)
return true return true
} }

View File

@ -13,7 +13,7 @@ actor PolicyService {
nonisolated private let snapshotPublisher: SnapshotPublisher<PolicyRuleSnapshot> nonisolated private let snapshotPublisher: SnapshotPublisher<PolicyRuleSnapshot>
// Flow : 180 // Flow : 180
nonisolated private let flowSessionManager = SDLFlowSessionManager(sessionTimeout: 180) nonisolated private let flowSessionTable = FlowSessionTable(sessionTimeout: 180)
// identityId // identityId
let identityId: UInt32 let identityId: UInt32
@ -27,7 +27,7 @@ actor PolicyService {
} }
nonisolated func policyRuntime() -> PolicyRuntime { 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) { nonisolated func recordOutboundFlow(ipPacket: IPPacket) {
@ -35,7 +35,7 @@ actor PolicyService {
return return
} }
self.flowSessionManager.updateSession(flowSession) self.flowSessionTable.updateSession(flowSession)
} }
func makePolicyRequest(srcIdentityID: UInt32) async -> Data? { func makePolicyRequest(srcIdentityID: UInt32) async -> Data? {
@ -59,7 +59,7 @@ actor PolicyService {
} }
func clear() async { func clear() async {
self.flowSessionManager.clear() self.flowSessionTable.clear()
await self.policyRuleStore.clear() await self.policyRuleStore.clear()
} }