2018-12-21 04:52:45 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-01-02 00:56:33 +00:00
|
|
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
2018-12-21 04:52:45 +00:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
final class TunnelConfiguration {
|
2018-12-21 23:28:18 +00:00
|
|
|
var name: String?
|
2018-12-21 04:52:45 +00:00
|
|
|
var interface: InterfaceConfiguration
|
|
|
|
let peers: [PeerConfiguration]
|
|
|
|
|
|
|
|
static let keyLength = 32
|
|
|
|
|
2018-12-21 23:28:18 +00:00
|
|
|
init(name: String?, interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
|
2018-12-21 04:52:45 +00:00
|
|
|
self.interface = interface
|
|
|
|
self.peers = peers
|
2018-12-21 23:28:18 +00:00
|
|
|
self.name = name
|
2018-12-21 04:52:45 +00:00
|
|
|
|
|
|
|
let peerPublicKeysArray = peers.map { $0.publicKey }
|
|
|
|
let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
|
|
|
|
if peerPublicKeysArray.count != peerPublicKeysSet.count {
|
|
|
|
fatalError("Two or more peers cannot have the same public key")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 04:41:54 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|