]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
All models now Equatable
authorEric Kuck <eric@bluelinelabs.com>
Sat, 22 Dec 2018 04:41:54 +0000 (22:41 -0600)
committerEric Kuck <eric@bluelinelabs.com>
Sat, 22 Dec 2018 04:57:17 +0000 (22:57 -0600)
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
.gitignore
WireGuard/Shared/Model/DNSServer.swift
WireGuard/Shared/Model/Endpoint.swift
WireGuard/Shared/Model/IPAddressRange.swift
WireGuard/Shared/Model/InterfaceConfiguration.swift
WireGuard/Shared/Model/PeerConfiguration.swift
WireGuard/Shared/Model/TunnelConfiguration.swift
WireGuard/WireGuard.xcodeproj/project.pbxproj
WireGuard/WireGuard/Tunnel/TunnelsManager.swift
WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift

index d203206225bd3f5db6791c3870ae9bce20496b5f..f7262ca0d8ede421da10d821365cdc2300eb5a59 100644 (file)
@@ -19,6 +19,7 @@ DerivedData
 *.perspectivev3
 !default.perspectivev3
 xcuserdata
+*.xcscheme
 
 ## Other
 *.xccheckout
index 710c656c31a477d3d04b8ee5b17f48184ed506a0..5a509cba6cebcc9187cd4133de7b64f4b8702fe4 100644 (file)
@@ -12,6 +12,12 @@ struct DNSServer {
     }
 }
 
+extension DNSServer: Equatable {
+    static func == (lhs: DNSServer, rhs: DNSServer) -> Bool {
+        return lhs.address.rawValue == rhs.address.rawValue
+    }
+}
+
 extension DNSServer {
     var stringRepresentation: String {
         return "\(address)"
index 03de1318766ad8690f53971a59a16d24136013df..bcc74cf7a3054408d0ca16b0938690c58c203365 100644 (file)
@@ -14,6 +14,19 @@ struct Endpoint {
     }
 }
 
+extension Endpoint: Equatable {
+    static func == (lhs: Endpoint, rhs: Endpoint) -> Bool {
+        return lhs.host == rhs.host && lhs.port == rhs.port
+    }
+}
+
+extension Endpoint: Hashable {
+    func hash(into hasher: inout Hasher) {
+        hasher.combine(host)
+        hasher.combine(port)
+    }
+}
+
 extension Endpoint {
     var stringRepresentation: String {
         switch host {
index 7d3e5ecae487ce3f5c3a5e6deac1d162a2b62101..26dccc34fe5fa4afd8b1db5200c3e2645b650339 100644 (file)
@@ -14,6 +14,19 @@ struct IPAddressRange {
     }
 }
 
+extension IPAddressRange: Equatable {
+    static func == (lhs: IPAddressRange, rhs: IPAddressRange) -> Bool {
+        return lhs.address.rawValue == rhs.address.rawValue && lhs.networkPrefixLength == rhs.networkPrefixLength
+    }
+}
+
+extension IPAddressRange: Hashable {
+    func hash(into hasher: inout Hasher) {
+        hasher.combine(address.rawValue)
+        hasher.combine(networkPrefixLength)
+    }
+}
+
 extension IPAddressRange {
     var stringRepresentation: String {
         return "\(address)/\(networkPrefixLength)"
index ef33907aab286512f1aaf5178f5348f5a6b86004..e28046b4baab2d4217da645533cb97ba1e510d26 100644 (file)
@@ -2,6 +2,7 @@
 // Copyright © 2018 WireGuard LLC. All Rights Reserved.
 
 import Foundation
+import Network
 
 struct InterfaceConfiguration {
     var privateKey: Data
@@ -17,3 +18,16 @@ struct InterfaceConfiguration {
         self.privateKey = privateKey
     }
 }
+
+extension InterfaceConfiguration: Equatable {
+    static func == (lhs: InterfaceConfiguration, rhs: InterfaceConfiguration) -> Bool {
+        let lhsAddresses = lhs.addresses.filter { $0.address is IPv4Address } + lhs.addresses.filter { $0.address is IPv6Address }
+        let rhsAddresses = rhs.addresses.filter { $0.address is IPv4Address } + rhs.addresses.filter { $0.address is IPv6Address }
+
+        return lhs.privateKey == rhs.privateKey &&
+            lhsAddresses == rhsAddresses &&
+            lhs.listenPort == rhs.listenPort &&
+            lhs.mtu == rhs.mtu &&
+            lhs.dns == rhs.dns
+    }
+}
index 2e969e6c39ad55e9af452cc3049ab7d37500d761..a684fa694b4dc9d468be23e48ef34ba92df73c83 100644 (file)
@@ -25,3 +25,24 @@ struct PeerConfiguration {
         }
     }
 }
+
+extension PeerConfiguration: Equatable {
+    static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
+        return lhs.publicKey == rhs.publicKey &&
+            lhs.preSharedKey == rhs.preSharedKey &&
+            Set(lhs.allowedIPs) == Set(rhs.allowedIPs) &&
+            lhs.endpoint == rhs.endpoint &&
+            lhs.persistentKeepAlive == rhs.persistentKeepAlive
+    }
+}
+
+extension PeerConfiguration: Hashable {
+    func hash(into hasher: inout Hasher) {
+        hasher.combine(publicKey)
+        hasher.combine(preSharedKey)
+        hasher.combine(Set(allowedIPs))
+        hasher.combine(endpoint)
+        hasher.combine(persistentKeepAlive)
+
+    }
+}
index bee3c9dca1836089495531782b044ddd2b5cdfd1..532212e5a521366b4cf7b3a6b5ae5b8b6032d87d 100644 (file)
@@ -22,3 +22,11 @@ final class TunnelConfiguration {
         }
     }
 }
+
+extension TunnelConfiguration: Equatable {
+    static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
+        return lhs.name == rhs.name &&
+            lhs.interface == rhs.interface &&
+            Set(lhs.peers) == Set(rhs.peers)
+    }
+}
index 7bdc5e872c688da6ee7f7326f104451f821b3c6d..2ef4bd28913c8a9fed108fb82f1bbf4599f73f5b 100644 (file)
                        isa = PBXNativeTarget;
                        buildConfigurationList = 6FF4AC26211EC472002C96EB /* Build configuration list for PBXNativeTarget "WireGuard" */;
                        buildPhases = (
+                               5F784E5721CDF6DD00B8D9A0 /* Strip Trailing Whitespace */,
                                5F45417A21C0902400994C13 /* Swiftlint */,
                                6B87860E2189532500C099FB /* Extract wireguard-go Version */,
                                6FF4AC10211EC46F002C96EB /* Sources */,
                        shellPath = /bin/sh;
                        shellScript = "if which swiftlint >/dev/null; then\n    swiftlint\nelse\n    echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
                };
+               5F784E5721CDF6DD00B8D9A0 /* Strip Trailing Whitespace */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputFileListPaths = (
+                       );
+                       inputPaths = (
+                       );
+                       name = "Strip Trailing Whitespace";
+                       outputFileListPaths = (
+                       );
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "find . -name '*.swift' -exec sed -i '' -E 's/[[:space:]]+$//g' {} +\n";
+               };
                6B87860E2189532500C099FB /* Extract wireguard-go Version */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
index 86f57d9449daae4d4148ed3afde9c37ff266fa8d..8b5311dadcd0763f5b21024c8766c1f802386a26 100644 (file)
@@ -64,7 +64,7 @@ class TunnelsManager {
             }
 
             let newTunnels = managers.map { TunnelContainer(tunnel: $0) }.sorted { $0.name < $1.name }
-            let hasChanges = self.tunnels.map { $0.name } != newTunnels.map { $0.name }
+            let hasChanges = self.tunnels.map { $0.tunnelConfiguration } != newTunnels.map { $0.tunnelConfiguration }
             if hasChanges {
                 self.tunnels = newTunnels
                 completionHandler(true)
index e44d29857e722167600cb717d22c64d20b591907..ca8902f25a749224076c7a9dd2d16d031289f6c7 100644 (file)
@@ -13,6 +13,10 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
     private var lastFirstInterface: NWInterface?
     private var packetTunnelSettingsGenerator: PacketTunnelSettingsGenerator?
 
+    deinit {
+        networkMonitor?.cancel()
+    }
+
     override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
         let activationAttemptId = options?["activationAttemptId"] as? String
         let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)