fix address
This commit is contained in:
parent
95e20fc6fe
commit
3cfe139512
@ -42,16 +42,16 @@ final class DNSCloudClient {
|
|||||||
self.packetContinuation = packetPair.continuation
|
self.packetContinuation = packetPair.continuation
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func makeEndpointHost(address: String) -> NWEndpoint.Host {
|
private static func makeEndpointHost(address ip: String) -> NWEndpoint.Host {
|
||||||
if let ipv4Address = IPv4Address(address) {
|
if let ipv4Address = IPv4Address(ip) {
|
||||||
return .ipv4(ipv4Address)
|
return .ipv4(ipv4Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ipv6Address = IPv6Address(address) {
|
if let ipv6Address = IPv6Address(ip) {
|
||||||
return .ipv6(ipv6Address)
|
return .ipv6(ipv6Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
return .name(address, nil)
|
preconditionFailure("invalid DNS cloud server IP: \(ip)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ actor DNSLocalClient {
|
|||||||
private var nextTransactionID: UInt16 = 1
|
private var nextTransactionID: UInt16 = 1
|
||||||
|
|
||||||
init(host: String) {
|
init(host: String) {
|
||||||
self.dnsServerEndpoint = .hostPort(host: NWEndpoint.Host(host), port: 53)
|
self.dnsServerEndpoint = .hostPort(host: Self.makeEndpointHost(ip: host), port: 53)
|
||||||
|
|
||||||
let (stream, continuation) = AsyncThrowingStream.makeStream(of: Data.self, bufferingPolicy: .bufferingNewest(256))
|
let (stream, continuation) = AsyncThrowingStream.makeStream(of: Data.self, bufferingPolicy: .bufferingNewest(256))
|
||||||
self.packetFlow = stream
|
self.packetFlow = stream
|
||||||
@ -54,6 +54,18 @@ actor DNSLocalClient {
|
|||||||
SDLLogger.log("[DNSLocalClient] packetFlow terminated: \(termination)")
|
SDLLogger.log("[DNSLocalClient] packetFlow terminated: \(termination)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func makeEndpointHost(ip: String) -> NWEndpoint.Host {
|
||||||
|
if let ipv4Address = IPv4Address(ip) {
|
||||||
|
return .ipv4(ipv4Address)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let ipv6Address = IPv6Address(ip) {
|
||||||
|
return .ipv6(ipv6Address)
|
||||||
|
}
|
||||||
|
|
||||||
|
preconditionFailure("invalid public DNS server IP: \(ip)")
|
||||||
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
guard self.state == .idle else {
|
guard self.state == .idle else {
|
||||||
|
|||||||
@ -33,10 +33,12 @@ actor SDLIPV6AssistClient {
|
|||||||
private var pendingRequests: [UInt32: PendingRequest] = [:]
|
private var pendingRequests: [UInt32: PendingRequest] = [:]
|
||||||
|
|
||||||
init?(assistServerInfo: SDLV6Info) {
|
init?(assistServerInfo: SDLV6Info) {
|
||||||
guard assistServerInfo.port <= UInt32(UInt16.max), let host = SDLUtil.ipv6DataToString(assistServerInfo.v6) else {
|
guard assistServerInfo.port <= UInt32(UInt16.max),
|
||||||
|
let host = SDLUtil.ipv6DataToString(assistServerInfo.v6),
|
||||||
|
let address = IPv6Address(host) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
self.assistServerAddress = .hostPort(host: NWEndpoint.Host(host), port: NWEndpoint.Port(integerLiteral: UInt16(assistServerInfo.port)))
|
self.assistServerAddress = .hostPort(host: .ipv6(address), port: NWEndpoint.Port(integerLiteral: UInt16(assistServerInfo.port)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SystemConfiguration
|
import SystemConfiguration
|
||||||
import Network
|
|
||||||
import Darwin
|
import Darwin
|
||||||
|
|
||||||
struct SDLUtil {
|
struct SDLUtil {
|
||||||
@ -111,31 +110,4 @@ struct SDLUtil {
|
|||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
// 域名解析
|
|
||||||
static func resolveHostname(host: String) async -> String? {
|
|
||||||
let endpoint = NWEndpoint.hostPort(host: NWEndpoint.Host(host), port: 53)
|
|
||||||
let parameters = NWParameters.udp
|
|
||||||
// 即使还没正式开始,也加上这个,确保不会被残留的旧 utun 路由卡死
|
|
||||||
parameters.prohibitedInterfaceTypes = [.other]
|
|
||||||
|
|
||||||
let connection = NWConnection(to: endpoint, using: parameters)
|
|
||||||
|
|
||||||
return await withCheckedContinuation { continuation in
|
|
||||||
connection.stateUpdateHandler = { state in
|
|
||||||
if case .ready = state {
|
|
||||||
if let path = connection.currentPath,
|
|
||||||
case .hostPort(let resolvedHost, _) = path.remoteEndpoint {
|
|
||||||
let ip = String(describing: resolvedHost)
|
|
||||||
continuation.resume(returning: ip)
|
|
||||||
connection.cancel()
|
|
||||||
}
|
|
||||||
} else if case .failed = state {
|
|
||||||
continuation.resume(returning: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connection.start(queue: .global())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,16 +97,16 @@ actor SDLSuperClient {
|
|||||||
self.connection = connection
|
self.connection = connection
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func makeEndpointHost(address: String) -> NWEndpoint.Host {
|
private static func makeEndpointHost(address ip: String) -> NWEndpoint.Host {
|
||||||
if let ipv4Address = IPv4Address(address) {
|
if let ipv4Address = IPv4Address(ip) {
|
||||||
return .ipv4(ipv4Address)
|
return .ipv4(ipv4Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ipv6Address = IPv6Address(address) {
|
if let ipv6Address = IPv6Address(ip) {
|
||||||
return .ipv6(ipv6Address)
|
return .ipv6(ipv6Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
return .name(address, nil)
|
preconditionFailure("invalid super server IP: \(ip)")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleConnectionState(state: NWConnection.State) {
|
private func handleConnectionState(state: NWConnection.State) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user