aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuardNetworkExtension
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-12 11:40:57 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-12 11:40:57 -0600
commitde14b76b4d99f74d52b6e404b2ab37394fa5b9dc (patch)
tree0d6e1efbf855bb4995b22e6c55ab8ab2f08e8f24 /WireGuard/WireGuardNetworkExtension
parentZip importing: importFromFile should take a completionHandler (diff)
downloadwireguard-apple-de14b76b4d99f74d52b6e404b2ab37394fa5b9dc.tar.xz
wireguard-apple-de14b76b4d99f74d52b6e404b2ab37394fa5b9dc.zip
Added swiftlint and fixed all errors (and a bunch, but not all, warnings)
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuardNetworkExtension')
-rw-r--r--WireGuard/WireGuardNetworkExtension/DNSResolver.swift6
-rw-r--r--WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift2
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift16
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift18
4 files changed, 21 insertions, 21 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
index 0874fd9..8a9873f 100644
--- a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
+++ b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
@@ -28,13 +28,13 @@ class DNSResolver {
}
var resolvedEndpoints: [Endpoint?] = Array<Endpoint?>(repeating: nil, count: endpoints.count)
- for (i, endpoint) in endpoints.enumerated() {
+ for (index, endpoint) in endpoints.enumerated() {
guard let endpoint = endpoint else { continue }
if (endpoint.hasHostAsIPAddress()) {
- resolvedEndpoints[i] = endpoint
+ resolvedEndpoints[index] = endpoint
} else {
let workItem = DispatchWorkItem {
- resolvedEndpoints[i] = DNSResolver.resolveSync(endpoint: endpoint)
+ resolvedEndpoints[index] = DNSResolver.resolveSync(endpoint: endpoint)
}
DispatchQueue.global(qos: .userInitiated).async(group: dispatchGroup, execute: workItem)
}
diff --git a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
index 4087fe7..4723e79 100644
--- a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
+++ b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
@@ -8,7 +8,7 @@ class ErrorNotifier {
switch (error) {
case .savedProtocolConfigurationIsInvalid:
return ("Activation failure", "Could not retrieve tunnel information from the saved configuration")
- case .dnsResolutionFailure(_):
+ case .dnsResolutionFailure:
return ("DNS resolution failure", "One or more endpoint domains could not be resolved")
case .couldNotStartWireGuard:
return ("Activation failure", "WireGuard backend could not be started")
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index f5f0296..81a9520 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -21,7 +21,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
// MARK: Properties
private var wgHandle: Int32?
-
+
private var networkMonitor: NWPathMonitor?
// MARK: NEPacketTunnelProvider
@@ -29,7 +29,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
deinit {
networkMonitor?.cancel()
}
-
+
/// Begin the process of establishing the tunnel.
override func startTunnel(options: [String: NSObject]?,
completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
@@ -89,9 +89,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
let wireguardSettings = packetTunnelSettingsGenerator.uapiConfiguration()
-
+
var handle: Int32 = -1
-
+
networkMonitor = NWPathMonitor()
networkMonitor?.pathUpdateHandler = { path in
guard handle >= 0 else { return }
@@ -99,18 +99,18 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
wg_log(.debug, message: "Network change detected, re-establishing sockets and IPs: \(path.availableInterfaces)")
let endpointString = packetTunnelSettingsGenerator.endpointUapiConfiguration(currentListenPort: wgGetListenPort(handle))
let err = endpointString.withCString {
- wgSetConfig(handle, gostring_t(p: $0, n: endpointString.utf8.count))
+ wgSetConfig(handle, gostring_t(p: $0, n: endpointString.utf8.count))
}
if err == -EADDRINUSE {
let endpointString = packetTunnelSettingsGenerator.endpointUapiConfiguration(currentListenPort: 0)
_ = endpointString.withCString {
- wgSetConfig(handle, gostring_t(p: $0, n: endpointString.utf8.count))
+ wgSetConfig(handle, gostring_t(p: $0, n: endpointString.utf8.count))
}
}
}
}
networkMonitor?.start(queue: DispatchQueue(label: "NetworkMonitor"))
-
+
handle = connect(interfaceName: tunnelConfiguration.interface.name, settings: wireguardSettings, fd: fd)
if handle < 0 {
@@ -141,7 +141,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
networkMonitor?.cancel()
networkMonitor = nil
-
+
wg_log(.info, staticMessage: "Stopping tunnel")
if let handle = wgHandle {
wgTurnOff(handle)
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
index 61e161e..f6bcdba 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
@@ -18,17 +18,17 @@ class PacketTunnelSettingsGenerator {
func endpointUapiConfiguration(currentListenPort: UInt16) -> String {
var wgSettings = "listen_port=\(tunnelConfiguration.interface.listenPort ?? currentListenPort)\n"
- for (i, peer) in tunnelConfiguration.peers.enumerated() {
+ for (index, peer) in tunnelConfiguration.peers.enumerated() {
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
- if let endpoint = resolvedEndpoints[i] {
+ if let endpoint = resolvedEndpoints[index] {
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
wgSettings.append("endpoint=\(endpoint.stringRepresentation())\n")
}
}
-
+
return wgSettings
}
-
+
func uapiConfiguration() -> String {
var wgSettings = ""
let privateKey = tunnelConfiguration.interface.privateKey.hexEncodedString()
@@ -40,12 +40,12 @@ class PacketTunnelSettingsGenerator {
wgSettings.append("replace_peers=true\n")
}
assert(tunnelConfiguration.peers.count == resolvedEndpoints.count)
- for (i, peer) in tunnelConfiguration.peers.enumerated() {
+ for (index, peer) in tunnelConfiguration.peers.enumerated() {
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
if let preSharedKey = peer.preSharedKey {
wgSettings.append("preshared_key=\(preSharedKey.hexEncodedString())\n")
}
- if let endpoint = resolvedEndpoints[i] {
+ if let endpoint = resolvedEndpoints[index] {
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
wgSettings.append("endpoint=\(endpoint.stringRepresentation())\n")
}
@@ -200,10 +200,10 @@ class PacketTunnelSettingsGenerator {
}
static func ipv4SubnetMaskString(of addressRange: IPAddressRange) -> String {
- let n: UInt8 = addressRange.networkPrefixLength
- assert(n <= 32)
+ let length: UInt8 = addressRange.networkPrefixLength
+ assert(length <= 32)
var octets: [UInt8] = [0, 0, 0, 0]
- let subnetMask: UInt32 = n > 0 ? ~UInt32(0) << (32 - n) : UInt32(0)
+ let subnetMask: UInt32 = length > 0 ? ~UInt32(0) << (32 - length) : UInt32(0)
octets[0] = UInt8(truncatingIfNeeded: subnetMask >> 24)
octets[1] = UInt8(truncatingIfNeeded: subnetMask >> 16)
octets[2] = UInt8(truncatingIfNeeded: subnetMask >> 8)