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
// 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

View File

@ -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
}

View File

@ -13,7 +13,7 @@ actor PolicyService {
nonisolated private let snapshotPublisher: SnapshotPublisher<PolicyRuleSnapshot>
// 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()
}