2018-12-21 04:52:45 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-02-14 15:10:32 +00:00
|
|
|
// Copyright © 2018-2023 WireGuard LLC. All Rights Reserved.
|
2018-12-21 04:52:45 +00:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-11-05 11:23:06 +00:00
|
|
|
public final class TunnelConfiguration {
|
|
|
|
public var name: String?
|
|
|
|
public var interface: InterfaceConfiguration
|
|
|
|
public let peers: [PeerConfiguration]
|
2018-12-21 04:52:45 +00:00
|
|
|
|
2020-11-05 11:23:06 +00:00
|
|
|
public 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 }
|
2020-11-26 16:23:50 +00:00
|
|
|
let peerPublicKeysSet = Set<PublicKey>(peerPublicKeysArray)
|
2018-12-21 04:52:45 +00:00
|
|
|
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 {
|
2020-11-05 11:23:06 +00:00
|
|
|
public static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
|
2018-12-22 04:41:54 +00:00
|
|
|
return lhs.name == rhs.name &&
|
|
|
|
lhs.interface == rhs.interface &&
|
|
|
|
Set(lhs.peers) == Set(rhs.peers)
|
|
|
|
}
|
|
|
|
}
|