Fix for Codacy: variable name should be between 3 and 40 characters long (#608)
Tiny fixes for iOS
This commit is contained in:
parent
e402cacc05
commit
9c4ee4014d
2 changed files with 29 additions and 27 deletions
|
@ -175,7 +175,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let wgConfigStr = try? JSONDecoder().decode(WGConfig.self, from: wgConfig).wg,
|
guard let wgConfigStr = try? JSONDecoder().decode(WGConfig.self, from: wgConfig).str,
|
||||||
let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: wgConfigStr)
|
let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: wgConfigStr)
|
||||||
else {
|
else {
|
||||||
wg_log(.error, message: "Can't parse WireGuard config")
|
wg_log(.error, message: "Can't parse WireGuard config")
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct WGConfigData: Decodable {
|
struct WGConfigData: Decodable {
|
||||||
let h1, h2, h3, h4: String?
|
let initPacketMagicHeader, responsePacketMagicHeader: String?
|
||||||
let jc, jmax, jmin: String?
|
let underloadPacketMagicHeader, transportPacketMagicHeader: String?
|
||||||
let s1, s2: String?
|
let junkPacketCount, junkPacketMinSize, junkPacketMaxSize: String?
|
||||||
|
let initPacketJunkSize, responsePacketJunkSize: String?
|
||||||
|
|
||||||
var settings: String {
|
var settings: String {
|
||||||
jc == nil ? "" :
|
junkPacketCount == nil ? "" :
|
||||||
"""
|
"""
|
||||||
Jc = \(jc!)
|
Jc = \(junkPacketCount!)
|
||||||
Jmin = \(jmin!)
|
Jmin = \(junkPacketMinSize!)
|
||||||
Jmax = \(jmax!)
|
Jmax = \(junkPacketMaxSize!)
|
||||||
S1 = \(s1!)
|
S1 = \(initPacketJunkSize!)
|
||||||
S2 = \(s2!)
|
S2 = \(responsePacketJunkSize!)
|
||||||
H1 = \(h1!)
|
H1 = \(initPacketMagicHeader!)
|
||||||
H2 = \(h2!)
|
H2 = \(responsePacketMagicHeader!)
|
||||||
H3 = \(h3!)
|
H3 = \(underloadPacketMagicHeader!)
|
||||||
H4 = \(h4!)
|
H4 = \(transportPacketMagicHeader!)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
@ -33,9 +34,10 @@ struct WGConfigData: Decodable {
|
||||||
var persistentKeepAlive: String
|
var persistentKeepAlive: String
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case h1 = "H1", h2 = "H2", h3 = "H3", h4 = "H4"
|
case initPacketMagicHeader = "H1", responsePacketMagicHeader = "H2"
|
||||||
case jc = "Jc", jmax = "Jmax", jmin = "Jmin"
|
case underloadPacketMagicHeader = "H3", transportPacketMagicHeader = "H4"
|
||||||
case s1 = "S1", s2 = "S2"
|
case junkPacketCount = "Jc", junkPacketMinSize = "Jmin", junkPacketMaxSize = "Jmax"
|
||||||
|
case initPacketJunkSize = "S1", responsePacketJunkSize = "S2"
|
||||||
|
|
||||||
case clientIP = "client_ip" // "10.8.1.16"
|
case clientIP = "client_ip" // "10.8.1.16"
|
||||||
case clientPrivateKey = "client_priv_key"
|
case clientPrivateKey = "client_priv_key"
|
||||||
|
@ -51,15 +53,15 @@ struct WGConfigData: Decodable {
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.h1 = try container.decodeIfPresent(String.self, forKey: .h1)
|
self.initPacketMagicHeader = try container.decodeIfPresent(String.self, forKey: .initPacketMagicHeader)
|
||||||
self.h2 = try container.decodeIfPresent(String.self, forKey: .h2)
|
self.responsePacketMagicHeader = try container.decodeIfPresent(String.self, forKey: .responsePacketMagicHeader)
|
||||||
self.h3 = try container.decodeIfPresent(String.self, forKey: .h3)
|
self.underloadPacketMagicHeader = try container.decodeIfPresent(String.self, forKey: .underloadPacketMagicHeader)
|
||||||
self.h4 = try container.decodeIfPresent(String.self, forKey: .h4)
|
self.transportPacketMagicHeader = try container.decodeIfPresent(String.self, forKey: .transportPacketMagicHeader)
|
||||||
self.jc = try container.decodeIfPresent(String.self, forKey: .jc)
|
self.junkPacketCount = try container.decodeIfPresent(String.self, forKey: .junkPacketCount)
|
||||||
self.jmax = try container.decodeIfPresent(String.self, forKey: .jmax)
|
self.junkPacketMinSize = try container.decodeIfPresent(String.self, forKey: .junkPacketMinSize)
|
||||||
self.jmin = try container.decodeIfPresent(String.self, forKey: .jmin)
|
self.junkPacketMaxSize = try container.decodeIfPresent(String.self, forKey: .junkPacketMaxSize)
|
||||||
self.s1 = try container.decodeIfPresent(String.self, forKey: .s1)
|
self.initPacketJunkSize = try container.decodeIfPresent(String.self, forKey: .initPacketJunkSize)
|
||||||
self.s2 = try container.decodeIfPresent(String.self, forKey: .s2)
|
self.responsePacketJunkSize = try container.decodeIfPresent(String.self, forKey: .responsePacketJunkSize)
|
||||||
self.clientIP = try container.decode(String.self, forKey: .clientIP)
|
self.clientIP = try container.decode(String.self, forKey: .clientIP)
|
||||||
self.clientPrivateKey = try container.decode(String.self, forKey: .clientPrivateKey)
|
self.clientPrivateKey = try container.decode(String.self, forKey: .clientPrivateKey)
|
||||||
self.clientPublicKey = try container.decode(String.self, forKey: .clientPublicKey)
|
self.clientPublicKey = try container.decode(String.self, forKey: .clientPublicKey)
|
||||||
|
@ -115,7 +117,7 @@ struct WGConfig: Decodable {
|
||||||
self.splitTunnelType = try container.decode(Int.self, forKey: .splitTunnelType)
|
self.splitTunnelType = try container.decode(Int.self, forKey: .splitTunnelType)
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg: String {
|
var str: String {
|
||||||
"""
|
"""
|
||||||
[Interface]
|
[Interface]
|
||||||
Address = \(data.clientIP)/32
|
Address = \(data.clientIP)/32
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue