解决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
// 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")

View File

@ -41,7 +41,6 @@ public class SDLConfiguration {
//
let version: Int
let serverIp: String
let serverHost: String
let stunServers: [String]
@ -69,7 +68,6 @@ public class SDLConfiguration {
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,

View File

@ -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 {

View File

@ -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,12 +105,12 @@ class AppContext {
identityId: context.identityId,
hostname: context.hostname,
noticePort: noticePort
) {
)
try await self.vpnManager.enableVpn(options: options)
self.networkContext = context
self.vpnOptions = options
}
}
//
func disconnectNetwork() async throws {