Sync Zonghengjia iPhone and iPad 1.0.4 source candidate
This commit is contained in:
+27
-20
@@ -4,7 +4,7 @@ import UIKit
|
||||
actor PlatformAPI {
|
||||
static let shared = PlatformAPI()
|
||||
|
||||
private let baseURL = URL(string: "https://vpn.example.invalid/")!
|
||||
private let baseURL = URL(string: "https://vpn.ucvl.cn/")!
|
||||
private let session: URLSession
|
||||
private let decoder = JSONDecoder()
|
||||
private let encoder = JSONEncoder()
|
||||
@@ -16,7 +16,7 @@ actor PlatformAPI {
|
||||
configuration.waitsForConnectivity = true
|
||||
configuration.httpAdditionalHeaders = [
|
||||
"Accept": "application/json",
|
||||
"User-Agent": "UCVL-Zonghengjia/1.0.3 iOS",
|
||||
"User-Agent": "UCVL-Zonghengjia/1.0.4 iOS",
|
||||
]
|
||||
session = URLSession(configuration: configuration)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ actor PlatformAPI {
|
||||
"password": password,
|
||||
"device_id": SecureStore.deviceID(),
|
||||
"device_name": await MainActor.run { UIDevice.current.name },
|
||||
"app_version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.3",
|
||||
"app_version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.4",
|
||||
"platform": "ios",
|
||||
]
|
||||
return try await send(
|
||||
@@ -66,10 +66,6 @@ actor PlatformAPI {
|
||||
}
|
||||
|
||||
func verifyProxyEgress() async throws {
|
||||
let endpoints = [
|
||||
URL(string: "https://api.openai.com/v1/models")!,
|
||||
URL(string: "https://chatgpt.com/api/auth/session")!,
|
||||
]
|
||||
let configuration = URLSessionConfiguration.ephemeral
|
||||
configuration.timeoutIntervalForRequest = 12
|
||||
configuration.timeoutIntervalForResource = 15
|
||||
@@ -78,27 +74,38 @@ actor PlatformAPI {
|
||||
let verifier = URLSession(configuration: configuration)
|
||||
defer { verifier.invalidateAndCancel() }
|
||||
|
||||
for endpoint in endpoints {
|
||||
var request = URLRequest(url: endpoint)
|
||||
request.httpMethod = "GET"
|
||||
request.setValue("no-cache", forHTTPHeaderField: "Cache-Control")
|
||||
do {
|
||||
let (_, response) = try await verifier.data(for: request)
|
||||
if let http = response as? HTTPURLResponse, (200..<500).contains(http.statusCode) {
|
||||
return
|
||||
let reachable = await withTaskGroup(of: Bool.self) { probes in
|
||||
for endpoint in TunnelConfigurationBuilder.egressProbeURLs {
|
||||
probes.addTask {
|
||||
var request = URLRequest(url: endpoint)
|
||||
request.setValue("no-cache", forHTTPHeaderField: "Cache-Control")
|
||||
do {
|
||||
let (_, response) = try await verifier.data(for: request)
|
||||
guard let response = response as? HTTPURLResponse else { return false }
|
||||
return response.url?.scheme == "https" && response.url?.host == endpoint.host
|
||||
&& (100...599).contains(response.statusCode)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
for await success in probes where success {
|
||||
probes.cancelAll()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
try Task.checkCancellation()
|
||||
guard reachable else {
|
||||
throw UCVLError.connection("当前入口未通过代理 HTTPS 出口验证。")
|
||||
}
|
||||
throw UCVLError.connection("当前节点未通过 OpenAI/ChatGPT 出口验证,正在切换其它节点。")
|
||||
}
|
||||
|
||||
func resolvePublicIPv4(host: String) async throws -> String {
|
||||
if NetworkAddress.isPublicIPv4(host) { return host }
|
||||
// 001/002 是后台节点名称。NPM TCP Stream 依靠 11081/11082 等端口
|
||||
// 分流,不要求每个节点子域名都单独发布 A 记录;解析不到时使用统一入口。
|
||||
let candidateHosts = host == "vpn.example.invalid" ? [host] : [host, "vpn.example.invalid"]
|
||||
let candidateHosts = host == "vpn.ucvl.cn" ? [host] : [host, "vpn.ucvl.cn"]
|
||||
let resolvers = [
|
||||
"https://dns.alidns.com/resolve",
|
||||
"https://doh.pub/resolve",
|
||||
@@ -131,7 +138,7 @@ actor PlatformAPI {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw UCVLError.connection("无法取得 NPM 入口 vpn.example.invalid 的真实公网 IPv4;已拒绝 Fake-IP/内网地址。")
|
||||
throw UCVLError.connection("无法取得 NPM 入口 vpn.ucvl.cn 的真实公网 IPv4;已拒绝 Fake-IP/内网地址。")
|
||||
}
|
||||
|
||||
func logout(token: String) async {
|
||||
|
||||
Reference in New Issue
Block a user