From e55621226630471c0169dfc4e372a3c4b0538073 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 26 Mar 2026 15:07:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3dns=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tun/Punchnet/Actors/SDLContextActor.swift | 2 +- Tun/Punchnet/SDLConfiguration.swift | 16 +++------------- punchnet/Core/SystemConfig.swift | 19 +++++++------------ punchnet/Views/AppContext.swift | 12 ++++++------ 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Tun/Punchnet/Actors/SDLContextActor.swift b/Tun/Punchnet/Actors/SDLContextActor.swift index c9d81b2..ea60283 100644 --- a/Tun/Punchnet/Actors/SDLContextActor.swift +++ b/Tun/Punchnet/Actors/SDLContextActor.swift @@ -223,7 +223,7 @@ actor SDLContextActor { self.dnsWorker = nil // 启动dns服务 - let dnsSocketAddress = try SocketAddress.makeAddressResolvingHost(self.config.serverIp, port: 15353) + let dnsSocketAddress = try SocketAddress.makeAddressResolvingHost(self.config.serverHost, port: 15353) let dnsClient = try await SDLDNSClient(dnsServerAddress: dnsSocketAddress, logger: SDLLogger.shared) try dnsClient.start() SDLLogger.shared.log("[SDLContext] dnsClient started") diff --git a/Tun/Punchnet/SDLConfiguration.swift b/Tun/Punchnet/SDLConfiguration.swift index 2763f0f..ecb7699 100644 --- a/Tun/Punchnet/SDLConfiguration.swift +++ b/Tun/Punchnet/SDLConfiguration.swift @@ -41,7 +41,6 @@ public class SDLConfiguration { // 当前的客户端版本 let version: Int - let serverIp: String let serverHost: String let stunServers: [String] @@ -67,9 +66,8 @@ public class SDLConfiguration { let hostname: String let accessToken: String let identityId: UInt32 - + public init(version: Int, - serverIp: String, serverHost: String, stunServers: [String], clientId: String, @@ -80,7 +78,6 @@ public class SDLConfiguration { identityId: UInt32) { self.version = version - self.serverIp = serverIp self.serverHost = serverHost self.stunServers = stunServers self.clientId = clientId @@ -97,9 +94,8 @@ extension SDLConfiguration { static func parse(options: [String: NSObject]) -> SDLConfiguration? { guard let version = options["version"] as? Int, - let serverIp = options["server_ip"] as? String, let serverHost = options["server_host"] as? String, - let stunAssistIp = options["stun_assist_ip"] as? String, + let stunAssistHost = options["stun_assist_host"] as? String, let noticePort = options["notice_port"] as? Int, let accessToken = options["access_token"] as? String, let identityId = options["identity_id"] as? UInt32, @@ -113,15 +109,9 @@ extension SDLConfiguration { return nil } - let stunServers: [String] = [ - serverIp, - stunAssistIp - ] - return SDLConfiguration(version: version, - serverIp: serverIp, serverHost: serverHost, - stunServers: stunServers, + stunServers: [serverHost, stunAssistHost], clientId: clientId, networkAddress: networkAddress, hostname: hostname, diff --git a/punchnet/Core/SystemConfig.swift b/punchnet/Core/SystemConfig.swift index 1d61403..693f634 100644 --- a/punchnet/Core/SystemConfig.swift +++ b/punchnet/Core/SystemConfig.swift @@ -29,25 +29,22 @@ struct SystemConfig { return "macOS \(version.majorVersion).\(version.minorVersion)" }() - static func getOptions(networkId: UInt32, networkDomain: String, ip: String, maskLen: UInt8, accessToken: String, identityId: UInt32, hostname: String, noticePort: Int) -> [String: NSObject]? { - guard let serverIp = DNSResolver.resolveAddrInfos(serverHost).first, - let stunAssistIp = DNSResolver.resolveAddrInfos(stunAssistHost).first else { - return nil - } - - NSLog("[SystemConfig] server_ip: \(serverIp), stun_assist_ip: \(stunAssistIp)") + static func getOptions(networkId: UInt32, networkDomain: String, ip: String, maskLen: UInt8, accessToken: String, identityId: UInt32, hostname: String, noticePort: Int) -> [String: NSObject] { +// guard let serverIp = DNSResolver.resolveAddrInfos(serverHost).first, +// let stunAssistIp = DNSResolver.resolveAddrInfos(stunAssistHost).first else { +// return nil +// } let clientId = getClientId() let mac = getMacAddress() - let options = [ + return [ "version": version as NSObject, "client_id": clientId as NSObject, "access_token": accessToken as NSObject, "identity_id": identityId as NSObject, - "server_ip": serverIp as NSObject, "server_host": serverHost as NSObject, - "stun_assist_ip": stunAssistIp as NSObject, + "stun_assist_host": stunAssistHost as NSObject, "hostname": hostname as NSObject, "notice_port": noticePort as NSObject, "network_address": [ @@ -58,8 +55,6 @@ struct SystemConfig { "network_domain": networkDomain as NSObject ] as NSObject ] - - return options } public static func getClientId() -> String { diff --git a/punchnet/Views/AppContext.swift b/punchnet/Views/AppContext.swift index 94b9e83..09cb48d 100644 --- a/punchnet/Views/AppContext.swift +++ b/punchnet/Views/AppContext.swift @@ -96,7 +96,7 @@ class AppContext { } let context = try await SDLAPIClient.connectNetwork(accesToken: session.accessToken) - if let options = SystemConfig.getOptions( + let options = SystemConfig.getOptions( networkId: UInt32(session.networkId), networkDomain: session.networkDomain, ip: context.ip, @@ -105,11 +105,11 @@ class AppContext { identityId: context.identityId, hostname: context.hostname, noticePort: noticePort - ) { - try await self.vpnManager.enableVpn(options: options) - self.networkContext = context - self.vpnOptions = options - } + ) + + try await self.vpnManager.enableVpn(options: options) + self.networkContext = context + self.vpnOptions = options } // 断开网络连接