aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/DNSServer.swift6
-rw-r--r--WireGuard/Shared/Model/Endpoint.swift13
-rw-r--r--WireGuard/Shared/Model/IPAddressRange.swift13
-rw-r--r--WireGuard/Shared/Model/InterfaceConfiguration.swift14
-rw-r--r--WireGuard/Shared/Model/PeerConfiguration.swift21
-rw-r--r--WireGuard/Shared/Model/TunnelConfiguration.swift8
6 files changed, 75 insertions, 0 deletions
diff --git a/WireGuard/Shared/Model/DNSServer.swift b/WireGuard/Shared/Model/DNSServer.swift
index 710c656c..5a509cba 100644
--- a/WireGuard/Shared/Model/DNSServer.swift
+++ b/WireGuard/Shared/Model/DNSServer.swift
@@ -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)"
diff --git a/WireGuard/Shared/Model/Endpoint.swift b/WireGuard/Shared/Model/Endpoint.swift
index 03de1318..bcc74cf7 100644
--- a/WireGuard/Shared/Model/Endpoint.swift
+++ b/WireGuard/Shared/Model/Endpoint.swift
@@ -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 {
diff --git a/WireGuard/Shared/Model/IPAddressRange.swift b/WireGuard/Shared/Model/IPAddressRange.swift
index 7d3e5eca..26dccc34 100644
--- a/WireGuard/Shared/Model/IPAddressRange.swift
+++ b/WireGuard/Shared/Model/IPAddressRange.swift
@@ -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)"
diff --git a/WireGuard/Shared/Model/InterfaceConfiguration.swift b/WireGuard/Shared/Model/InterfaceConfiguration.swift
index ef33907a..e28046b4 100644
--- a/WireGuard/Shared/Model/InterfaceConfiguration.swift
+++ b/WireGuard/Shared/Model/InterfaceConfiguration.swift
@@ -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
+ }
+}
diff --git a/WireGuard/Shared/Model/PeerConfiguration.swift b/WireGuard/Shared/Model/PeerConfiguration.swift
index 2e969e6c..a684fa69 100644
--- a/WireGuard/Shared/Model/PeerConfiguration.swift
+++ b/WireGuard/Shared/Model/PeerConfiguration.swift
@@ -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)
+
+ }
+}
diff --git a/WireGuard/Shared/Model/TunnelConfiguration.swift b/WireGuard/Shared/Model/TunnelConfiguration.swift
index bee3c9dc..532212e5 100644
--- a/WireGuard/Shared/Model/TunnelConfiguration.swift
+++ b/WireGuard/Shared/Model/TunnelConfiguration.swift
@@ -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)
+ }
+}