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