let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewStatusCell.id, for: indexPath) as! TunnelDetailTableViewStatusCell
cell.tunnel = self.tunnel
cell.onSwitchToggled = { [weak self] isOn in
- cell.isSwitchInteractionEnabled = false
guard let s = self else { return }
if (isOn) {
- s.tunnelsManager.startActivation(of: s.tunnel) { error in
- print("Error while activating: \(String(describing: error))")
+ s.tunnelsManager.startActivation(of: s.tunnel) { [weak self] error in
+ if let error = error {
+ switch (error) {
+ case TunnelsManagerError.noEndpoint:
+ self?.showErrorAlert(title: "Endpoint missing", message: "There must be atleast one peer with an endpoint")
+ case TunnelsManagerError.dnsResolutionFailed:
+ self?.showErrorAlert(title: "DNS Failure", message: "One or more endpoint domains could not be resolved")
+ default:
+ self?.showErrorAlert(title: "Internal error", message: "The tunnel could not be activated")
+ }
+ }
}
} else {
s.tunnelsManager.startDeactivation(of: s.tunnel) { error in
guard let s = self, let tunnelsManager = s.tunnelsManager else { return }
if (isOn) {
tunnelsManager.startActivation(of: tunnel) { error in
- print("Error while activating: \(String(describing: error))")
+ if let error = error {
+ switch (error) {
+ case TunnelsManagerError.noEndpoint:
+ self?.showErrorAlert(title: "Endpoint missing", message: "There must be atleast one peer with an endpoint")
+ case TunnelsManagerError.dnsResolutionFailed:
+ self?.showErrorAlert(title: "DNS Failure", message: "One or more endpoint domains could not be resolved")
+ default:
+ self?.showErrorAlert(title: "Internal error", message: "The tunnel could not be activated")
+ }
+ }
}
} else {
tunnelsManager.startDeactivation(of: tunnel) { error in
if let endpoints = dnsResolver.resolveWithoutNetworkRequests() {
guard (endpoints.contains(where: { $0 != nil })) else {
completionHandler(TunnelsManagerError.noEndpoint)
+ status = .inactive
return
}
self.tunnelProvider.loadFromPreferences { [weak self] (error) in
} catch (let error) {
os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)")
completionHandler(error)
+ s.status = .inactive
+ return
}
+ completionHandler(nil)
}
} else {
self.dnsResolver = dnsResolver
try session.startTunnel(options: tunnelOptions)
} catch (let error) {
os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)")
- completionHandler(error)
+ s.status = .inactive
+ return
}
}
}