Commit a6265e68 authored by Jose Blaya's avatar Jose Blaya

Add `offline` attribute to Server

parent 0954dd6d
......@@ -117,6 +117,9 @@ public class Server: Hashable {
/// The server is virtually located.
public let geo: Bool
/// The server is unavailable.
public let offline: Bool
/// The best address for establishing an OpenVPN connection over TCP.
public let bestOpenVPNAddressForTCP: Address?
......@@ -166,6 +169,7 @@ public class Server: Hashable {
pingAddress: Address?,
responseTime: Int? = 0,
geo: Bool = false,
offline: Bool = false,
meta: ServerAddressIP? = nil,
dipExpire: Date? = nil,
dipToken: String? = nil,
......@@ -177,6 +181,7 @@ public class Server: Hashable {
self.country = country
self.hostname = hostname
self.geo = geo
self.offline = offline
self.regionIdentifier = regionIdentifier
identifier = hostname.components(separatedBy: ".").first ?? ""
......
......@@ -42,6 +42,7 @@ class GlossServer: GlossParser {
let dipToken: String? = "dipToken" <~~ json ?? nil
let geo: Bool = "geo" <~~ json ?? false
let offline: Bool = "offline" <~~ json ?? false
var meta: Server.ServerAddressIP?
if let metaServer: [String: Any] = "servers" <~~ json {
......@@ -125,6 +126,7 @@ class GlossServer: GlossParser {
pingAddress: pingAddress,
responseTime: 0,
geo: geo,
offline: offline,
meta: meta,
dipToken: dipToken,
regionIdentifier: regionIdentifier
......@@ -158,6 +160,7 @@ extension Server: JSONEncodable {
"name" ~~> name,
"country" ~~> country,
"geo" ~~> geo,
"offline" ~~> offline,
"dns" ~~> hostname,
"openvpn_tcp" ~~> jsonify([
"best" ~~> bestOpenVPNAddressForTCP?.description
......
......@@ -75,6 +75,18 @@ public class MockServerProvider: ServerProvider, DatabaseAccess, WebServicesCons
pingAddress: nil,
responseTime: 0,
regionIdentifier: ""
), Server(
serial: "8a55f03812851897f6e43b2ae22b1234",
name: "US East Offline",
country: "us",
hostname: "us-east.example.com",
bestOpenVPNAddressForTCP: nil,
bestOpenVPNAddressForUDP: nil,
pingAddress: nil,
responseTime: 0,
geo: true,
offline: true,
regionIdentifier: ""
)
]
......
......@@ -62,10 +62,11 @@ class ServerTests: XCTestCase {
func testMockDownload() {
__testProviderDownload(factory: MockProviders())
}
// func testWebDownload() {
// __testProviderDownload(factory: Client.Providers())
// }
func testOfflineServers() {
__testProviderDownload(factory: MockProviders())
XCTAssertTrue(Client.providers.serverProvider.currentServers.filter({$0.offline == true}).count == 1)
}
private func __testProviderDownload(factory: Client.Providers) {
let exp = expectation(description: "download")
......@@ -86,13 +87,4 @@ class ServerTests: XCTestCase {
waitForExpectations(timeout: 5.0, handler: nil)
}
// func testSelection() {
// let cached = Client.providers.serverProvider.currentServers
// guard !cached.isEmpty else {
// return
// }
//
// let selected = cached[Int(arc4random()) % cached.count]
// Client.preferences.editable().preferredServer = selected
// }
}
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