Commit f09d9933 authored by Davide De Rosa's avatar Davide De Rosa
Browse files

Pick custom servers from dynamic file

parent b68d1a8b
......@@ -12,6 +12,7 @@ before_script:
- bundle update
#- bundle exec fastlane run ensure_git_status_clean
- echo "$PIA_STAGING_ENDPOINT" >"Resources/staging.endpoint"
- echo "$PIA_CUSTOM_SERVERS" >"Resources/custom.servers"
stages:
- test
......
......@@ -23,6 +23,7 @@
0E3A352D1FD9CDC5000B0F99 /* Theme+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3A352B1FD9CDC5000B0F99 /* Theme+App.swift */; };
0E3A35351FD9EBDA000B0F99 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3A35341FD9EBDA000B0F99 /* AppDelegate.swift */; };
0E3A35361FD9EBDA000B0F99 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3A35341FD9EBDA000B0F99 /* AppDelegate.swift */; };
0E3C9A5E20EC004E00B199F9 /* custom.servers in Resources */ = {isa = PBXBuildFile; fileRef = 0E3C9A5D20EC004D00B199F9 /* custom.servers */; };
0E435DA11E748C3900101226 /* PIA VPN Tunnel.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 0E67FC221E3F802D00EF9929 /* PIA VPN Tunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
0E441E262055AEDF007528D5 /* ThemeStrategy+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E441E252055AEDF007528D5 /* ThemeStrategy+App.swift */; };
0E441E272055AEDF007528D5 /* ThemeStrategy+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E441E252055AEDF007528D5 /* ThemeStrategy+App.swift */; };
......@@ -272,6 +273,7 @@
0E3A35271FD9A960000B0F99 /* DashboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardViewController.swift; sourceTree = "<group>"; };
0E3A352B1FD9CDC5000B0F99 /* Theme+App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+App.swift"; sourceTree = "<group>"; };
0E3A35341FD9EBDA000B0F99 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
0E3C9A5D20EC004D00B199F9 /* custom.servers */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = custom.servers; sourceTree = "<group>"; };
0E441E252055AEDF007528D5 /* ThemeStrategy+App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ThemeStrategy+App.swift"; sourceTree = "<group>"; };
0E441E302055B8A7007528D5 /* Theme+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+Extension.swift"; sourceTree = "<group>"; };
0E492C661FE60907007F23DF /* Flags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Flags.swift; sourceTree = "<group>"; };
......@@ -636,6 +638,7 @@
children = (
0ED984161FC48C5100542EE6 /* Fonts */,
0E0786DD1EFA7EAE00F77466 /* Components.plist */,
0E3C9A5D20EC004D00B199F9 /* custom.servers */,
0ED66BCF20A9918000333B35 /* staging.endpoint */,
);
path = Resources;
......@@ -1043,6 +1046,7 @@
0EE220631F4EF307002805AE /* Launch Screen.storyboard in Resources */,
0ED984201FC48C6500542EE6 /* Roboto-Medium.ttf in Resources */,
0ED984211FC48C6500542EE6 /* Roboto-Regular.ttf in Resources */,
0E3C9A5E20EC004E00B199F9 /* custom.servers in Resources */,
0EFDC1D51FE4607D007C0B9B /* Images.xcassets in Resources */,
0ED9841F1FC48C6500542EE6 /* Roboto-Light.ttf in Resources */,
0EE2206A1F4EF307002805AE /* Components.plist in Resources */,
......
......@@ -64,6 +64,48 @@ struct AppConstants {
}()
}
struct Servers {
static var customServers: [Server]? = {
guard let path = Bundle.main.path(forResource: "custom", ofType: "servers") else {
return nil
}
guard let content = try? String(contentsOfFile: path) else {
return nil
}
var servers: [Server] = []
let lines = content.components(separatedBy: "\n")
for line in lines {
let tokens = line.components(separatedBy: ":")
guard tokens.count == 6 else {
continue
}
let name = tokens[0]
let country = tokens[1]
let hostname = tokens[2]
let address = tokens[3]
guard let udpPort = UInt16(tokens[4]) else {
continue
}
guard let tcpPort = UInt16(tokens[5]) else {
continue
}
servers.append(Server(
name: name,
country: country,
hostname: hostname,
bestOpenVPNAddressForTCP: Server.Address(hostname: address, port: tcpPort),
bestOpenVPNAddressForUDP: Server.Address(hostname: address, port: udpPort),
pingAddress: nil
))
}
return servers
}()
}
struct Fonts {
static let typeface: Theme.Typeface = {
let typeface = Theme.Typeface()
......
......@@ -58,6 +58,11 @@ class Bootstrapper {
if let stagingUrl = AppConstants.Web.stagingEndpointURL {
Client.configuration.setBaseURL(stagingUrl.absoluteString, for: .staging)
}
if Client.configuration.isDevelopment, let customServers = AppConstants.Servers.customServers {
for server in customServers {
Client.configuration.addCustomServer(server)
}
}
Client.configuration.enablesConnectivityUpdates = true
Client.configuration.enablesServerUpdates = true
......
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