punchnet-macos/Tun/Punchnet/Policy/PolicyRuntime.swift
2026-05-21 12:03:17 +08:00

29 lines
857 B
Swift

//
// PolicyRuntime.swift
// Tun
//
// Created by Codex on 2026/5/21.
//
import Foundation
struct PolicyRuntime: @unchecked Sendable {
private let policySnapshot: PolicySnapshot
private let flowSessionManager: SDLFlowSessionManager
init(policySnapshot: PolicySnapshot, flowSessionManager: SDLFlowSessionManager) {
self.policySnapshot = policySnapshot
self.flowSessionManager = flowSessionManager
}
func allowsInbound(srcIdentityID: UInt32, ipPacket: IPPacket) -> Bool {
if let reverseFlowSession = ipPacket.flowSession()?.reverse(),
self.flowSessionManager.hasSession(reverseFlowSession) {
self.flowSessionManager.updateSession(reverseFlowSession)
return true
}
return self.policySnapshot.allows(srcIdentityID: srcIdentityID, ipPacket: ipPacket)
}
}