Compare commits
No commits in common. "28219a3bb36c829cda7a924164d105e69d169108" and "f86dd4c273ff48cccfa945ea30cec6634546176c" have entirely different histories.
28219a3bb3
...
f86dd4c273
@ -36,9 +36,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
let superPort = options["super_port"] as! Int
|
let superPort = options["super_port"] as! Int
|
||||||
let stunServersStr = options["stun_servers"] as! String
|
let stunServersStr = options["stun_servers"] as! String
|
||||||
let noticePort = options["notice_port"] as! Int
|
let noticePort = options["notice_port"] as! Int
|
||||||
let token = options["token"] as! String
|
|
||||||
let networkCode = options["network_code"] as! String
|
|
||||||
let clientId = options["client_id"] as! String
|
|
||||||
|
|
||||||
let stunServers = stunServersStr.split(separator: ";").compactMap { server -> SDLConfiguration.StunServer? in
|
let stunServers = stunServersStr.split(separator: ";").compactMap { server -> SDLConfiguration.StunServer? in
|
||||||
let parts = server.split(separator: ":", maxSplits: 2)
|
let parts = server.split(separator: ":", maxSplits: 2)
|
||||||
@ -58,18 +55,15 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||||||
NSLog("stunServers配置错误")
|
NSLog("stunServers配置错误")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog("[PacketTunnelProvider] client_id: \(clientId), token: \(token), network_code: \(networkCode)")
|
|
||||||
|
|
||||||
let config = SDLConfiguration(version: 1,
|
let config = SDLConfiguration(version: 1,
|
||||||
installedChannel: installed_channel,
|
installedChannel: installed_channel,
|
||||||
superHost: superIp,
|
superHost: superIp,
|
||||||
superPort: superPort,
|
superPort: superPort,
|
||||||
stunServers: stunServers,
|
stunServers: stunServers,
|
||||||
clientId: clientId,
|
clientId: SDLContext.getUUID(),
|
||||||
noticePort: noticePort,
|
noticePort: noticePort,
|
||||||
token: token,
|
token: "")
|
||||||
networkCode: networkCode)
|
|
||||||
// 加密算法
|
// 加密算法
|
||||||
let rsaCipher = try! CCRSACipher(keySize: 1024)
|
let rsaCipher = try! CCRSACipher(keySize: 1024)
|
||||||
let aesChiper = CCAESChiper()
|
let aesChiper = CCAESChiper()
|
||||||
|
|||||||
@ -50,9 +50,8 @@ public class SDLConfiguration {
|
|||||||
|
|
||||||
let clientId: String
|
let clientId: String
|
||||||
let token: String
|
let token: String
|
||||||
let networkCode: String
|
|
||||||
|
|
||||||
public init(version: UInt8, installedChannel: String, superHost: String, superPort: Int, stunServers: [StunServer], clientId: String, noticePort: Int, token: String, networkCode: String) {
|
public init(version: UInt8, installedChannel: String, superHost: String, superPort: Int, stunServers: [StunServer], clientId: String, noticePort: Int, token: String) {
|
||||||
self.version = version
|
self.version = version
|
||||||
self.installedChannel = installedChannel
|
self.installedChannel = installedChannel
|
||||||
self.superHost = superHost
|
self.superHost = superHost
|
||||||
@ -61,7 +60,6 @@ public class SDLConfiguration {
|
|||||||
self.clientId = clientId
|
self.clientId = clientId
|
||||||
self.noticePort = noticePort
|
self.noticePort = noticePort
|
||||||
self.token = token
|
self.token = token
|
||||||
self.networkCode = networkCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -249,7 +249,7 @@ public class SDLContext: @unchecked Sendable {
|
|||||||
let aesKey = try! self.rsaCipher.decode(data: Data(registerSuperAck.aesKey))
|
let aesKey = try! self.rsaCipher.decode(data: Data(registerSuperAck.aesKey))
|
||||||
let upgradeType = SDLUpgradeType(rawValue: registerSuperAck.upgradeType)
|
let upgradeType = SDLUpgradeType(rawValue: registerSuperAck.upgradeType)
|
||||||
|
|
||||||
self.logger.log("[SDLContext] get registerSuperAck, aes_key len: \(aesKey.count), network_id:\(registerSuperAck.devAddr.networkID)", level: .info)
|
self.logger.log("[SDLContext] get registerSuperAck, aes_key len: \(aesKey.count)", level: .info)
|
||||||
self.devAddr = registerSuperAck.devAddr
|
self.devAddr = registerSuperAck.devAddr
|
||||||
|
|
||||||
if upgradeType == .force {
|
if upgradeType == .force {
|
||||||
@ -589,6 +589,18 @@ public class SDLContext: @unchecked Sendable {
|
|||||||
self.superClient = nil
|
self.superClient = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func getUUID() -> String {
|
||||||
|
let userDefaults = UserDefaults.standard
|
||||||
|
if let uuid = userDefaults.value(forKey: "gClientId") as? String {
|
||||||
|
return uuid
|
||||||
|
} else {
|
||||||
|
let uuid = UUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased()
|
||||||
|
userDefaults.setValue(uuid, forKey: "gClientId")
|
||||||
|
|
||||||
|
return uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取mac地址
|
// 获取mac地址
|
||||||
public static func getMacAddress() -> Data {
|
public static func getMacAddress() -> Data {
|
||||||
let key = "gMacAddress2"
|
let key = "gMacAddress2"
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
// DO NOT EDIT.
|
// DO NOT EDIT.
|
||||||
// swift-format-ignore-file
|
// swift-format-ignore-file
|
||||||
// swiftlint:disable all
|
|
||||||
//
|
//
|
||||||
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
// Generated by the Swift generator plugin for the protocol buffer compiler.
|
||||||
// Source: sdlan_pb.proto
|
// Source: sdlan_pb.proto
|
||||||
@ -21,7 +20,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
|
|||||||
typealias Version = _2
|
typealias Version = _2
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLV4Info: @unchecked Sendable {
|
struct SDLV4Info {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -37,7 +36,7 @@ struct SDLV4Info: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLV6Info: @unchecked Sendable {
|
struct SDLV6Info {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -52,7 +51,7 @@ struct SDLV6Info: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 设备网络地址信息
|
/// 设备网络地址信息
|
||||||
struct SDLDevAddr: @unchecked Sendable {
|
struct SDLDevAddr {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -71,7 +70,7 @@ struct SDLDevAddr: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// tcp通讯消息
|
/// tcp通讯消息
|
||||||
struct SDLEmpty: Sendable {
|
struct SDLEmpty {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -81,7 +80,7 @@ struct SDLEmpty: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLRegisterSuper: Sendable {
|
struct SDLRegisterSuper {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -105,8 +104,6 @@ struct SDLRegisterSuper: Sendable {
|
|||||||
|
|
||||||
var token: String = String()
|
var token: String = String()
|
||||||
|
|
||||||
var networkCode: String = String()
|
|
||||||
|
|
||||||
var unknownFields = SwiftProtobuf.UnknownStorage()
|
var unknownFields = SwiftProtobuf.UnknownStorage()
|
||||||
|
|
||||||
init() {}
|
init() {}
|
||||||
@ -114,7 +111,7 @@ struct SDLRegisterSuper: Sendable {
|
|||||||
fileprivate var _devAddr: SDLDevAddr? = nil
|
fileprivate var _devAddr: SDLDevAddr? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLRegisterSuperAck: @unchecked Sendable {
|
struct SDLRegisterSuperAck {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -159,7 +156,7 @@ struct SDLRegisterSuperAck: @unchecked Sendable {
|
|||||||
fileprivate var _upgradeAddress: String? = nil
|
fileprivate var _upgradeAddress: String? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLRegisterSuperNak: Sendable {
|
struct SDLRegisterSuperNak {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -173,7 +170,7 @@ struct SDLRegisterSuperNak: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLQueryInfo: @unchecked Sendable {
|
struct SDLQueryInfo {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -185,7 +182,7 @@ struct SDLQueryInfo: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLPeerInfo: @unchecked Sendable {
|
struct SDLPeerInfo {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -201,6 +198,8 @@ struct SDLPeerInfo: @unchecked Sendable {
|
|||||||
/// Clears the value of `v4Info`. Subsequent reads from it will return its default value.
|
/// Clears the value of `v4Info`. Subsequent reads from it will return its default value.
|
||||||
mutating func clearV4Info() {self._v4Info = nil}
|
mutating func clearV4Info() {self._v4Info = nil}
|
||||||
|
|
||||||
|
var natType: UInt32 = 0
|
||||||
|
|
||||||
var v6Info: SDLV6Info {
|
var v6Info: SDLV6Info {
|
||||||
get {return _v6Info ?? SDLV6Info()}
|
get {return _v6Info ?? SDLV6Info()}
|
||||||
set {_v6Info = newValue}
|
set {_v6Info = newValue}
|
||||||
@ -218,7 +217,7 @@ struct SDLPeerInfo: @unchecked Sendable {
|
|||||||
fileprivate var _v6Info: SDLV6Info? = nil
|
fileprivate var _v6Info: SDLV6Info? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLNatChangedEvent: @unchecked Sendable {
|
struct SDLNatChangedEvent {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -232,7 +231,7 @@ struct SDLNatChangedEvent: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLSendRegisterEvent: @unchecked Sendable {
|
struct SDLSendRegisterEvent {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -243,8 +242,6 @@ struct SDLSendRegisterEvent: @unchecked Sendable {
|
|||||||
|
|
||||||
var natPort: UInt32 = 0
|
var natPort: UInt32 = 0
|
||||||
|
|
||||||
var natType: UInt32 = 0
|
|
||||||
|
|
||||||
var v6Info: SDLV6Info {
|
var v6Info: SDLV6Info {
|
||||||
get {return _v6Info ?? SDLV6Info()}
|
get {return _v6Info ?? SDLV6Info()}
|
||||||
set {_v6Info = newValue}
|
set {_v6Info = newValue}
|
||||||
@ -261,7 +258,7 @@ struct SDLSendRegisterEvent: @unchecked Sendable {
|
|||||||
fileprivate var _v6Info: SDLV6Info? = nil
|
fileprivate var _v6Info: SDLV6Info? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLNetworkShutdownEvent: Sendable {
|
struct SDLNetworkShutdownEvent {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -273,7 +270,7 @@ struct SDLNetworkShutdownEvent: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLChangeNetworkCommand: @unchecked Sendable {
|
struct SDLChangeNetworkCommand {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -296,7 +293,7 @@ struct SDLChangeNetworkCommand: @unchecked Sendable {
|
|||||||
fileprivate var _devAddr: SDLDevAddr? = nil
|
fileprivate var _devAddr: SDLDevAddr? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLCommandAck: Sendable {
|
struct SDLCommandAck {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -320,7 +317,7 @@ struct SDLCommandAck: Sendable {
|
|||||||
fileprivate var _message: String? = nil
|
fileprivate var _message: String? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLFlows: Sendable {
|
struct SDLFlows {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -339,7 +336,7 @@ struct SDLFlows: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLStunRequest: @unchecked Sendable {
|
struct SDLStunRequest {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -372,7 +369,7 @@ struct SDLStunRequest: @unchecked Sendable {
|
|||||||
fileprivate var _v6Info: SDLV6Info? = nil
|
fileprivate var _v6Info: SDLV6Info? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLStunReply: Sendable {
|
struct SDLStunReply {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -384,7 +381,7 @@ struct SDLStunReply: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLData: @unchecked Sendable {
|
struct SDLData {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -406,7 +403,7 @@ struct SDLData: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLRegister: @unchecked Sendable {
|
struct SDLRegister {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -422,7 +419,7 @@ struct SDLRegister: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLRegisterAck: @unchecked Sendable {
|
struct SDLRegisterAck {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -438,7 +435,7 @@ struct SDLRegisterAck: @unchecked Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLStunProbe: Sendable {
|
struct SDLStunProbe {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -452,7 +449,7 @@ struct SDLStunProbe: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDLStunProbeReply: Sendable {
|
struct SDLStunProbeReply {
|
||||||
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
// SwiftProtobuf.Message conformance is added in an extension below. See the
|
||||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||||
// methods supported on all messages.
|
// methods supported on all messages.
|
||||||
@ -468,6 +465,31 @@ struct SDLStunProbeReply: Sendable {
|
|||||||
init() {}
|
init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if swift(>=5.5) && canImport(_Concurrency)
|
||||||
|
extension SDLV4Info: @unchecked Sendable {}
|
||||||
|
extension SDLV6Info: @unchecked Sendable {}
|
||||||
|
extension SDLDevAddr: @unchecked Sendable {}
|
||||||
|
extension SDLEmpty: @unchecked Sendable {}
|
||||||
|
extension SDLRegisterSuper: @unchecked Sendable {}
|
||||||
|
extension SDLRegisterSuperAck: @unchecked Sendable {}
|
||||||
|
extension SDLRegisterSuperNak: @unchecked Sendable {}
|
||||||
|
extension SDLQueryInfo: @unchecked Sendable {}
|
||||||
|
extension SDLPeerInfo: @unchecked Sendable {}
|
||||||
|
extension SDLNatChangedEvent: @unchecked Sendable {}
|
||||||
|
extension SDLSendRegisterEvent: @unchecked Sendable {}
|
||||||
|
extension SDLNetworkShutdownEvent: @unchecked Sendable {}
|
||||||
|
extension SDLChangeNetworkCommand: @unchecked Sendable {}
|
||||||
|
extension SDLCommandAck: @unchecked Sendable {}
|
||||||
|
extension SDLFlows: @unchecked Sendable {}
|
||||||
|
extension SDLStunRequest: @unchecked Sendable {}
|
||||||
|
extension SDLStunReply: @unchecked Sendable {}
|
||||||
|
extension SDLData: @unchecked Sendable {}
|
||||||
|
extension SDLRegister: @unchecked Sendable {}
|
||||||
|
extension SDLRegisterAck: @unchecked Sendable {}
|
||||||
|
extension SDLStunProbe: @unchecked Sendable {}
|
||||||
|
extension SDLStunProbeReply: @unchecked Sendable {}
|
||||||
|
#endif // swift(>=5.5) && canImport(_Concurrency)
|
||||||
|
|
||||||
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
// MARK: - Code below here is support for the SwiftProtobuf runtime.
|
||||||
|
|
||||||
extension SDLV4Info: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
extension SDLV4Info: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
|
||||||
@ -607,8 +629,8 @@ extension SDLEmpty: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationB
|
|||||||
static let _protobuf_nameMap = SwiftProtobuf._NameMap()
|
static let _protobuf_nameMap = SwiftProtobuf._NameMap()
|
||||||
|
|
||||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||||
// Load everything into unknown fields
|
while let _ = try decoder.nextFieldNumber() {
|
||||||
while try decoder.nextFieldNumber() != nil {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
|
||||||
@ -630,7 +652,6 @@ extension SDLRegisterSuper: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme
|
|||||||
4: .standard(proto: "dev_addr"),
|
4: .standard(proto: "dev_addr"),
|
||||||
5: .standard(proto: "pub_key"),
|
5: .standard(proto: "pub_key"),
|
||||||
6: .same(proto: "token"),
|
6: .same(proto: "token"),
|
||||||
7: .standard(proto: "network_code"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||||
@ -645,7 +666,6 @@ extension SDLRegisterSuper: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme
|
|||||||
case 4: try { try decoder.decodeSingularMessageField(value: &self._devAddr) }()
|
case 4: try { try decoder.decodeSingularMessageField(value: &self._devAddr) }()
|
||||||
case 5: try { try decoder.decodeSingularStringField(value: &self.pubKey) }()
|
case 5: try { try decoder.decodeSingularStringField(value: &self.pubKey) }()
|
||||||
case 6: try { try decoder.decodeSingularStringField(value: &self.token) }()
|
case 6: try { try decoder.decodeSingularStringField(value: &self.token) }()
|
||||||
case 7: try { try decoder.decodeSingularStringField(value: &self.networkCode) }()
|
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -674,9 +694,6 @@ extension SDLRegisterSuper: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme
|
|||||||
if !self.token.isEmpty {
|
if !self.token.isEmpty {
|
||||||
try visitor.visitSingularStringField(value: self.token, fieldNumber: 6)
|
try visitor.visitSingularStringField(value: self.token, fieldNumber: 6)
|
||||||
}
|
}
|
||||||
if !self.networkCode.isEmpty {
|
|
||||||
try visitor.visitSingularStringField(value: self.networkCode, fieldNumber: 7)
|
|
||||||
}
|
|
||||||
try unknownFields.traverse(visitor: &visitor)
|
try unknownFields.traverse(visitor: &visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +704,6 @@ extension SDLRegisterSuper: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme
|
|||||||
if lhs._devAddr != rhs._devAddr {return false}
|
if lhs._devAddr != rhs._devAddr {return false}
|
||||||
if lhs.pubKey != rhs.pubKey {return false}
|
if lhs.pubKey != rhs.pubKey {return false}
|
||||||
if lhs.token != rhs.token {return false}
|
if lhs.token != rhs.token {return false}
|
||||||
if lhs.networkCode != rhs.networkCode {return false}
|
|
||||||
if lhs.unknownFields != rhs.unknownFields {return false}
|
if lhs.unknownFields != rhs.unknownFields {return false}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -828,7 +844,8 @@ extension SDLPeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
|
|||||||
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
|
||||||
1: .standard(proto: "dst_mac"),
|
1: .standard(proto: "dst_mac"),
|
||||||
2: .standard(proto: "v4_info"),
|
2: .standard(proto: "v4_info"),
|
||||||
3: .standard(proto: "v6_info"),
|
3: .standard(proto: "nat_type"),
|
||||||
|
4: .standard(proto: "v6_info"),
|
||||||
]
|
]
|
||||||
|
|
||||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||||
@ -839,7 +856,8 @@ extension SDLPeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
|
|||||||
switch fieldNumber {
|
switch fieldNumber {
|
||||||
case 1: try { try decoder.decodeSingularBytesField(value: &self.dstMac) }()
|
case 1: try { try decoder.decodeSingularBytesField(value: &self.dstMac) }()
|
||||||
case 2: try { try decoder.decodeSingularMessageField(value: &self._v4Info) }()
|
case 2: try { try decoder.decodeSingularMessageField(value: &self._v4Info) }()
|
||||||
case 3: try { try decoder.decodeSingularMessageField(value: &self._v6Info) }()
|
case 3: try { try decoder.decodeSingularUInt32Field(value: &self.natType) }()
|
||||||
|
case 4: try { try decoder.decodeSingularMessageField(value: &self._v6Info) }()
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -856,8 +874,11 @@ extension SDLPeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
|
|||||||
try { if let v = self._v4Info {
|
try { if let v = self._v4Info {
|
||||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
|
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
|
||||||
} }()
|
} }()
|
||||||
|
if self.natType != 0 {
|
||||||
|
try visitor.visitSingularUInt32Field(value: self.natType, fieldNumber: 3)
|
||||||
|
}
|
||||||
try { if let v = self._v6Info {
|
try { if let v = self._v6Info {
|
||||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
|
try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
|
||||||
} }()
|
} }()
|
||||||
try unknownFields.traverse(visitor: &visitor)
|
try unknownFields.traverse(visitor: &visitor)
|
||||||
}
|
}
|
||||||
@ -865,6 +886,7 @@ extension SDLPeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati
|
|||||||
static func ==(lhs: SDLPeerInfo, rhs: SDLPeerInfo) -> Bool {
|
static func ==(lhs: SDLPeerInfo, rhs: SDLPeerInfo) -> Bool {
|
||||||
if lhs.dstMac != rhs.dstMac {return false}
|
if lhs.dstMac != rhs.dstMac {return false}
|
||||||
if lhs._v4Info != rhs._v4Info {return false}
|
if lhs._v4Info != rhs._v4Info {return false}
|
||||||
|
if lhs.natType != rhs.natType {return false}
|
||||||
if lhs._v6Info != rhs._v6Info {return false}
|
if lhs._v6Info != rhs._v6Info {return false}
|
||||||
if lhs.unknownFields != rhs.unknownFields {return false}
|
if lhs.unknownFields != rhs.unknownFields {return false}
|
||||||
return true
|
return true
|
||||||
@ -915,8 +937,7 @@ extension SDLSendRegisterEvent: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
|
|||||||
1: .standard(proto: "dst_mac"),
|
1: .standard(proto: "dst_mac"),
|
||||||
2: .standard(proto: "nat_ip"),
|
2: .standard(proto: "nat_ip"),
|
||||||
3: .standard(proto: "nat_port"),
|
3: .standard(proto: "nat_port"),
|
||||||
4: .standard(proto: "nat_type"),
|
4: .standard(proto: "v6_info"),
|
||||||
5: .standard(proto: "v6_info"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
|
||||||
@ -928,8 +949,7 @@ extension SDLSendRegisterEvent: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
|
|||||||
case 1: try { try decoder.decodeSingularBytesField(value: &self.dstMac) }()
|
case 1: try { try decoder.decodeSingularBytesField(value: &self.dstMac) }()
|
||||||
case 2: try { try decoder.decodeSingularUInt32Field(value: &self.natIp) }()
|
case 2: try { try decoder.decodeSingularUInt32Field(value: &self.natIp) }()
|
||||||
case 3: try { try decoder.decodeSingularUInt32Field(value: &self.natPort) }()
|
case 3: try { try decoder.decodeSingularUInt32Field(value: &self.natPort) }()
|
||||||
case 4: try { try decoder.decodeSingularUInt32Field(value: &self.natType) }()
|
case 4: try { try decoder.decodeSingularMessageField(value: &self._v6Info) }()
|
||||||
case 5: try { try decoder.decodeSingularMessageField(value: &self._v6Info) }()
|
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -949,11 +969,8 @@ extension SDLSendRegisterEvent: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
|
|||||||
if self.natPort != 0 {
|
if self.natPort != 0 {
|
||||||
try visitor.visitSingularUInt32Field(value: self.natPort, fieldNumber: 3)
|
try visitor.visitSingularUInt32Field(value: self.natPort, fieldNumber: 3)
|
||||||
}
|
}
|
||||||
if self.natType != 0 {
|
|
||||||
try visitor.visitSingularUInt32Field(value: self.natType, fieldNumber: 4)
|
|
||||||
}
|
|
||||||
try { if let v = self._v6Info {
|
try { if let v = self._v6Info {
|
||||||
try visitor.visitSingularMessageField(value: v, fieldNumber: 5)
|
try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
|
||||||
} }()
|
} }()
|
||||||
try unknownFields.traverse(visitor: &visitor)
|
try unknownFields.traverse(visitor: &visitor)
|
||||||
}
|
}
|
||||||
@ -962,7 +979,6 @@ extension SDLSendRegisterEvent: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
|
|||||||
if lhs.dstMac != rhs.dstMac {return false}
|
if lhs.dstMac != rhs.dstMac {return false}
|
||||||
if lhs.natIp != rhs.natIp {return false}
|
if lhs.natIp != rhs.natIp {return false}
|
||||||
if lhs.natPort != rhs.natPort {return false}
|
if lhs.natPort != rhs.natPort {return false}
|
||||||
if lhs.natType != rhs.natType {return false}
|
|
||||||
if lhs._v6Info != rhs._v6Info {return false}
|
if lhs._v6Info != rhs._v6Info {return false}
|
||||||
if lhs.unknownFields != rhs.unknownFields {return false}
|
if lhs.unknownFields != rhs.unknownFields {return false}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@ -148,9 +148,6 @@ actor SDLSuperClient {
|
|||||||
registerSuper.devAddr = ctx.devAddr
|
registerSuper.devAddr = ctx.devAddr
|
||||||
registerSuper.pubKey = ctx.rsaCipher.pubKey
|
registerSuper.pubKey = ctx.rsaCipher.pubKey
|
||||||
registerSuper.token = ctx.config.token
|
registerSuper.token = ctx.config.token
|
||||||
registerSuper.networkCode = ctx.config.networkCode
|
|
||||||
|
|
||||||
NSLog("[SuperClient] register super request: \(registerSuper)")
|
|
||||||
|
|
||||||
let data = try! registerSuper.serializedData()
|
let data = try! registerSuper.serializedData()
|
||||||
|
|
||||||
|
|||||||
@ -128,11 +128,7 @@ actor SDLUDPHole {
|
|||||||
|
|
||||||
// MARK: super_node apis
|
// MARK: super_node apis
|
||||||
|
|
||||||
func stunRequest(context ctx: SDLContext) -> UInt32? {
|
func stunRequest(context ctx: SDLContext) -> UInt32 {
|
||||||
guard ctx.devAddr.networkID > 0 else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let cookie = self.cookieGenerator.nextId()
|
let cookie = self.cookieGenerator.nextId()
|
||||||
let remoteAddress = ctx.config.stunSocketAddress
|
let remoteAddress = ctx.config.stunSocketAddress
|
||||||
|
|
||||||
@ -144,7 +140,7 @@ actor SDLUDPHole {
|
|||||||
stunRequest.mac = ctx.devAddr.mac
|
stunRequest.mac = ctx.devAddr.mac
|
||||||
stunRequest.natType = UInt32(ctx.natType.rawValue)
|
stunRequest.natType = UInt32(ctx.natType.rawValue)
|
||||||
|
|
||||||
self.logger.log("[SDLUDPHole] stunRequest: \(remoteAddress), host: \(ctx.config.stunServers[0].host):\(ctx.config.stunServers[0].ports[0]), network_id: \(ctx.devAddr.networkID)", level: .debug)
|
self.logger.log("[SDLUDPHole] stunRequest: \(remoteAddress), host: \(ctx.config.stunServers[0].host):\(ctx.config.stunServers[0].ports[0])", level: .debug)
|
||||||
|
|
||||||
self.send(remoteAddress: remoteAddress, type: .stunRequest, data: try! stunRequest.serializedData())
|
self.send(remoteAddress: remoteAddress, type: .stunRequest, data: try! stunRequest.serializedData())
|
||||||
|
|
||||||
|
|||||||
2
dmg.sh
2
dmg.sh
@ -1,3 +1,3 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
create-dmg --volname "punchnet" --window-pos 200 120 --window-size 800 400 --icon "punchnet.app" 200 190 --hide-extension "punchnet.app" --app-drop-link 600 185 ~/Desktop/punchnet.dmg /Users/anlicheng/Desktop/punchnet_macos_v1
|
create-dmg --volname "punchnet" --window-pos 200 120 --window-size 800 400 --icon "punchnet.app" 200 190 --hide-extension "punchnet.app" --app-drop-link 600 185 ~/Desktop/punchnet.dmg /Users/anlicheng/Desktop/punchnet_v1
|
||||||
|
|||||||
@ -561,7 +561,6 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_ENTITLEMENTS = punchnet/punchnet.entitlements;
|
CODE_SIGN_ENTITLEMENTS = punchnet/punchnet.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
|
||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Manual;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
@ -579,10 +578,10 @@
|
|||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac;
|
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTest;
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnet;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
@ -594,7 +593,6 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_ENTITLEMENTS = punchnet/punchnet.entitlements;
|
CODE_SIGN_ENTITLEMENTS = punchnet/punchnet.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
|
||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Manual;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
@ -612,10 +610,10 @@
|
|||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac;
|
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTest;
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnet;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
@ -660,7 +658,6 @@
|
|||||||
C8A77F212DD1E6D100195617 /* Debug */ = {
|
C8A77F212DD1E6D100195617 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = PF3QG837XS;
|
DEVELOPMENT_TEAM = PF3QG837XS;
|
||||||
@ -678,7 +675,6 @@
|
|||||||
C8A77F222DD1E6D100195617 /* Release */ = {
|
C8A77F222DD1E6D100195617 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = PF3QG837XS;
|
DEVELOPMENT_TEAM = PF3QG837XS;
|
||||||
@ -715,10 +711,10 @@
|
|||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac.tun;
|
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet.tun;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTunTest;
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTun;
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@ -747,10 +743,10 @@
|
|||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
MACOSX_DEPLOYMENT_TARGET = 14.6;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnetmac.tun;
|
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet.tun;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTunTest;
|
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = MacPunchnetTun;
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
|
|||||||
@ -7,23 +7,13 @@
|
|||||||
<key>Tun.xcscheme_^#shared#^_</key>
|
<key>Tun.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>2</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>punchnet.xcscheme_^#shared#^_</key>
|
<key>punchnet.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>punchnetTests.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
<key>punchnetUITests.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
</dict>
|
||||||
<key>SuppressBuildableAutocreation</key>
|
<key>SuppressBuildableAutocreation</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -32,11 +22,6 @@
|
|||||||
<key>primary</key>
|
<key>primary</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
<key>C8A77F052DD1E6D100195617</key>
|
|
||||||
<dict>
|
|
||||||
<key>primary</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
<key>C8A77F262DD1E77B00195617</key>
|
<key>C8A77F262DD1E77B00195617</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>primary</key>
|
<key>primary</key>
|
||||||
|
|||||||
@ -20,23 +20,12 @@ struct JSONRPCError: Decodable {
|
|||||||
|
|
||||||
struct SDLAPI {
|
struct SDLAPI {
|
||||||
|
|
||||||
static let baseUrl: String = "https://punchnet.s5s8.com/api"
|
|
||||||
static let testBaseUrl: String = "http://127.0.0.1:19082/test"
|
|
||||||
|
|
||||||
struct Upgrade: Decodable {
|
struct Upgrade: Decodable {
|
||||||
let upgrade_type: Int
|
let upgrade_type: Int
|
||||||
let upgrade_prompt: String
|
let upgrade_prompt: String
|
||||||
let upgrade_address: String
|
let upgrade_address: String
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NetworkProfile: Decodable {
|
|
||||||
struct NetworkItem: Decodable {
|
|
||||||
let name: String
|
|
||||||
let code: String
|
|
||||||
}
|
|
||||||
let network: [NetworkItem]
|
|
||||||
}
|
|
||||||
|
|
||||||
static func checkVersion(clientId: String, version: Int, channel: String) async throws -> JSONRPCResponse<Upgrade> {
|
static func checkVersion(clientId: String, version: Int, channel: String) async throws -> JSONRPCResponse<Upgrade> {
|
||||||
let params: [String:Any] = [
|
let params: [String:Any] = [
|
||||||
"client_id": clientId,
|
"client_id": clientId,
|
||||||
@ -45,7 +34,7 @@ struct SDLAPI {
|
|||||||
]
|
]
|
||||||
|
|
||||||
let postData = try! JSONSerialization.data(withJSONObject: params)
|
let postData = try! JSONSerialization.data(withJSONObject: params)
|
||||||
var request = URLRequest(url: URL(string: baseUrl + "/upgrade")!)
|
var request = URLRequest(url: URL(string: "http://127.0.0.1:18082/test/upgrade")!)
|
||||||
request.httpMethod = "POST"
|
request.httpMethod = "POST"
|
||||||
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||||
request.httpBody = postData
|
request.httpBody = postData
|
||||||
@ -55,20 +44,4 @@ struct SDLAPI {
|
|||||||
return try JSONDecoder().decode(JSONRPCResponse<Upgrade>.self, from: data)
|
return try JSONDecoder().decode(JSONRPCResponse<Upgrade>.self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getUserNetworks(clientId: String) async throws -> JSONRPCResponse<NetworkProfile> {
|
|
||||||
let params: [String:Any] = [
|
|
||||||
"client_id": clientId
|
|
||||||
]
|
|
||||||
|
|
||||||
let postData = try! JSONSerialization.data(withJSONObject: params)
|
|
||||||
var request = URLRequest(url: URL(string: baseUrl + "/get_user_network")!)
|
|
||||||
request.httpMethod = "POST"
|
|
||||||
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
||||||
request.httpBody = postData
|
|
||||||
|
|
||||||
let (data, _) = try await URLSession.shared.data(for: request)
|
|
||||||
|
|
||||||
return try JSONDecoder().decode(JSONRPCResponse<NetworkProfile>.self, from: data)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,43 +19,28 @@ struct SystemConfig {
|
|||||||
// super 节点
|
// super 节点
|
||||||
//static let superHost = "118.178.229.213"
|
//static let superHost = "118.178.229.213"
|
||||||
|
|
||||||
static let superHost = "punchnet.s5s8.com"
|
static let superHost = "punchnet.aioe.tech"
|
||||||
static let superPort = 18083
|
static let superPort = 18083
|
||||||
|
|
||||||
// stun探测服务
|
// stun探测服务
|
||||||
static let stunServers = "118.178.229.213:1265,1266;118.178.229.213:1265,1266"
|
static let stunServers = "118.178.229.213:1265,1266;118.178.229.213:1265,1266"
|
||||||
//static let stunServers = "127.0.0.1:1265,1266;127.0.0.1:1265,1266"
|
|
||||||
|
|
||||||
static func getOptions(networkCode: String, token: String, clientId: String, noticePort: Int) -> [String:NSObject]? {
|
static func getOptions(token: String) -> [String:NSObject]? {
|
||||||
guard let superIp = DNSResolver.resolveAddrInfos(superHost).first else {
|
guard let superIp = DNSResolver.resolveAddrInfos(superHost).first else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = [
|
let options = [
|
||||||
"version:": version as NSObject,
|
"version:": version as NSObject,
|
||||||
"installed_channel": installedChannel as NSObject,
|
"installed_channel": installedChannel as NSObject,
|
||||||
"client_id": clientId as NSObject,
|
|
||||||
"network_code": networkCode as NSObject,
|
|
||||||
"token": token as NSObject,
|
"token": token as NSObject,
|
||||||
"super_ip": superIp as NSObject,
|
"super_ip": "118.178.229.213" as NSObject,
|
||||||
"super_port": superPort as NSObject,
|
"super_port": superPort as NSObject,
|
||||||
"stun_servers": stunServers as NSObject,
|
"stun_servers": stunServers as NSObject
|
||||||
"notice_port": noticePort as NSObject
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
print("options: \(options)")
|
||||||
|
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func getClientId() -> String {
|
|
||||||
let userDefaults = UserDefaults.standard
|
|
||||||
if let uuid = userDefaults.value(forKey: "gClientId") as? String {
|
|
||||||
return uuid
|
|
||||||
} else {
|
|
||||||
let uuid = UUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased()
|
|
||||||
userDefaults.setValue(uuid, forKey: "gClientId")
|
|
||||||
|
|
||||||
return uuid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,11 @@ final class UDPNoticeCenterServer: ChannelInboundHandler {
|
|||||||
private var channel: Channel?
|
private var channel: Channel?
|
||||||
|
|
||||||
var messageFlow = PassthroughSubject<NoticeMessage.InboundMessage, Never>()
|
var messageFlow = PassthroughSubject<NoticeMessage.InboundMessage, Never>()
|
||||||
public var port: Int = 0
|
static let shared = UDPNoticeCenterServer()
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||||
@ -27,8 +31,7 @@ final class UDPNoticeCenterServer: ChannelInboundHandler {
|
|||||||
.channelInitializer { channel in
|
.channelInitializer { channel in
|
||||||
channel.pipeline.addHandler(self)
|
channel.pipeline.addHandler(self)
|
||||||
}
|
}
|
||||||
self.channel = try! bootstrap.bind(host: "127.0.0.1", port: 0).wait()
|
self.channel = try! bootstrap.bind(host: "127.0.0.1", port: 50195).wait()
|
||||||
self.port = self.channel?.localAddress?.port ?? 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
|
|||||||
@ -28,7 +28,6 @@ class VPNManager: ObservableObject {
|
|||||||
|
|
||||||
// 开启vpn
|
// 开启vpn
|
||||||
func enableVpn(options: [String : NSObject]) async throws {
|
func enableVpn(options: [String : NSObject]) async throws {
|
||||||
NSLog("enable vpn with options: \(options)")
|
|
||||||
let manager = try await loadAndCreateProviderManager()
|
let manager = try await loadAndCreateProviderManager()
|
||||||
try await manager.loadFromPreferences()
|
try await manager.loadFromPreferences()
|
||||||
self.addVPNStatusObserver(manager)
|
self.addVPNStatusObserver(manager)
|
||||||
@ -74,14 +73,14 @@ class VPNManager: ObservableObject {
|
|||||||
let managers = try await NETunnelProviderManager.loadAllFromPreferences()
|
let managers = try await NETunnelProviderManager.loadAllFromPreferences()
|
||||||
|
|
||||||
let manager = managers.first ?? NETunnelProviderManager()
|
let manager = managers.first ?? NETunnelProviderManager()
|
||||||
manager.localizedDescription = "punchnetmac"
|
manager.localizedDescription = "punchnet"
|
||||||
manager.isEnabled = true
|
manager.isEnabled = true
|
||||||
|
|
||||||
// 设置相关参数,在PacketTunnel中可以用
|
// 设置相关参数,在PacketTunnel中可以用
|
||||||
let protocolConfiguration = NETunnelProviderProtocol()
|
let protocolConfiguration = NETunnelProviderProtocol()
|
||||||
protocolConfiguration.serverAddress = "punchnetmac"
|
protocolConfiguration.serverAddress = "punchnet"
|
||||||
protocolConfiguration.providerConfiguration = [String:AnyObject]()
|
protocolConfiguration.providerConfiguration = [String:AnyObject]()
|
||||||
protocolConfiguration.providerBundleIdentifier = "com.jihe.punchnetmac.tun"
|
protocolConfiguration.providerBundleIdentifier = "com.jihe.punchnet.tun"
|
||||||
manager.protocolConfiguration = protocolConfiguration
|
manager.protocolConfiguration = protocolConfiguration
|
||||||
manager.isOnDemandEnabled = false
|
manager.isOnDemandEnabled = false
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,6 @@ import Combine
|
|||||||
|
|
||||||
struct IndexView: View {
|
struct IndexView: View {
|
||||||
@AppStorage("token") private var token: String = ""
|
@AppStorage("token") private var token: String = ""
|
||||||
@AppStorage("network_code") private var networkCode: String = ""
|
|
||||||
|
|
||||||
@State private var showToken: Bool = false
|
@State private var showToken: Bool = false
|
||||||
|
|
||||||
@ObservedObject private var vpnManager = VPNManager.shared
|
@ObservedObject private var vpnManager = VPNManager.shared
|
||||||
@ -23,15 +21,6 @@ struct IndexView: View {
|
|||||||
|
|
||||||
@State private var showMenu: Bool = false
|
@State private var showMenu: Bool = false
|
||||||
|
|
||||||
@State private var networkProfile: SDLAPI.NetworkProfile = .init(network: [])
|
|
||||||
@State private var selectedIdx: Int = 0
|
|
||||||
|
|
||||||
// 显示ip信息
|
|
||||||
@State private var showIpAdress: Bool = false
|
|
||||||
@State private var ipAddress: String = ""
|
|
||||||
|
|
||||||
public var noticeServer: UDPNoticeCenterServer
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
VStack(alignment: .center, spacing: 10) {
|
VStack(alignment: .center, spacing: 10) {
|
||||||
@ -58,55 +47,19 @@ struct IndexView: View {
|
|||||||
self.showMenu = false
|
self.showMenu = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if showIpAdress {
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Text("ip: ")
|
|
||||||
.font(.system(size: 16, weight: .medium))
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.cornerRadius(5.0)
|
|
||||||
|
|
||||||
Text(ipAddress)
|
|
||||||
.font(.system(size: 16, weight: .medium))
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.cornerRadius(5.0)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
.frame(width: 1, height: 10)
|
.frame(width: 1, height: 10)
|
||||||
|
|
||||||
VStack(spacing: 0) {
|
if showToken {
|
||||||
ForEach(Array(networkProfile.network.enumerated()), id: \.offset) { idx, network in
|
TextField("邀请码", text: $token)
|
||||||
NetworkItemView(idx: idx, item: network)
|
.multilineTextAlignment(.leading)
|
||||||
.padding(.horizontal, 8)
|
.textFieldStyle(PlainTextFieldStyle())
|
||||||
.padding(.vertical, 6)
|
.frame(width: 200, height: 25)
|
||||||
.background(
|
.background(Color.white)
|
||||||
RoundedRectangle(cornerRadius: 8)
|
.foregroundColor(Color.black)
|
||||||
.fill(selectedIdx == idx ? Color.blue.opacity(0.3) : Color.clear)
|
.cornerRadius(5.0)
|
||||||
)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
withAnimation(.easeInOut(duration: 0.2)) {
|
|
||||||
selectedIdx = idx
|
|
||||||
self.networkCode = network.code
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField("邀请码", text: $token)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
.textFieldStyle(PlainTextFieldStyle())
|
|
||||||
.frame(width: 200, height: 25)
|
|
||||||
.background(Color.white)
|
|
||||||
.foregroundColor(Color.black)
|
|
||||||
.cornerRadius(5.0)
|
|
||||||
.opacity(showToken ? 1 : 0)
|
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
.frame(width: 1, height: 10)
|
.frame(width: 1, height: 10)
|
||||||
|
|
||||||
@ -128,6 +81,8 @@ struct IndexView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
.overlay(alignment: .top) {
|
.overlay(alignment: .top) {
|
||||||
|
|
||||||
@ -205,10 +160,8 @@ struct IndexView: View {
|
|||||||
}
|
}
|
||||||
.offset(x: 0, y: 10)
|
.offset(x: 0, y: 10)
|
||||||
}
|
}
|
||||||
.padding([.leading, .trailing, .top], 10)
|
.frame(width: 300, height: 500)
|
||||||
.padding([.bottom], 20)
|
|
||||||
.background(Color(red: 36 / 255, green: 38 / 255, blue: 51 / 255))
|
.background(Color(red: 36 / 255, green: 38 / 255, blue: 51 / 255))
|
||||||
.frame(width: 320)
|
|
||||||
.alert(isPresented: $showAlert) {
|
.alert(isPresented: $showAlert) {
|
||||||
Alert(title: Text("请输入正确的邀请码"))
|
Alert(title: Text("请输入正确的邀请码"))
|
||||||
}
|
}
|
||||||
@ -222,33 +175,11 @@ struct IndexView: View {
|
|||||||
Alert(title: Text(""))
|
Alert(title: Text(""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.task {
|
|
||||||
do {
|
|
||||||
let response = try await SDLAPI.getUserNetworks(clientId: SystemConfig.getClientId())
|
|
||||||
print("get user networks: \(response)")
|
|
||||||
if let result = response.result {
|
|
||||||
self.networkProfile = result
|
|
||||||
if self.networkProfile.network.count > 0 {
|
|
||||||
self.networkCode = self.networkProfile.network[0].code
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch let err {
|
|
||||||
NSLog("get user networks get error: \(err)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onAppear {
|
.onAppear {
|
||||||
self.cancel = self.noticeServer.messageFlow.sink{ message in
|
self.cancel = UDPNoticeCenterServer.shared.messageFlow.sink{ message in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
switch message {
|
self.message = message
|
||||||
case .none:
|
self.showStunAlert = true
|
||||||
()
|
|
||||||
case .ip(let ip):
|
|
||||||
self.showIpAdress = true
|
|
||||||
self.ipAddress = ip
|
|
||||||
default:
|
|
||||||
self.message = message
|
|
||||||
self.showStunAlert = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,43 +188,15 @@ struct IndexView: View {
|
|||||||
private func clickSwitchButton() async throws {
|
private func clickSwitchButton() async throws {
|
||||||
switch self.vpnManager.vpnStatus {
|
switch self.vpnManager.vpnStatus {
|
||||||
case .connected:
|
case .connected:
|
||||||
self.showIpAdress = false
|
|
||||||
self.ipAddress = ""
|
|
||||||
try await vpnManager.disableVpn()
|
try await vpnManager.disableVpn()
|
||||||
case .disconnected:
|
case .disconnected:
|
||||||
let clientId = SystemConfig.getClientId()
|
try await vpnManager.enableVpn(options: SystemConfig.getOptions(token: self.token)!)
|
||||||
NSLog("[IndexView] use token: \(self.token), network_code: \(networkCode)")
|
|
||||||
// token存在则优先使用token
|
|
||||||
try await vpnManager.enableVpn(options: SystemConfig.getOptions(networkCode: self.networkCode, token: self.token, clientId: clientId, noticePort: self.noticeServer.port)!)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IndexView {
|
|
||||||
struct NetworkItemView: View {
|
|
||||||
let idx: Int
|
|
||||||
let item: SDLAPI.NetworkProfile.NetworkItem
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
HStack {
|
|
||||||
Text(item.name)
|
|
||||||
.font(.system(size: 14))
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.frame(width: 80, alignment: .leading)
|
|
||||||
|
|
||||||
Text(item.code)
|
|
||||||
.font(.system(size: 14))
|
|
||||||
.foregroundColor(.white)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
let server = UDPNoticeCenterServer()
|
IndexView()
|
||||||
IndexView(noticeServer: server)
|
|
||||||
//.modelContainer(for: Item.self, inMemory: true)
|
//.modelContainer(for: Item.self, inMemory: true)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,19 +31,12 @@ struct punchnetApp: App {
|
|||||||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||||
|
|
||||||
@AppStorage("token") var token: String = ""
|
@AppStorage("token") var token: String = ""
|
||||||
@AppStorage("network_code") var networkCode: String = ""
|
|
||||||
@ObservedObject var vpnManager = VPNManager.shared
|
@ObservedObject var vpnManager = VPNManager.shared
|
||||||
|
|
||||||
private var noticeServer: UDPNoticeCenterServer
|
|
||||||
|
|
||||||
init() {
|
|
||||||
self.noticeServer = UDPNoticeCenterServer()
|
|
||||||
self.noticeServer.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup(id: "mainWindow") {
|
WindowGroup(id: "mainWindow") {
|
||||||
IndexView(noticeServer: self.noticeServer)
|
IndexView()
|
||||||
|
.frame(minWidth: 300, maxWidth: 300, minHeight: 500, maxHeight: 500)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
// 获取主屏幕的尺寸
|
// 获取主屏幕的尺寸
|
||||||
guard let screenFrame = NSScreen.main?.frame else { return }
|
guard let screenFrame = NSScreen.main?.frame else { return }
|
||||||
@ -60,8 +53,6 @@ struct punchnetApp: App {
|
|||||||
window.setFrameOrigin(NSPoint(x: centerX, y: centerY))
|
window.setFrameOrigin(NSPoint(x: centerX, y: centerY))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.toolbar(.hidden)
|
|
||||||
.navigationTitle("")
|
|
||||||
}
|
}
|
||||||
.commands {
|
.commands {
|
||||||
CommandGroup(replacing: .appInfo) {
|
CommandGroup(replacing: .appInfo) {
|
||||||
@ -103,8 +94,7 @@ struct punchnetApp: App {
|
|||||||
switch self.vpnManager.vpnStatus {
|
switch self.vpnManager.vpnStatus {
|
||||||
case .disconnected:
|
case .disconnected:
|
||||||
Task {
|
Task {
|
||||||
let clientId = SystemConfig.getClientId()
|
try await vpnManager.enableVpn(options: SystemConfig.getOptions(token: self.token)!)
|
||||||
try await vpnManager.enableVpn(options: SystemConfig.getOptions(networkCode: self.networkCode, token: self.token, clientId: clientId, noticePort: self.noticeServer.port)!)
|
|
||||||
}
|
}
|
||||||
case .connected:
|
case .connected:
|
||||||
Task {
|
Task {
|
||||||
@ -119,7 +109,7 @@ struct punchnetApp: App {
|
|||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
func applicationWillFinishLaunching(_ notification: Notification) {
|
||||||
|
UDPNoticeCenterServer.shared.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
||||||
@ -128,6 +118,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
sender.reply(toApplicationShouldTerminate: true)
|
sender.reply(toApplicationShouldTerminate: true)
|
||||||
}
|
}
|
||||||
|
UDPNoticeCenterServer.shared.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
return .terminateLater
|
return .terminateLater
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user