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
|
|
|
|
|
|
|
|
struct PeerConfiguration {
|
|
|
|
var publicKey: Data
|
|
|
|
var preSharedKey: Data? {
|
|
|
|
didSet(value) {
|
|
|
|
if let value = value {
|
|
|
|
if value.count != TunnelConfiguration.keyLength {
|
|
|
|
fatalError("Invalid preshared key")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var allowedIPs = [IPAddressRange]()
|
|
|
|
var endpoint: Endpoint?
|
|
|
|
var persistentKeepAlive: UInt16?
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-21 04:52:45 +00:00
|
|
|
init(publicKey: Data) {
|
|
|
|
self.publicKey = publicKey
|
|
|
|
if publicKey.count != TunnelConfiguration.keyLength {
|
|
|
|
fatalError("Invalid public key")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 04:41:54 +00:00
|
|
|
|
|
|
|
extension PeerConfiguration: Equatable {
|
|
|
|
static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
|
|
|
|
return lhs.publicKey == rhs.publicKey &&
|
|
|
|
lhs.preSharedKey == rhs.preSharedKey &&
|
|
|
|
Set(lhs.allowedIPs) == Set(rhs.allowedIPs) &&
|
|
|
|
lhs.endpoint == rhs.endpoint &&
|
|
|
|
lhs.persistentKeepAlive == rhs.persistentKeepAlive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PeerConfiguration: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(publicKey)
|
|
|
|
hasher.combine(preSharedKey)
|
|
|
|
hasher.combine(Set(allowedIPs))
|
|
|
|
hasher.combine(endpoint)
|
|
|
|
hasher.combine(persistentKeepAlive)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|