aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/wireguard/WireguardPeer.java
blob: 34d0f5556610fe5590f7c9c4dc10ffe82e4051a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.wireguard;

import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.WireguardKeyWithTimestamp;
import com.yahoo.vespa.hosted.node.admin.task.util.network.VersionedIpAddress;

import java.util.List;

/**
 * A wireguard peer. Sorted by hostname. IP addresses are sorted by version, IPv6 first.
 * The public key should always be non-null.
 *
 * @author gjoranv
 */
public record WireguardPeer(HostName hostname,
                            List<VersionedIpAddress> ipAddresses,
                            WireguardKeyWithTimestamp keyWithTimestamp) implements Comparable<WireguardPeer> {

    public WireguardPeer {
        if (ipAddresses.isEmpty()) throw new IllegalArgumentException("No IP addresses for peer node " + hostname.value());
        ipAddresses = ipAddresses.stream().sorted().toList();
    }

    @Override
    public int compareTo(WireguardPeer o) {
        return hostname.value().compareTo(o.hostname.value());
    }

}