fix env support
This commit is contained in:
parent
4bf1a7160f
commit
7b156f757e
@ -73,6 +73,8 @@ public class SDLConfiguration {
|
||||
let hostname: String
|
||||
let accessToken: String
|
||||
let identityId: UInt32
|
||||
let env: String
|
||||
|
||||
var acl: ACL
|
||||
|
||||
var exitNode: ExitNode?
|
||||
@ -85,6 +87,7 @@ public class SDLConfiguration {
|
||||
hostname: String,
|
||||
accessToken: String,
|
||||
identityId: UInt32,
|
||||
env: String,
|
||||
acl: ACL,
|
||||
exitNode: ExitNode?) {
|
||||
self.version = version
|
||||
@ -102,8 +105,11 @@ public class SDLConfiguration {
|
||||
self.accessToken = accessToken
|
||||
self.identityId = identityId
|
||||
self.acl = acl
|
||||
self.env = env
|
||||
self.hostname = hostname
|
||||
self.exitNode = exitNode
|
||||
|
||||
setenv("RUNTIME_ENV", env, 1)
|
||||
}
|
||||
|
||||
}
|
||||
@ -132,6 +138,7 @@ extension SDLConfiguration {
|
||||
let identityId = options["identity_id"] as? UInt32,
|
||||
let clientId = options["client_id"] as? String,
|
||||
let hostname = options["hostname"] as? String,
|
||||
let env = options["env"] as? String,
|
||||
let networkAddressDict = options["network_address"] as? [String: NSObject] else {
|
||||
return nil
|
||||
}
|
||||
@ -160,6 +167,7 @@ extension SDLConfiguration {
|
||||
hostname: hostname,
|
||||
accessToken: accessToken,
|
||||
identityId: identityId,
|
||||
env: env,
|
||||
acl: acl,
|
||||
exitNode: exitNode)
|
||||
}
|
||||
|
||||
@ -9,9 +9,9 @@ import os
|
||||
|
||||
public class SDLLogger: @unchecked Sendable {
|
||||
|
||||
public enum Subsystem: String, CaseIterable {
|
||||
case debug = "com.jihe.punchnet.debug"
|
||||
case trace = "com.jihe.punchnet.trace"
|
||||
public enum Subsystem: CaseIterable {
|
||||
case debug
|
||||
case trace
|
||||
}
|
||||
|
||||
private static let debugLoggingEnabled = ProcessInfo.processInfo.environment["SDL_DEBUG_LOG"] != "0"
|
||||
@ -23,7 +23,15 @@ public class SDLLogger: @unchecked Sendable {
|
||||
private let log: Logger
|
||||
|
||||
private init(subsystem: Subsystem) {
|
||||
self.log = Logger(subsystem: subsystem.rawValue, category: "punchnet")
|
||||
let env = ProcessInfo.processInfo.environment["RUNTIME_ENV"] ?? "prod"
|
||||
var label: String
|
||||
switch subsystem {
|
||||
case .debug:
|
||||
label = "com.jihe.punchnet-\(env).debug"
|
||||
case .trace:
|
||||
label = "com.jihe.punchnet-\(env).trace"
|
||||
}
|
||||
self.log = Logger(subsystem: label, category: "punchnet")
|
||||
}
|
||||
|
||||
public func _log(_ message: String) {
|
||||
|
||||
@ -591,10 +591,10 @@
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac.dev;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTest;
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTestDev;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
@ -728,10 +728,10 @@
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac.tun;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac.dev.tun;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTunTest;
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTunTestDev;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
||||
@ -8,6 +8,21 @@
|
||||
import Foundation
|
||||
|
||||
struct SystemConfig {
|
||||
|
||||
struct EnvConfig {
|
||||
let serverHost: String
|
||||
let stunAssistHost: String
|
||||
let tunBundleId: String
|
||||
let localizedDescription: String
|
||||
}
|
||||
|
||||
enum Env: String {
|
||||
case dev = "dev"
|
||||
case prod = "prod"
|
||||
}
|
||||
|
||||
static let env: Env = .dev
|
||||
|
||||
// 版本设置
|
||||
static let version: Int = 1
|
||||
|
||||
@ -18,10 +33,20 @@ struct SystemConfig {
|
||||
// 渠道相关
|
||||
static let channel = "appstore"
|
||||
|
||||
static let serverHost = "test.punchsky.com"
|
||||
|
||||
// stun探测辅助服务器ip
|
||||
static let stunAssistHost = "test.punchsky.com"
|
||||
static let envConfigs: [Env: EnvConfig] = [
|
||||
.dev: EnvConfig(
|
||||
serverHost: "test.punchsky.com",
|
||||
stunAssistHost: "test.punchsky.com",
|
||||
tunBundleId: "com.jihe.punchnetmac.dev.tun",
|
||||
localizedDescription: "punchnetmac-dev"
|
||||
),
|
||||
.prod: EnvConfig(
|
||||
serverHost: "root.punchsky.com",
|
||||
stunAssistHost: "root.punchsky.com",
|
||||
tunBundleId: "com.jihe.punchnetmac.tun",
|
||||
localizedDescription: "punchnetmac"
|
||||
)
|
||||
]
|
||||
|
||||
// 获取系统信息
|
||||
static let systemInfo: String = {
|
||||
@ -29,6 +54,10 @@ struct SystemConfig {
|
||||
return "macOS \(version.majorVersion).\(version.minorVersion)"
|
||||
}()
|
||||
|
||||
static func getCurrentEnvConfig() -> EnvConfig {
|
||||
return envConfigs[Self.env]!
|
||||
}
|
||||
|
||||
static func getOptions(networkId: UInt32,
|
||||
networkDomain: String,
|
||||
ip: String,
|
||||
@ -38,11 +67,8 @@ struct SystemConfig {
|
||||
hostname: String,
|
||||
acl: NetworkContext.ACL,
|
||||
exitNodeIp: String?) -> [String: NSObject] {
|
||||
// guard let serverIp = DNSResolver.resolveAddrInfos(serverHost).first,
|
||||
// let stunAssistIp = DNSResolver.resolveAddrInfos(stunAssistHost).first else {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
|
||||
let envConfig = getCurrentEnvConfig()
|
||||
let clientId = getClientId()
|
||||
let mac = getMacAddress()
|
||||
|
||||
@ -51,9 +77,10 @@ struct SystemConfig {
|
||||
"client_id": clientId as NSObject,
|
||||
"access_token": accessToken as NSObject,
|
||||
"identity_id": identityId as NSObject,
|
||||
"server_host": serverHost as NSObject,
|
||||
"stun_assist_host": stunAssistHost as NSObject,
|
||||
"server_host": envConfig.serverHost as NSObject,
|
||||
"stun_assist_host": envConfig.stunAssistHost as NSObject,
|
||||
"hostname": hostname as NSObject,
|
||||
"env": Self.env.rawValue as NSObject,
|
||||
"acl": [
|
||||
"tcp": acl.tcp as NSObject,
|
||||
"udp": acl.udp as NSObject
|
||||
|
||||
@ -125,15 +125,17 @@ class VPNManager {
|
||||
private func loadAndCreateProviderManager() async throws -> NETunnelProviderManager {
|
||||
let managers = try await NETunnelProviderManager.loadAllFromPreferences()
|
||||
|
||||
let env = SystemConfig.getCurrentEnvConfig()
|
||||
|
||||
let manager = managers.first ?? NETunnelProviderManager()
|
||||
manager.localizedDescription = "punchnetmac"
|
||||
manager.localizedDescription = env.localizedDescription
|
||||
manager.isEnabled = true
|
||||
|
||||
// 设置相关参数,在PacketTunnel中可以用
|
||||
let protocolConfiguration = NETunnelProviderProtocol()
|
||||
protocolConfiguration.serverAddress = "punchnetmac"
|
||||
protocolConfiguration.serverAddress = env.localizedDescription
|
||||
protocolConfiguration.providerConfiguration = [String:AnyObject]()
|
||||
protocolConfiguration.providerBundleIdentifier = "com.jihe.punchnetmac.tun"
|
||||
protocolConfiguration.providerBundleIdentifier = env.tunBundleId
|
||||
manager.protocolConfiguration = protocolConfiguration
|
||||
manager.isOnDemandEnabled = false
|
||||
|
||||
|
||||
@ -21,7 +21,9 @@ struct SDLAPIError: Error, Decodable {
|
||||
struct SDLAPIClient {
|
||||
|
||||
static var baseUrl: String {
|
||||
return "https://\(SystemConfig.serverHost)/api"
|
||||
let envConfig = SystemConfig.getCurrentEnvConfig()
|
||||
|
||||
return "https://\(envConfig.serverHost)/api"
|
||||
}
|
||||
|
||||
static private let token: String = "H6p*2RfEu4ITcL"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user