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