Commit 4aba475c authored by Jose Blaya's avatar Jose Blaya
Browse files

Fix force wrap crash

parent 1a7cf3b3
//
// EndpointManager.swift
// PIALibrary
//
//
// Created by Jose Blaya on 15/09/2020.
// Copyright © 2020 Private Internet Access, Inc.
//
// This file is part of the Private Internet Access iOS Client.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
......@@ -47,23 +47,32 @@ public class EndpointManager {
private func availableMetaEndpoints(_ availableEndpoints: inout [PinningEndpoint]) {
var currentServers = Client.providers.serverProvider.currentServers
currentServers = currentServers.sorted(by: { $0.pingTime ?? 1000 < $1.pingTime ?? 1000 })
currentServers = currentServers.filter({$0.meta != nil})
if let historicalServer = Client.providers.serverProvider.historicalServers.first(where: {$0.meta != nil}) {
availableEndpoints.append(PinningEndpoint(host: historicalServer.meta!.ip,
if let historicalServer = Client.providers.serverProvider.historicalServers.first,
let meta = historicalServer.meta {
availableEndpoints.append(PinningEndpoint(host: meta.ip,
useCertificatePinning: true,
commonName: historicalServer.meta?.cn))
commonName: meta.cn))
}
if currentServers.count > 2 {
guard !currentServers.filter({$0.meta != nil}).isEmpty else {
return
}
if currentServers[0].pingTime == nil && currentServers[1].pingTime == nil {
while availableEndpoints.count < 2 {
availableEndpoints.append(PinningEndpoint(host: currentServers.randomElement()!.meta!.ip, useCertificatePinning: true, commonName: currentServers.randomElement()?.meta?.cn))
if let random = currentServers.randomElement(), let meta = random.meta {
availableEndpoints.append(PinningEndpoint(host: meta.ip, useCertificatePinning: true, commonName: meta.cn))
}
}
} else {
availableEndpoints.append(PinningEndpoint(host: currentServers[0].meta!.ip, useCertificatePinning: true, commonName: currentServers[0].meta?.cn))
if let meta = currentServers[0].meta {
availableEndpoints.append(PinningEndpoint(host: meta.ip, useCertificatePinning: true, commonName: meta.cn))
}
if availableEndpoints.count < 2 {
availableEndpoints.append(PinningEndpoint(host: currentServers[1].meta!.ip, useCertificatePinning: true, commonName: currentServers[1].meta?.cn))
if let meta = currentServers[1].meta {
availableEndpoints.append(PinningEndpoint(host: meta.ip, useCertificatePinning: true, commonName: meta.cn))
}
}
}
}
......
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