fix FlowSession
This commit is contained in:
parent
3cfe139512
commit
5cb8e4646c
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user