解决dns的解析问题

This commit is contained in:
anlicheng 2026-03-26 15:07:21 +08:00
parent 224e38aa8b
commit e556212266
4 changed files with 17 additions and 32 deletions

View File

@ -223,7 +223,7 @@ actor SDLContextActor {
self.dnsWorker = nil self.dnsWorker = nil
// dns // 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) let dnsClient = try await SDLDNSClient(dnsServerAddress: dnsSocketAddress, logger: SDLLogger.shared)
try dnsClient.start() try dnsClient.start()
SDLLogger.shared.log("[SDLContext] dnsClient started") SDLLogger.shared.log("[SDLContext] dnsClient started")

View File

@ -41,7 +41,6 @@ public class SDLConfiguration {
// //
let version: Int let version: Int
let serverIp: String
let serverHost: String let serverHost: String
let stunServers: [String] let stunServers: [String]
@ -67,9 +66,8 @@ public class SDLConfiguration {
let hostname: String let hostname: String
let accessToken: String let accessToken: String
let identityId: UInt32 let identityId: UInt32
public init(version: Int, public init(version: Int,
serverIp: String,
serverHost: String, serverHost: String,
stunServers: [String], stunServers: [String],
clientId: String, clientId: String,
@ -80,7 +78,6 @@ public class SDLConfiguration {
identityId: UInt32) { identityId: UInt32) {
self.version = version self.version = version
self.serverIp = serverIp
self.serverHost = serverHost self.serverHost = serverHost
self.stunServers = stunServers self.stunServers = stunServers
self.clientId = clientId self.clientId = clientId
@ -97,9 +94,8 @@ extension SDLConfiguration {
static func parse(options: [String: NSObject]) -> SDLConfiguration? { static func parse(options: [String: NSObject]) -> SDLConfiguration? {
guard let version = options["version"] as? Int, guard let version = options["version"] as? Int,
let serverIp = options["server_ip"] as? String,
let serverHost = options["server_host"] 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 noticePort = options["notice_port"] as? Int,
let accessToken = options["access_token"] as? String, let accessToken = options["access_token"] as? String,
let identityId = options["identity_id"] as? UInt32, let identityId = options["identity_id"] as? UInt32,
@ -113,15 +109,9 @@ extension SDLConfiguration {
return nil return nil
} }
let stunServers: [String] = [
serverIp,
stunAssistIp
]
return SDLConfiguration(version: version, return SDLConfiguration(version: version,
serverIp: serverIp,
serverHost: serverHost, serverHost: serverHost,
stunServers: stunServers, stunServers: [serverHost, stunAssistHost],
clientId: clientId, clientId: clientId,
networkAddress: networkAddress, networkAddress: networkAddress,
hostname: hostname, hostname: hostname,

View File

@ -29,25 +29,22 @@ struct SystemConfig {
return "macOS \(version.majorVersion).\(version.minorVersion)" 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]? { 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, // guard let serverIp = DNSResolver.resolveAddrInfos(serverHost).first,
let stunAssistIp = DNSResolver.resolveAddrInfos(stunAssistHost).first else { // let stunAssistIp = DNSResolver.resolveAddrInfos(stunAssistHost).first else {
return nil // return nil
} // }
NSLog("[SystemConfig] server_ip: \(serverIp), stun_assist_ip: \(stunAssistIp)")
let clientId = getClientId() let clientId = getClientId()
let mac = getMacAddress() let mac = getMacAddress()
let options = [ return [
"version": version as NSObject, "version": version as NSObject,
"client_id": clientId as NSObject, "client_id": clientId as NSObject,
"access_token": accessToken as NSObject, "access_token": accessToken as NSObject,
"identity_id": identityId as NSObject, "identity_id": identityId as NSObject,
"server_ip": serverIp as NSObject,
"server_host": serverHost as NSObject, "server_host": serverHost as NSObject,
"stun_assist_ip": stunAssistIp as NSObject, "stun_assist_host": stunAssistHost as NSObject,
"hostname": hostname as NSObject, "hostname": hostname as NSObject,
"notice_port": noticePort as NSObject, "notice_port": noticePort as NSObject,
"network_address": [ "network_address": [
@ -58,8 +55,6 @@ struct SystemConfig {
"network_domain": networkDomain as NSObject "network_domain": networkDomain as NSObject
] as NSObject ] as NSObject
] ]
return options
} }
public static func getClientId() -> String { public static func getClientId() -> String {

View File

@ -96,7 +96,7 @@ class AppContext {
} }
let context = try await SDLAPIClient.connectNetwork(accesToken: session.accessToken) let context = try await SDLAPIClient.connectNetwork(accesToken: session.accessToken)
if let options = SystemConfig.getOptions( let options = SystemConfig.getOptions(
networkId: UInt32(session.networkId), networkId: UInt32(session.networkId),
networkDomain: session.networkDomain, networkDomain: session.networkDomain,
ip: context.ip, ip: context.ip,
@ -105,11 +105,11 @@ class AppContext {
identityId: context.identityId, identityId: context.identityId,
hostname: context.hostname, hostname: context.hostname,
noticePort: noticePort noticePort: noticePort
) { )
try await self.vpnManager.enableVpn(options: options)
self.networkContext = context try await self.vpnManager.enableVpn(options: options)
self.vpnOptions = options self.networkContext = context
} self.vpnOptions = options
} }
// //