aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-05 15:24:08 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-05 15:29:28 +0530
commit3afcee04bef286c486cac28fee23b727a6fb1af8 (patch)
tree2adcd667f3d88f6b1d9106a626868cc52595c538 /WireGuard
parentImporting: Simplify TunnelImporter (diff)
downloadwireguard-apple-3afcee04bef286c486cac28fee23b727a6fb1af8.tar.xz
wireguard-apple-3afcee04bef286c486cac28fee23b727a6fb1af8.zip
TunnelsManager: addMultiple() should also return the last error
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift12
-rw-r--r--WireGuard/WireGuard/UI/TunnelImporter.swift2
2 files changed, 8 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index e05bea9d..a94d63d7 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -148,19 +148,21 @@ class TunnelsManager {
}
}
- func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt) -> Void) {
- addMultiple(tunnelConfigurations: ArraySlice(tunnelConfigurations), numberSuccessful: 0, completionHandler: completionHandler)
+ func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt, TunnelsManagerError?) -> Void) {
+ addMultiple(tunnelConfigurations: ArraySlice(tunnelConfigurations), numberSuccessful: 0, lastError: nil, completionHandler: completionHandler)
}
- private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, completionHandler: @escaping (UInt) -> Void) {
+ private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, lastError: TunnelsManagerError?, completionHandler: @escaping (UInt, TunnelsManagerError?) -> Void) {
guard let head = tunnelConfigurations.first else {
- completionHandler(numberSuccessful)
+ completionHandler(numberSuccessful, lastError)
return
}
let tail = tunnelConfigurations.dropFirst()
add(tunnelConfiguration: head) { [weak self, tail] result in
DispatchQueue.main.async {
- self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (result.isSuccess ? 1 : 0), completionHandler: completionHandler)
+ let numberSuccessful = numberSuccessful + (result.isSuccess ? 1 : 0)
+ let lastError = lastError ?? (result.error as? TunnelsManagerError)
+ self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful, lastError: lastError, completionHandler: completionHandler)
}
}
}
diff --git a/WireGuard/WireGuard/UI/TunnelImporter.swift b/WireGuard/WireGuard/UI/TunnelImporter.swift
index 4fabd07b..a306a7e0 100644
--- a/WireGuard/WireGuard/UI/TunnelImporter.swift
+++ b/WireGuard/WireGuard/UI/TunnelImporter.swift
@@ -56,7 +56,7 @@ class TunnelImporter {
}
}
dispatchGroup.notify(queue: .main) {
- tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { numberSuccessful in
+ tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { numberSuccessful, _ in
if !configs.isEmpty && numberSuccessful == configs.count {
completionHandler?()
return