Remove useless whitespace
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
ecbab37e0e
commit
5971c197bd
|
@ -30,7 +30,7 @@ class WgQuickConfigFileParser {
|
|||
|
||||
var parserState = ParserState.notInASection
|
||||
var attributes = [String: String]()
|
||||
|
||||
|
||||
for (lineIndex, line) in lines.enumerated() {
|
||||
var trimmedLine: String
|
||||
if let commentRange = line.range(of: "#") {
|
||||
|
@ -94,7 +94,7 @@ class WgQuickConfigFileParser {
|
|||
throw ParseError.noInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static func collate(interfaceAttributes attributes: [String: String], name: String) -> InterfaceConfiguration? {
|
||||
// required wg fields
|
||||
guard let privateKeyString = attributes["privatekey"] else { return nil }
|
||||
|
@ -130,7 +130,7 @@ class WgQuickConfigFileParser {
|
|||
}
|
||||
return interface
|
||||
}
|
||||
|
||||
|
||||
private static func collate(peerAttributes attributes: [String: String]) -> PeerConfiguration? {
|
||||
// required wg fields
|
||||
guard let publicKeyString = attributes["publickey"] else { return nil }
|
||||
|
@ -160,5 +160,5 @@ class WgQuickConfigFileParser {
|
|||
}
|
||||
return peer
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import os.log
|
|||
class ErrorPresenter {
|
||||
static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) {
|
||||
guard let sourceVC = sourceVC else { return }
|
||||
|
||||
|
||||
let (title, message) = error.alertText()
|
||||
let okAction = UIAlertAction(title: "OK", style: .default) { _ in
|
||||
onDismissal?()
|
||||
|
@ -20,7 +20,7 @@ class ErrorPresenter {
|
|||
|
||||
static func showErrorAlert(title: String, message: String, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) {
|
||||
guard let sourceVC = sourceVC else { return }
|
||||
|
||||
|
||||
let okAction = UIAlertAction(title: "OK", style: .default) { _ in
|
||||
onDismissal?()
|
||||
}
|
||||
|
|
|
@ -199,13 +199,13 @@ extension TunnelEditTableViewController {
|
|||
return interfaceFieldKeyValueCell(for: tableView, at: indexPath, with: field)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func generateKeyPairCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell {
|
||||
let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.buttonText = field.rawValue
|
||||
cell.onTapped = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
|
||||
self.tunnelViewModel.interfaceData[.privateKey] = Curve25519.generatePrivateKey().base64EncodedString()
|
||||
if let privateKeyRow = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .privateKey),
|
||||
let publicKeyRow = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .publicKey) {
|
||||
|
@ -227,7 +227,7 @@ extension TunnelEditTableViewController {
|
|||
private func interfaceFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell {
|
||||
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.key = field.rawValue
|
||||
|
||||
|
||||
switch field {
|
||||
case .name, .privateKey:
|
||||
cell.placeholderText = "Required"
|
||||
|
@ -260,7 +260,7 @@ extension TunnelEditTableViewController {
|
|||
if field == .privateKey {
|
||||
cell.onValueBeingEdited = { [weak self] value in
|
||||
guard let self = self else { return }
|
||||
|
||||
|
||||
self.tunnelViewModel.interfaceData[.privateKey] = value
|
||||
if let row = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .publicKey) {
|
||||
self.tableView.reloadRows(at: [IndexPath(row: row, section: indexPath.section)], with: .none)
|
||||
|
@ -275,7 +275,7 @@ extension TunnelEditTableViewController {
|
|||
private func peerCell(for tableView: UITableView, at indexPath: IndexPath, with peerData: TunnelViewModel.PeerData) -> UITableViewCell {
|
||||
let peerFieldsToShow = peerData.shouldAllowExcludePrivateIPsControl ? peerFields : peerFields.filter { $0 != .excludePrivateIPs }
|
||||
let field = peerFieldsToShow[indexPath.row]
|
||||
|
||||
|
||||
switch field {
|
||||
case .deletePeer:
|
||||
return deletePeerCell(for: tableView, at: indexPath, peerData: peerData, field: field)
|
||||
|
@ -285,7 +285,7 @@ extension TunnelEditTableViewController {
|
|||
return peerFieldKeyValueCell(for: tableView, at: indexPath, peerData: peerData, field: field)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func deletePeerCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
|
||||
let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.buttonText = field.rawValue
|
||||
|
@ -304,14 +304,14 @@ extension TunnelEditTableViewController {
|
|||
let rowIndexPath = IndexPath(row: row, section: self.interfaceFieldsBySection.count /* First peer section */)
|
||||
self.tableView.insertRows(at: [rowIndexPath], with: .fade)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
|
||||
private func excludePrivateIPsCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
|
||||
let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.message = field.rawValue
|
||||
|
@ -326,7 +326,7 @@ extension TunnelEditTableViewController {
|
|||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
|
||||
private func peerFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
|
||||
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.key = field.rawValue
|
||||
|
@ -350,11 +350,11 @@ extension TunnelEditTableViewController {
|
|||
|
||||
cell.isValueValid = !peerData.fieldsWithError.contains(field)
|
||||
cell.value = peerData[field]
|
||||
|
||||
|
||||
if field == .allowedIPs {
|
||||
cell.onValueBeingEdited = { [weak self, weak peerData] value in
|
||||
guard let self = self, let peerData = peerData else { return }
|
||||
|
||||
|
||||
let oldValue = peerData.shouldAllowExcludePrivateIPsControl
|
||||
peerData[.allowedIPs] = value
|
||||
if oldValue != peerData.shouldAllowExcludePrivateIPsControl {
|
||||
|
@ -372,7 +372,7 @@ extension TunnelEditTableViewController {
|
|||
peerData?[field] = value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
|
@ -476,7 +476,7 @@ extension TunnelEditTableViewController {
|
|||
let option = activateOnDemandOptions[indexPath.row - 1]
|
||||
assert(option != .none)
|
||||
activateOnDemandSetting.activateOnDemandOption = option
|
||||
|
||||
|
||||
let indexPaths = (1 ..< 4).map { IndexPath(row: $0, section: indexPath.section) }
|
||||
UIView.performWithoutAnimation {
|
||||
tableView.reloadRows(at: indexPaths, with: .none)
|
||||
|
|
|
@ -13,7 +13,7 @@ extension UITableView {
|
|||
func register<T: UITableViewCell>(_: T.Type) {
|
||||
register(T.self, forCellReuseIdentifier: T.reuseIdentifier)
|
||||
}
|
||||
|
||||
|
||||
func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T {
|
||||
//swiftlint:disable:next force_cast
|
||||
return dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T
|
||||
|
|
|
@ -268,16 +268,16 @@ class TunnelsManager {
|
|||
|
||||
private func startObservingTunnelStatuses() {
|
||||
guard statusObservationToken == nil else { return }
|
||||
|
||||
|
||||
statusObservationToken = NotificationCenter.default.addObserver(forName: .NEVPNStatusDidChange, object: nil, queue: OperationQueue.main) { [weak self] statusChangeNotification in
|
||||
guard let self = self else { return }
|
||||
guard let session = statusChangeNotification.object as? NETunnelProviderSession else { return }
|
||||
guard let tunnelProvider = session.manager as? NETunnelProviderManager else { return }
|
||||
guard let tunnel = self.tunnels.first(where: { $0.tunnelProvider == tunnelProvider }) else { return }
|
||||
|
||||
|
||||
os_log("Tunnel '%{public}@' connection status changed to '%{public}@'",
|
||||
log: OSLog.default, type: .debug, tunnel.name, "\(tunnel.tunnelProvider.connection.status)")
|
||||
|
||||
|
||||
// In case our attempt to start the tunnel, didn't succeed
|
||||
if tunnel == self.tunnelBeingActivated {
|
||||
if session.status == .disconnected {
|
||||
|
@ -290,7 +290,7 @@ class TunnelsManager {
|
|||
self.tunnelBeingActivated = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// In case we're restarting the tunnel
|
||||
if (tunnel.status == .restarting) && (session.status == .disconnected || session.status == .disconnecting) {
|
||||
// Don't change tunnel.status when disconnecting for a restart
|
||||
|
@ -300,7 +300,7 @@ class TunnelsManager {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
tunnel.refreshStatus()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,12 +80,12 @@ class PacketTunnelSettingsGenerator {
|
|||
}
|
||||
|
||||
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress)
|
||||
|
||||
|
||||
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation() }
|
||||
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
|
||||
dnsSettings.matchDomains = [""] // All DNS queries must first go through the VPN's DNS
|
||||
networkSettings.dnsSettings = dnsSettings
|
||||
|
||||
|
||||
let mtu = tunnelConfiguration.interface.mtu ?? 0
|
||||
if mtu == 0 {
|
||||
// 0 imples automatic MTU, where we set overhead as 80 bytes, which is the worst case for WireGuard
|
||||
|
@ -93,16 +93,16 @@ class PacketTunnelSettingsGenerator {
|
|||
} else {
|
||||
networkSettings.mtu = NSNumber(value: mtu)
|
||||
}
|
||||
|
||||
|
||||
let (ipv4Routes, ipv6Routes) = routes()
|
||||
let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes()
|
||||
let (ipv4ExcludedRoutes, ipv6ExcludedRoutes) = excludedRoutes()
|
||||
|
||||
|
||||
let ipv4Settings = NEIPv4Settings(addresses: ipv4Routes.map { $0.destinationAddress }, subnetMasks: ipv4Routes.map { $0.destinationSubnetMask })
|
||||
ipv4Settings.includedRoutes = ipv4IncludedRoutes
|
||||
ipv4Settings.excludedRoutes = ipv4ExcludedRoutes
|
||||
networkSettings.ipv4Settings = ipv4Settings
|
||||
|
||||
|
||||
let ipv6Settings = NEIPv6Settings(addresses: ipv6Routes.map { $0.destinationAddress }, networkPrefixLengths: ipv6Routes.map { $0.destinationNetworkPrefixLength })
|
||||
ipv6Settings.includedRoutes = ipv6IncludedRoutes
|
||||
ipv6Settings.excludedRoutes = ipv6ExcludedRoutes
|
||||
|
@ -122,7 +122,7 @@ class PacketTunnelSettingsGenerator {
|
|||
octets[3] = UInt8(truncatingIfNeeded: subnetMask)
|
||||
return octets.map { String($0) }.joined(separator: ".")
|
||||
}
|
||||
|
||||
|
||||
private func routes() -> ([NEIPv4Route], [NEIPv6Route]) {
|
||||
var ipv4Routes = [NEIPv4Route]()
|
||||
var ipv6Routes = [NEIPv6Route]()
|
||||
|
@ -140,7 +140,7 @@ class PacketTunnelSettingsGenerator {
|
|||
}
|
||||
return (ipv4Routes, ipv6Routes)
|
||||
}
|
||||
|
||||
|
||||
private func includedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) {
|
||||
var ipv4IncludedRoutes = [NEIPv4Route]()
|
||||
var ipv6IncludedRoutes = [NEIPv6Route]()
|
||||
|
@ -155,7 +155,7 @@ class PacketTunnelSettingsGenerator {
|
|||
}
|
||||
return (ipv4IncludedRoutes, ipv6IncludedRoutes)
|
||||
}
|
||||
|
||||
|
||||
private func excludedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) {
|
||||
var ipv4ExcludedRoutes = [NEIPv4Route]()
|
||||
var ipv6ExcludedRoutes = [NEIPv6Route]()
|
||||
|
@ -172,7 +172,7 @@ class PacketTunnelSettingsGenerator {
|
|||
}
|
||||
return (ipv4ExcludedRoutes, ipv6ExcludedRoutes)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
|
|
Loading…
Reference in New Issue