Update NordVPN infrastructure
- Pick default pool by country e.g. "us" rather than "us-123" - Drop overwhelming resolved addresses Required changes: - Assume default pool id to be a prefix - Make Pool addresses optional
This commit is contained in:
parent
e0c8b478bb
commit
8a81ad8f72
File diff suppressed because one or more lines are too long
|
@ -271,8 +271,8 @@ public class ConnectionService: Codable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix renamed pool, fall back to default
|
// fix renamed pool, fall back to default
|
||||||
if providerProfile.pool == nil {
|
if providerProfile.pool == nil, let fallbackPool = providerProfile.infrastructure.defaultPool() {
|
||||||
providerProfile.poolId = providerProfile.infrastructure.defaults.pool
|
providerProfile.poolId = fallbackPool.id
|
||||||
}
|
}
|
||||||
|
|
||||||
profile = providerProfile
|
profile = providerProfile
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var pool: Pool? {
|
public var pool: Pool? {
|
||||||
return infrastructure.pool(for: poolId) ?? infrastructure.pool(for: infrastructure.defaults.pool)
|
return infrastructure.pool(for: poolId)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var presetId: String {
|
public var presetId: String {
|
||||||
|
@ -68,7 +68,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||||
|
|
||||||
username = nil
|
username = nil
|
||||||
|
|
||||||
poolId = infrastructure.defaults.pool
|
poolId = infrastructure.defaultPool()?.id ?? infrastructure.defaults.pool
|
||||||
presetId = infrastructure.defaults.preset
|
presetId = infrastructure.defaults.preset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,18 @@ public struct Infrastructure: Codable {
|
||||||
return try JSONDecoder().decode(Infrastructure.self, from: json)
|
return try JSONDecoder().decode(Infrastructure.self, from: json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func defaultPool() -> Pool? {
|
||||||
|
return pool(withPrefix: defaults.pool)
|
||||||
|
}
|
||||||
|
|
||||||
public func pool(for identifier: String) -> Pool? {
|
public func pool(for identifier: String) -> Pool? {
|
||||||
return pools.first { $0.id == identifier }
|
return pools.first { $0.id == identifier }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func pool(withPrefix prefix: String) -> Pool? {
|
||||||
|
return pools.first { $0.id.hasPrefix(prefix) }
|
||||||
|
}
|
||||||
|
|
||||||
public func preset(for identifier: String) -> InfrastructurePreset? {
|
public func preset(for identifier: String) -> InfrastructurePreset? {
|
||||||
return presets.first { $0.id == identifier }
|
return presets.first { $0.id == identifier }
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,12 @@ public struct Pool: Codable, Hashable, CustomStringConvertible {
|
||||||
|
|
||||||
public let hostname: String?
|
public let hostname: String?
|
||||||
|
|
||||||
public let numericAddresses: [UInt32]
|
public let numericAddresses: [UInt32]?
|
||||||
|
|
||||||
public func hasAddress(_ address: String) -> Bool {
|
public func hasAddress(_ address: String) -> Bool {
|
||||||
|
guard let numericAddresses = numericAddresses else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
guard let ipv4 = DNSResolver.ipv4(fromString: address) else {
|
guard let ipv4 = DNSResolver.ipv4(fromString: address) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -88,7 +91,7 @@ public struct Pool: Codable, Hashable, CustomStringConvertible {
|
||||||
|
|
||||||
// XXX: inefficient, can't easily use lazy on struct
|
// XXX: inefficient, can't easily use lazy on struct
|
||||||
public func addresses() -> [String] {
|
public func addresses() -> [String] {
|
||||||
var addrs = numericAddresses.map { DNSResolver.string(fromIPv4: $0) }
|
var addrs = numericAddresses?.map { DNSResolver.string(fromIPv4: $0) } ?? []
|
||||||
if let hostname = hostname {
|
if let hostname = hostname {
|
||||||
addrs.insert(hostname, at: 0)
|
addrs.insert(hostname, at: 0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue