aboutsummaryrefslogblamecommitdiffstats
path: root/WireGuard/Shared/Model/TunnelConfiguration.swift
blob: 5a8f7df5af50b2bd0096d3888bf145c3bdedd150 (plain) (tree)
1
2
3
4
5
6
7
                               
                                                             



                                 
                     




                                         
                                                                                        

                                  
                        







                                                                           







                                                                                 
// SPDX-License-Identifier: MIT
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.

import Foundation

final class TunnelConfiguration {
    var name: String?
    var interface: InterfaceConfiguration
    let peers: [PeerConfiguration]

    static let keyLength = 32

    init(name: String?, interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
        self.interface = interface
        self.peers = peers
        self.name = name

        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")
        }
    }
}

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)
    }
}