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

This commit is contained in:
Roopesh Chander 2018-11-06 08:17:19 +05:30
parent e05a6c31b9
commit e9044966bf
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)