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 struct PeerConfiguration {
|
2020-11-26 16:23:50 +00:00
|
|
|
public var publicKey: PublicKey
|
|
|
|
public var preSharedKey: PreSharedKey?
|
2020-11-05 11:23:06 +00:00
|
|
|
public var allowedIPs = [IPAddressRange]()
|
|
|
|
public var endpoint: Endpoint?
|
|
|
|
public var persistentKeepAlive: UInt16?
|
|
|
|
public var rxBytes: UInt64?
|
|
|
|
public var txBytes: UInt64?
|
|
|
|
public var lastHandshakeTime: Date?
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2020-11-26 16:23:50 +00:00
|
|
|
public init(publicKey: PublicKey) {
|
2018-12-21 04:52:45 +00:00
|
|
|
self.publicKey = publicKey
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 04:41:54 +00:00
|
|
|
|
|
|
|
extension PeerConfiguration: Equatable {
|
2020-11-05 11:23:06 +00:00
|
|
|
public static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
|
2018-12-22 04:41:54 +00:00
|
|
|
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 {
|
2020-11-05 11:23:06 +00:00
|
|
|
public func hash(into hasher: inout Hasher) {
|
2018-12-22 04:41:54 +00:00
|
|
|
hasher.combine(publicKey)
|
|
|
|
hasher.combine(preSharedKey)
|
|
|
|
hasher.combine(Set(allowedIPs))
|
|
|
|
hasher.combine(endpoint)
|
|
|
|
hasher.combine(persistentKeepAlive)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|