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:
Davide De Rosa 2019-04-11 19:31:21 +02:00
parent e0c8b478bb
commit 8a81ad8f72
5 changed files with 18 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -271,8 +271,8 @@ public class ConnectionService: Codable {
}
// fix renamed pool, fall back to default
if providerProfile.pool == nil {
providerProfile.poolId = providerProfile.infrastructure.defaults.pool
if providerProfile.pool == nil, let fallbackPool = providerProfile.infrastructure.defaultPool() {
providerProfile.poolId = fallbackPool.id
}
profile = providerProfile

View File

@ -40,7 +40,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
}
public var pool: Pool? {
return infrastructure.pool(for: poolId) ?? infrastructure.pool(for: infrastructure.defaults.pool)
return infrastructure.pool(for: poolId)
}
public var presetId: String {
@ -68,7 +68,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
username = nil
poolId = infrastructure.defaults.pool
poolId = infrastructure.defaultPool()?.id ?? infrastructure.defaults.pool
presetId = infrastructure.defaults.preset
}

View File

@ -64,10 +64,18 @@ public struct Infrastructure: Codable {
return try JSONDecoder().decode(Infrastructure.self, from: json)
}
public func defaultPool() -> Pool? {
return pool(withPrefix: defaults.pool)
}
public func pool(for identifier: String) -> Pool? {
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? {
return presets.first { $0.id == identifier }
}

View File

@ -77,9 +77,12 @@ public struct Pool: Codable, Hashable, CustomStringConvertible {
public let hostname: String?
public let numericAddresses: [UInt32]
public let numericAddresses: [UInt32]?
public func hasAddress(_ address: String) -> Bool {
guard let numericAddresses = numericAddresses else {
return false
}
guard let ipv4 = DNSResolver.ipv4(fromString: address) else {
return false
}
@ -88,7 +91,7 @@ public struct Pool: Codable, Hashable, CustomStringConvertible {
// XXX: inefficient, can't easily use lazy on struct
public func addresses() -> [String] {
var addrs = numericAddresses.map { DNSResolver.string(fromIPv4: $0) }
var addrs = numericAddresses?.map { DNSResolver.string(fromIPv4: $0) } ?? []
if let hostname = hostname {
addrs.insert(hostname, at: 0)
}