Tunnel view model: Peers in a configuation may not share the same public key

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-06 08:17:19 +05:30
parent 636aa98b79
commit a62f7fb988
1 changed files with 7 additions and 0 deletions

View File

@ -434,6 +434,13 @@ class TunnelViewModel {
peerConfigurations.append(peerConfiguration)
}
}
let peerPublicKeysArray = peerConfigurations.map { $0.publicKey }
let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
if (peerPublicKeysArray.count != peerPublicKeysSet.count) {
return .error("Two or more peers cannot have the same public key")
}
let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration)
tunnelConfiguration.peers = peerConfigurations
return .saved(tunnelConfiguration)