Commit 25ddece9 authored by Jose Blaya's avatar Jose Blaya

Expiring Token

Refactor
Piaproxy URL updated
parent ff410f4a
......@@ -20,9 +20,25 @@
//
import Foundation
import PIAAccount
public enum DedicatedIPStatus {
case active
case expired
case invalid
case error
init(fromAPIStatus dipStatus: DedicatedIPInformationResponse.Status) {
switch dipStatus {
case .invalid:
self = .invalid
case .expired:
self = .expired
case .error:
self = .error
default:
self = .active
}
}
}
......@@ -23,6 +23,7 @@ import Foundation
import PIAAccount
public enum InAppMessageType {
case none
case action
case view
case link
......@@ -37,7 +38,7 @@ public struct InAppMessage {
public let id: String
public let message: [String: String]
public let linkMessage: [String: String]
public let linkMessage: [String: String]?
public let type: InAppMessageType
public let level: InAppMessageLevel
......@@ -62,29 +63,38 @@ extension InAppMessage {
init(withMessage messageInformation: MessageInformation, andLevel level: InAppMessageLevel) {
self.id = messageInformation.id
self.id = "\(messageInformation.id)"
self.message = messageInformation.message
self.linkMessage = messageInformation.link.text
if !messageInformation.link.action.settings.isEmpty {
self.type = .action
var actions = [String: Bool]()
for setting in messageInformation.link.action.settings {
actions[setting.key] = setting.value.boolValue
if let link = messageInformation.link {
self.linkMessage = link.text
if !link.action.settings.isEmpty {
self.type = .action
var actions = [String: Bool]()
for setting in link.action.settings {
actions[setting.key] = setting.value.boolValue
}
self.settingAction = actions
self.settingLink = nil
self.settingView = nil
} else if !link.action.uri.isEmpty {
self.type = .link
self.settingLink = link.action.uri
self.settingAction = nil
self.settingView = nil
} else {
self.type = .view
self.settingView = link.action.view
self.settingLink = nil
self.settingAction = nil
}
self.settingAction = actions
self.settingLink = nil
self.settingView = nil
} else if !messageInformation.link.action.uri.isEmpty {
self.type = .link
self.settingLink = messageInformation.link.action.uri
self.settingAction = nil
self.settingView = nil
} else {
self.type = .view
self.settingView = messageInformation.link.action.view
self.type = .none
self.linkMessage = nil
self.settingLink = nil
self.settingAction = nil
self.settingView = nil
}
self.level = level
......
......@@ -198,8 +198,9 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
}
webServices.activateDIPToken(tokens: [token]) { (servers, error) in
if let servers = servers,
let first = servers.first {
if !self.currentServers.contains(where: {$0.dipToken == first.dipToken}) {
let first = servers.first,
let status = first.dipStatus {
if !self.currentServers.contains(where: {$0.dipToken == first.dipToken}) && status == .active {
self.currentServers.append(contentsOf: servers)
}
callback?(first, error)
......
......@@ -38,7 +38,7 @@ public struct PinningEndpoint {
public class EndpointManager {
private let internalUrl = "10.0.0.1"
private let proxy = "piaproxy.net"
private let proxy = "www.piaproxy.net"
private let pia = "www.privateinternetaccess.com"
private let region = "serverlist.piaservers.net"
......
......@@ -233,25 +233,30 @@ class PIAWebServices: WebServices, ConfigurationAccess {
var dipRegions = [Server]()
for dipServer in dedicatedIps {
if dipServer.status == DedicatedIPInformationResponse.Status.active {
guard let firstServer = Client.providers.serverProvider.currentServers.first(where: {$0.identifier == dipServer.id}) else {
callback?([], ClientError.malformedResponseData)
return
}
guard let ip = dipServer.ip, let cn = dipServer.cn, let expirationTime = dipServer.dip_expire else {
callback?([], ClientError.malformedResponseData)
return
}
let dipRegion = Server(serial: firstServer.serial, name: firstServer.name, country: firstServer.country, hostname: firstServer.hostname, openVPNAddressesForTCP: [Server.ServerAddressIP(ip: ip, cn: cn)], openVPNAddressesForUDP: [Server.ServerAddressIP(ip: ip, cn: cn)], wireGuardAddressesForUDP: [Server.ServerAddressIP(ip: ip, cn: cn)], iKEv2AddressesForUDP: [Server.ServerAddressIP(ip: ip, cn: cn)], pingAddress: firstServer.pingAddress, geo: false, meta: nil, dipExpire: Date(timeIntervalSince1970: TimeInterval(expirationTime)), dipToken: dipServer.dipToken, dipStatus: DedicatedIPStatus.active, regionIdentifier: firstServer.regionIdentifier)
dipRegions.append(dipRegion)
guard let firstServer = Client.providers.serverProvider.currentServers.first(where: {$0.identifier == dipServer.id}) else {
callback?([], ClientError.malformedResponseData)
return
}
guard let ip = dipServer.ip, let cn = dipServer.cn, let expirationTime = dipServer.dip_expire else {
callback?([], ClientError.malformedResponseData)
return
}
let expiringDate = Date(timeIntervalSince1970: TimeInterval(expirationTime))
let status = DedicatedIPStatus(fromAPIStatus: dipServer.status)
let server = Server.ServerAddressIP(ip: ip, cn: cn)
let dipRegion = Server(serial: firstServer.serial, name: firstServer.name, country: firstServer.country, hostname: firstServer.hostname, openVPNAddressesForTCP: [server], openVPNAddressesForUDP: [server], wireGuardAddressesForUDP: [server], iKEv2AddressesForUDP: [server], pingAddress: firstServer.pingAddress, geo: false, meta: nil, dipExpire: expiringDate, dipToken: dipServer.dipToken, dipStatus: status, regionIdentifier: firstServer.regionIdentifier)
dipRegions.append(dipRegion)
if status == .active {
Client.database.secure.setDIPToken(dipServer.dipToken)
Client.database.secure.setPassword(ip, forDipToken: dipServer.dipToken)
}
}
callback?(dipRegions, nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment