aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/TunnelViewModel.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-10-23 16:28:24 +0530
committerRoopesh Chander <roop@roopc.net>2018-10-27 15:13:01 +0530
commit722b3f6c7b8b8ad06733040ba5cb2216c6e66d41 (patch)
treeacbf74907120180e9fcac0d18a3d34e209cdb7df /WireGuard/WireGuard/UI/TunnelViewModel.swift
parentModel for DNS server (diff)
downloadwireguard-apple-722b3f6c7b8b8ad06733040ba5cb2216c6e66d41.tar.xz
wireguard-apple-722b3f6c7b8b8ad06733040ba5cb2216c6e66d41.zip
Model: Use DNSServer in the Configuration model
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/TunnelViewModel.swift')
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift17
1 files changed, 13 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index 13c831f..d6f7126 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -74,8 +74,8 @@ class TunnelViewModel {
if let mtu = config.mtu {
scratchpad[.mtu] = String(mtu)
}
- if let dns = config.dns {
- scratchpad[.dns] = String(dns)
+ if (!config.dns.isEmpty) {
+ scratchpad[.dns] = config.dns.map { $0.stringRepresentation() }.joined(separator: ", ")
}
}
@@ -124,9 +124,18 @@ class TunnelViewModel {
errorMessages.append("Interface's MTU should be a number")
}
}
- // TODO: Validate DNS
if let dnsString = scratchpad[.dns] {
- config.dns = dnsString
+ var dnsServers: [DNSServer] = []
+ for dnsServerString in dnsString.split(separator: ",") {
+ let trimmedString = dnsServerString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
+ if let dnsServer = DNSServer(from: trimmedString) {
+ dnsServers.append(dnsServer)
+ } else {
+ fieldsWithError.insert(.dns)
+ errorMessages.append("Interface's DNS should be a list of comma-separated IP addresses")
+ }
+ }
+ config.dns = dnsServers
}
guard (errorMessages.isEmpty) else {