aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-02 13:09:45 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-02 13:09:45 +0530
commit66e802584bd0c5be0c545d87b3aa52c6d182d475 (patch)
tree668cdf8e3f99cb5aa1b17a5cd8a5df644fd3213b /WireGuard
parentTunnel view model: Initialize peerData.numberOfPeers (diff)
downloadwireguard-apple-66e802584bd0c5be0c545d87b3aa52c6d182d475.tar.xz
wireguard-apple-66e802584bd0c5be0c545d87b3aa52c6d182d475.zip
Tunnel view model: If there's just one peer, populate the scratchpad on init
So that exclude private IPs can be computed correctly. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift20
1 files changed, 13 insertions, 7 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index 0886848..a9ee6f8 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -179,11 +179,9 @@ class TunnelViewModel {
var validatedConfiguration: PeerConfiguration? = nil
// For exclude private IPs
- var shouldAllowExcludePrivateIPsControl: Bool = false
- var excludePrivateIPsValue: Bool = false
- var numberOfPeers: Int = 0 {
- didSet { updateExcludePrivateIPsFieldState() }
- }
+ var shouldAllowExcludePrivateIPsControl: Bool = false /* Read-only from the VC's point of view */
+ var excludePrivateIPsValue: Bool = false /* Read-only from the VC's point of view */
+ fileprivate var numberOfPeers: Int = 0
init(index: Int) {
self.index = index
@@ -318,6 +316,9 @@ class TunnelViewModel {
excludePrivateIPsValue = false
return
}
+ if (scratchpad.isEmpty) {
+ populateScratchpad()
+ }
let allowedIPStrings = Set<String>(
(scratchpad[.allowedIPs] ?? "")
.split(separator: ",")
@@ -365,8 +366,8 @@ class TunnelViewModel {
var peersData: [PeerData]
init(tunnelConfiguration: TunnelConfiguration?) {
- interfaceData = InterfaceData()
- peersData = []
+ let interfaceData: InterfaceData = InterfaceData()
+ var peersData: [PeerData] = []
if let tunnelConfiguration = tunnelConfiguration {
interfaceData.validatedConfiguration = tunnelConfiguration.interface
for (i, peerConfiguration) in tunnelConfiguration.peers.enumerated() {
@@ -378,7 +379,10 @@ class TunnelViewModel {
let numberOfPeers = peersData.count
for peerData in peersData {
peerData.numberOfPeers = numberOfPeers
+ peerData.updateExcludePrivateIPsFieldState()
}
+ self.interfaceData = interfaceData
+ self.peersData = peersData
}
func appendEmptyPeer() {
@@ -386,6 +390,7 @@ class TunnelViewModel {
peersData.append(peer)
for p in peersData {
p.numberOfPeers = peersData.count
+ p.updateExcludePrivateIPsFieldState()
}
}
@@ -398,6 +403,7 @@ class TunnelViewModel {
}
for p in peersData {
p.numberOfPeers = peersData.count
+ p.updateExcludePrivateIPsFieldState()
}
}