diff --git a/Tun/Punchnet/Context/SDLContextActor.swift b/Tun/Punchnet/Context/SDLContextActor.swift index 295bcce..f4963a5 100644 --- a/Tun/Punchnet/Context/SDLContextActor.swift +++ b/Tun/Punchnet/Context/SDLContextActor.swift @@ -261,7 +261,7 @@ extension SDLContextActor { await self.handleEvent(event: event) case .policyReponse(let policyResponse): // 处理权限的请求问题 - await self.policyService.identifyStore.applyPolicyResponse(policyResponse) + await self.policyService.applyPolicyResponse(policyResponse) case .arpResponse(let arpResponse): SDLLogger.log("[SDLContext] get arp response: \(arpResponse)") await self.arpServer.handleArpResponse(arpResponse: arpResponse) diff --git a/Tun/Punchnet/Context/SDLTunPacketRouter.swift b/Tun/Punchnet/Context/SDLTunPacketRouter.swift index 4d555ae..9904241 100644 --- a/Tun/Punchnet/Context/SDLTunPacketRouter.swift +++ b/Tun/Punchnet/Context/SDLTunPacketRouter.swift @@ -101,10 +101,8 @@ extension SDLTunPacketRouter.RouteDecision { switch self { case .forwardToNextHop(_, _, _, let kind): switch kind { - case .sameNetwork, .exitNode: + case .sameNetwork, .exitNode, .dnsExitNode: return true - case .dnsExitNode: - return false } default: return false diff --git a/Tun/Punchnet/Policy/IdentityStore.swift b/Tun/Punchnet/Policy/IdentityStore.swift index a088198..170997a 100644 --- a/Tun/Punchnet/Policy/IdentityStore.swift +++ b/Tun/Punchnet/Policy/IdentityStore.swift @@ -80,6 +80,13 @@ actor IdentityStore { let snapshot = compileSnapshot() publisher.publish(snapshot) } + + func clear() { + self.coolingDown.removeAll() + self.versions.removeAll() + self.identityMap.removeAll() + self.publisher.publish(IdentitySnapshot.empty()) + } private func compileSnapshot() -> IdentitySnapshot { return IdentitySnapshot(identityMap: identityMap) diff --git a/Tun/Punchnet/Policy/PolicyService.swift b/Tun/Punchnet/Policy/PolicyService.swift index d6dc9dd..d5742dd 100644 --- a/Tun/Punchnet/Policy/PolicyService.swift +++ b/Tun/Punchnet/Policy/PolicyService.swift @@ -68,9 +68,19 @@ actor PolicyService { await superService.send(type: .policyRequest, data: request) } } + + func applyPolicyResponse(_ policyResponse: SDLPolicyResponse) async { + guard policyResponse.dstIdentityID == self.identityId else { + SDLLogger.log("[PolicyService] ignore policy response, dstIdentityID mismatch: \(policyResponse.dstIdentityID), expected: \(self.identityId)", for: .debug) + return + } + + await self.identifyStore.applyPolicyResponse(policyResponse) + } - func clear() { + func clear() async { self.flowSessionManager.clear() + await self.identifyStore.clear() } deinit {