Commit 7d6a0aa1 authored by Jose Blaya's avatar Jose Blaya
Browse files

Legacy servers not available anymore

parent 1283aad4
......@@ -298,7 +298,6 @@
DD76292921ECDFF80092DF50 /* Usage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292721ECDFF80092DF50 /* Usage.swift */; };
DD76292E21ECEC3F0092DF50 /* DataManipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */; };
DD76292F21ECEC3F0092DF50 /* DataManipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */; };
DD7AD3E12462EC7E00CDCE0F /* ServerNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD7AD3E02462EC7E00CDCE0F /* ServerNetwork.swift */; };
DD86BAF121EF5B6D004A988F /* UIViewAutolayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD86BAF021EF5B6D004A988F /* UIViewAutolayout.swift */; };
DD8BF3CB219C6BAA0041357C /* ConfirmVPNPlanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8BF3CA219C6BAA0041357C /* ConfirmVPNPlanViewController.swift */; };
DD8C3E612327EF4C00BAD18E /* IKEv2IntegrityAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8C3E602327EF4C00BAD18E /* IKEv2IntegrityAlgorithm.swift */; };
......@@ -606,7 +605,6 @@
DD7411A823EC35B40058CEF3 /* PIAWGTunnelProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAWGTunnelProfile.swift; sourceTree = "<group>"; };
DD76292721ECDFF80092DF50 /* Usage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Usage.swift; sourceTree = "<group>"; };
DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataManipulation.swift; sourceTree = "<group>"; };
DD7AD3E02462EC7E00CDCE0F /* ServerNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerNetwork.swift; sourceTree = "<group>"; };
DD86BAF021EF5B6D004A988F /* UIViewAutolayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewAutolayout.swift; sourceTree = "<group>"; };
DD8BF3CA219C6BAA0041357C /* ConfirmVPNPlanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmVPNPlanViewController.swift; sourceTree = "<group>"; };
DD8C3E602327EF4C00BAD18E /* IKEv2IntegrityAlgorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IKEv2IntegrityAlgorithm.swift; sourceTree = "<group>"; };
......@@ -837,7 +835,6 @@
isa = PBXGroup;
children = (
0E9D62D91FDEE3FE009A90CF /* ServerProvider.swift */,
DD7AD3E02462EC7E00CDCE0F /* ServerNetwork.swift */,
);
path = Server;
sourceTree = "<group>";
......@@ -1934,7 +1931,6 @@
0E38E4101FF81722008223AB /* Notification+UI.swift in Sources */,
0E392DA91FE329AD0002160D /* PlatformVPNLog.swift in Sources */,
0EB8C0481F9CCE07005857E4 /* Macros.swift in Sources */,
DD7AD3E12462EC7E00CDCE0F /* ServerNetwork.swift in Sources */,
84577FC3213D9AEA006DEC3D /* UITextField+PlaceholderColor.swift in Sources */,
0EFEB4C12007784A00F81029 /* PIATunnelProvider+Profile.swift in Sources */,
DD8C3E612327EF4C00BAD18E /* IKEv2IntegrityAlgorithm.swift in Sources */,
......
......@@ -41,9 +41,7 @@ protocol PlainStore: class {
var cachedServers: [Server] { get set }
var preferredServer: Server? { get set }
var serverNetwork: ServersNetwork { get set }
func ping(forServerIdentifier serverIdentifier: String) -> Int?
func setPing(_ ping: Int, forServerIdentifier serverIdentifier: String)
......
//
// ServerNetwork.swift
// PIALibrary
//
// Created by Jose Antonio Blaya Garcia on 06/05/2020.
// Copyright © 2020 Private Internet Access, Inc.
//
// This file is part of the Private Internet Access iOS Client.
//
// The Private Internet Access iOS Client is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// The Private Internet Access iOS Client is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with the Private
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
//
import Foundation
public enum ServersNetwork: String {
case legacy
case gen4
}
......@@ -134,9 +134,7 @@ public class Server: Hashable {
/// The best server IPs for establishing an IKEv2 connection over UDP.
public let iKEv2AddressesForUDP: [ServerAddressIP]?
public let serverNetwork: ServersNetwork?
/// The address on which to "ping" the server.
///
/// - Seealso: `Macros.ping(...)`
......@@ -167,7 +165,6 @@ public class Server: Hashable {
iKEv2AddressesForUDP: [ServerAddressIP]? = nil,
pingAddress: Address?,
responseTime: Int? = 0,
serverNetwork: ServersNetwork? = .legacy,
geo: Bool = false,
meta: ServerAddressIP? = nil,
dipExpire: Date? = nil,
......@@ -192,7 +189,6 @@ public class Server: Hashable {
self.meta = meta
self.pingAddress = pingAddress
self.serverNetwork = serverNetwork
self.dipExpire = dipExpire
self.dipToken = dipToken
......@@ -218,8 +214,7 @@ public class Server: Hashable {
extension Server {
func bestAddressForOpenVPNTCP() -> Address? {
if Client.configuration.serverNetwork == .gen4,
let addresses = openVPNAddressesForTCP {
if let addresses = openVPNAddressesForTCP {
let sorted = addresses.sorted(by: { $0.responseTime ?? 0 > $1.responseTime ?? 0 })
return nil
}
......@@ -229,8 +224,7 @@ extension Server {
}
func bestAddressForOpenVPNUDP() -> Address? {
if Client.configuration.serverNetwork == .gen4,
let addresses = openVPNAddressesForUDP {
if let addresses = openVPNAddressesForUDP {
let sorted = addresses.sorted(by: { $0.responseTime ?? 0 > $1.responseTime ?? 0 })
return nil
}
......@@ -241,8 +235,7 @@ extension Server {
func bestAddressForIKEv2() -> ServerAddressIP? {
if Client.configuration.serverNetwork == .gen4,
let addresses = iKEv2AddressesForUDP {
if let addresses = iKEv2AddressesForUDP {
let sorted = addresses.sorted(by: { $0.responseTime ?? 0 > $1.responseTime ?? 0 })
return sorted.first
}
......@@ -251,8 +244,7 @@ extension Server {
}
func bestAddressForWireGuard() -> ServerAddressIP? {
if Client.configuration.serverNetwork == .gen4,
let addresses = wireGuardAddressesForUDP {
if let addresses = wireGuardAddressesForUDP {
let sorted = addresses.sorted(by: { $0.responseTime ?? 0 > $1.responseTime ?? 0 })
return sorted.first
}
......@@ -262,35 +254,28 @@ extension Server {
func bestPingAddress() -> [Address] {
if Client.configuration.serverNetwork == .gen4 {
switch Client.providers.vpnProvider.currentVPNType {
case IKEv2Profile.vpnType:
var addresses: [Address] = []
for address in iKEv2AddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
return addresses
case PIATunnelProfile.vpnType:
var addresses: [Address] = []
for address in openVPNAddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
return addresses
case PIAWGTunnelProfile.vpnType:
var addresses: [Address] = []
for address in wireGuardAddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
return addresses
default:
return []
switch Client.providers.vpnProvider.currentVPNType {
case IKEv2Profile.vpnType:
var addresses: [Address] = []
for address in iKEv2AddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
} else if let pingAddress = pingAddress {
return [pingAddress]
} else {
return addresses
case PIATunnelProfile.vpnType:
var addresses: [Address] = []
for address in openVPNAddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
return addresses
case PIAWGTunnelProfile.vpnType:
var addresses: [Address] = []
for address in wireGuardAddressesForUDP ?? [] {
addresses.append(Address(hostname: address.ip, port: 0))
}
return addresses
default:
return []
}
}
......
......@@ -144,9 +144,6 @@ extension Client {
/// Store the account password in memory when the email is set and the user is LoggedIn.
public var tempAccountPassword: String
/// The server network to use.
private(set) var serverNetwork: ServersNetwork
// MARK: Initialization
init() {
......@@ -218,7 +215,6 @@ extension Client {
maxQuickConnectServers = 6
tempAccountPassword = ""
serverNetwork = Client.database.plain.serverNetwork
}
......@@ -307,15 +303,6 @@ extension Client {
#endif
public func setServerNetworks(to serverNetwork: ServersNetwork) {
self.serverNetwork = serverNetwork
Client.database.plain.serverNetwork = serverNetwork
}
public func currentServerNetwork() -> ServersNetwork {
return Client.database.plain.serverNetwork
}
// public init(name: String) {
// guard let path = Bundle.main.path(forResource: name, ofType: "plist") else {
// fatalError("Unable to read configuration from \(name).plist")
......
......@@ -54,50 +54,27 @@ class PingTask {
let persistence = Client.database.plain
self.state = .pending
if Client.configuration.serverNetwork == .gen4 {
log.debug("Starting to Ping \(server.identifier) with address: \(address.hostname)")
queue.async() { [weak self] in
guard let address = self?.address, let server = self?.server else {
return
}
let tcpAddress = Server.Address(hostname: address.hostname, port: 443)
response = server.ping(toAddress: tcpAddress, withProtocol: .TCP)
DispatchQueue.main.async {
self?.parsePingResponse(response: response, withServer: server)
if let responseTime = response {
server.updateResponseTime(responseTime, forAddress: address)
persistence.setPing(responseTime, forServerIdentifier: server.identifier)
}
self?.state = .completed
}
log.debug("Starting to Ping \(server.identifier) with address: \(address.hostname)")
queue.async() { [weak self] in
guard let address = self?.address, let server = self?.server else {
return
}
} else {
queue.async() { [weak self] in
guard let address = self?.address, let server = self?.server else {
return
}
response = server.ping(toAddress: address, withProtocol: .UDP)
DispatchQueue.main.async {
self?.parsePingResponse(response: response, withServer: server)
if let responseTime = response {
server.updateResponseTime(responseTime, forAddress: address)
persistence.setPing(responseTime, forServerIdentifier: server.identifier)
}
self?.state = .completed
let tcpAddress = Server.Address(hostname: address.hostname, port: 443)
response = server.ping(toAddress: tcpAddress, withProtocol: .TCP)
DispatchQueue.main.async {
self?.parsePingResponse(response: response, withServer: server)
if let responseTime = response {
server.updateResponseTime(responseTime, forAddress: address)
persistence.setPing(responseTime, forServerIdentifier: server.identifier)
}
self?.state = .completed
}
}
}
private func parsePingResponse(response: Int?, withServer server: Server) {
......
......@@ -171,15 +171,7 @@ class ServersDaemon: Daemon, ConfigurationAccess, DatabaseAccess, ProvidersAcces
@objc private func applicationDidBecomeActive(notification: Notification) {
if hasEnabledUpdates {
let currentServers = accessedProviders.serverProvider.currentServers
if let serverNetwork = currentServers.first?.serverNetwork, serverNetwork != Client.configuration.serverNetwork {
Client.providers.serverProvider.resetCurrentServers()
if let data = Client.configuration.bundledServersJSON {
Client.providers.serverProvider.loadLocalJSON(fromJSON: data)
}
pingIfOffline(servers: accessedProviders.serverProvider.currentServers)
} else {
pingIfOffline(servers: currentServers)
}
pingIfOffline(servers: currentServers)
}
}
......
......@@ -318,16 +318,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
}
}
var serverNetwork: ServersNetwork {
get {
let network = backend.string(forKey: Entries.serverNetwork)
return ServersNetwork(rawValue: network ?? "") ?? ServersNetwork.gen4
}
set {
backend.set(newValue.rawValue, forKey: Entries.serverNetwork)
}
}
func ping(forServerIdentifier serverIdentifier: String) -> Int? {
return pingByServerIdentifier[serverIdentifier]
}
......
......@@ -79,8 +79,7 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
// guard (avg < bestResponseTime) else {
// continue
// }
let servers = currentServers.filter { $0.serverNetwork == Client.configuration.currentServerNetwork() }
for server in servers {
for server in currentServers {
guard let responseTime = accessedDatabase.plain.ping(forServerIdentifier: server.identifier) else {
continue
}
......@@ -127,7 +126,7 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
public var regionStaticData: RegionData!
func loadLocalJSON(fromJSON jsonData: Data) {
guard let bundle = GlossServersBundle(jsonData: jsonData, forServerNetwork: .gen4) else {
guard let bundle = GlossServersBundle(jsonData: jsonData) else {
return
}
if let configuration = bundle.parsed.configuration {
......
......@@ -167,21 +167,13 @@ public class IKEv2Profile: NetworkExtensionProfile {
var iKEv2Username = ""
var iKEv2Password: Data?
if Client.configuration.currentServerNetwork() == .gen4 {
if let username = Client.providers.accountProvider.token {
iKEv2Username = username
}
iKEv2Password = ikev2PasswordReference()
} else {
if let username = Client.providers.accountProvider.currentUser?.credentials.username {
iKEv2Username = username
}
iKEv2Password = configuration.passwordReference
if let username = Client.providers.accountProvider.token {
iKEv2Username = username
}
iKEv2Password = ikev2PasswordReference()
let cfg = NEVPNProtocolIKEv2()
if Client.configuration.serverNetwork == .gen4,
let ip = configuration.server.bestAddressForIKEv2()?.ip {
if let ip = configuration.server.bestAddressForIKEv2()?.ip {
cfg.serverAddress = ip
} else {
cfg.serverAddress = configuration.server.hostname
......
......@@ -45,7 +45,7 @@ public class EndpointManager {
public static let shared = EndpointManager()
private func availableMetaEndpoints(_ availableEndpoints: inout [PinningEndpoint]) {
var currentServers = Client.providers.serverProvider.currentServers.filter { $0.serverNetwork == .gen4 }
var currentServers = Client.providers.serverProvider.currentServers
currentServers = currentServers.sorted(by: { $0.pingTime ?? 1000 < $1.pingTime ?? 1000 })
currentServers = currentServers.filter({$0.meta != nil})
......@@ -71,48 +71,33 @@ public class EndpointManager {
}
public func availableRegionEndpoints() -> [PinningEndpoint] {
if Client.configuration.currentServerNetwork() == .gen4 {
if Client.providers.vpnProvider.isVPNConnected {
return [PinningEndpoint(host: internalUrl),
PinningEndpoint(host: region)]
}
var availableEndpoints = [PinningEndpoint]()
availableMetaEndpoints(&availableEndpoints)
availableEndpoints.append(PinningEndpoint(host: region))
return availableEndpoints
} else {
return [PinningEndpoint(host: region)]
if Client.providers.vpnProvider.isVPNConnected {
return [PinningEndpoint(host: internalUrl),
PinningEndpoint(host: region)]
}
var availableEndpoints = [PinningEndpoint]()
availableMetaEndpoints(&availableEndpoints)
availableEndpoints.append(PinningEndpoint(host: region))
return availableEndpoints
}
public func availableEndpoints() -> [PinningEndpoint] {
if Client.configuration.currentServerNetwork() == .gen4 {
if Client.providers.vpnProvider.isVPNConnected {
return [PinningEndpoint(host: internalUrl),
PinningEndpoint(host: pia),
PinningEndpoint(host: proxy, isProxy: true)]
}
var availableEndpoints = [PinningEndpoint]()
availableMetaEndpoints(&availableEndpoints)
availableEndpoints.append(PinningEndpoint(host: pia))
availableEndpoints.append(PinningEndpoint(host: proxy, isProxy: true))
return availableEndpoints
} else {
return [PinningEndpoint(host: pia),
if Client.providers.vpnProvider.isVPNConnected {
return [PinningEndpoint(host: internalUrl),
PinningEndpoint(host: pia),
PinningEndpoint(host: proxy, isProxy: true)]
}
var availableEndpoints = [PinningEndpoint]()
availableMetaEndpoints(&availableEndpoints)
availableEndpoints.append(PinningEndpoint(host: pia))
availableEndpoints.append(PinningEndpoint(host: proxy, isProxy: true))
return availableEndpoints
}
}
......@@ -43,149 +43,95 @@ class GlossServer: GlossParser {
let geo: Bool = "geo" <~~ json ?? false
var internalServerNetwork: ServersNetwork?
if let serverNetwork: String = "internal_server_network" <~~ json { //We need this tmp key when storing the server in userdefault as json
internalServerNetwork = ServersNetwork(rawValue: serverNetwork)
}
if Client.configuration.serverNetwork == .gen4 {
var meta: Server.ServerAddressIP?
if let metaServer: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "meta" <~~ metaServer {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
meta = Server.ServerAddressIP(ip: ip, cn: cn)
}
var meta: Server.ServerAddressIP?
if let metaServer: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "meta" <~~ metaServer {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
meta = Server.ServerAddressIP(ip: ip, cn: cn)
}
}
}
}
guard let regionIdentifier: String = "id" <~~ json else {
return nil
}
var ovpnTCPServerAddressIP: [Server.ServerAddressIP] = []
if let ovpnTCP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "ovpntcp" <~~ ovpnTCP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
ovpnTCPServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
guard let regionIdentifier: String = "id" <~~ json else {
return nil
}
var ovpnTCPServerAddressIP: [Server.ServerAddressIP] = []
if let ovpnTCP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "ovpntcp" <~~ ovpnTCP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
ovpnTCPServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
}
var ovpnUDPServerAddressIP: [Server.ServerAddressIP] = []
if let ovpnUDP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "ovpnudp" <~~ ovpnUDP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
ovpnUDPServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
var ovpnUDPServerAddressIP: [Server.ServerAddressIP] = []
if let ovpnUDP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "ovpnudp" <~~ ovpnUDP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
ovpnUDPServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
}
var wgServerAddressIP: [Server.ServerAddressIP] = []
if let wgUDP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "wg" <~~ wgUDP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
wgServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
var wgServerAddressIP: [Server.ServerAddressIP] = []
if let wgUDP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "wg" <~~ wgUDP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
wgServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
}
var ikev2ServerAddressIP: [Server.ServerAddressIP] = []
if let ikev2UDP: [String: Any] = "servers" <~~ json {
if let addressArray: [JSON] = "ikev2" <~~ ikev2UDP {
for address in addressArray {
if let ip: String = "ip" <~~ address,
let cn: String = "cn" <~~ address {
ikev2ServerAddressIP.append(Server.ServerAddressIP(ip: ip, cn: cn))
}
}
var ikev2ServerAddressIP: [Server.ServerAddressIP] = []
if let ikev2UDP: [String: Any] = "servers" <~~ json {