@@ -30,9 +30,7 @@ public final class Config {
|
||||
private final List<Peer> peers;
|
||||
|
||||
private Config(final Builder builder) {
|
||||
if (builder.interfaze == null)
|
||||
throw new IllegalArgumentException("An [Interface] section is required");
|
||||
interfaze = builder.interfaze;
|
||||
interfaze = Objects.requireNonNull(builder.interfaze, "An [Interface] section is required");
|
||||
// Defensively copy to ensure immutability even if the Builder is reused.
|
||||
peers = Collections.unmodifiableList(new ArrayList<>(builder.peers));
|
||||
}
|
||||
@@ -189,6 +187,8 @@ public final class Config {
|
||||
}
|
||||
|
||||
public Config build() {
|
||||
if (interfaze == null)
|
||||
throw new IllegalArgumentException("An [Interface] section is required");
|
||||
return new Config(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,11 @@ public final class Interface {
|
||||
private final Optional<Integer> mtu;
|
||||
|
||||
private Interface(final Builder builder) {
|
||||
if (builder.keyPair == null)
|
||||
throw new IllegalArgumentException("Interfaces must have a private key");
|
||||
|
||||
// Defensively copy to ensure immutability even if the Builder is reused.
|
||||
addresses = Collections.unmodifiableSet(new LinkedHashSet<>(builder.addresses));
|
||||
dnsServers = Collections.unmodifiableSet(new LinkedHashSet<>(builder.dnsServers));
|
||||
excludedApplications = Collections.unmodifiableSet(new LinkedHashSet<>(builder.excludedApplications));
|
||||
keyPair = builder.keyPair;
|
||||
keyPair = Objects.requireNonNull(builder.keyPair, "Interfaces must have a private key");
|
||||
listenPort = builder.listenPort;
|
||||
mtu = builder.mtu;
|
||||
}
|
||||
@@ -264,6 +261,8 @@ public final class Interface {
|
||||
}
|
||||
|
||||
public Interface build() {
|
||||
if (keyPair == null)
|
||||
throw new IllegalArgumentException("Interfaces must have a private key");
|
||||
return new Interface(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +35,12 @@ public final class Peer {
|
||||
private final Key publicKey;
|
||||
|
||||
private Peer(final Builder builder) {
|
||||
if (builder.publicKey == null)
|
||||
throw new IllegalArgumentException("Peers must have a public key");
|
||||
// Defensively copy to ensure immutability even if the Builder is reused.
|
||||
allowedIps = Collections.unmodifiableSet(new LinkedHashSet<>(builder.allowedIps));
|
||||
endpoint = builder.endpoint;
|
||||
persistentKeepalive = builder.persistentKeepalive;
|
||||
preSharedKey = builder.preSharedKey;
|
||||
publicKey = builder.publicKey;
|
||||
publicKey = Objects.requireNonNull(builder.publicKey, "Peers must have a public key");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,6 +224,8 @@ public final class Peer {
|
||||
}
|
||||
|
||||
public Peer build() {
|
||||
if (publicKey == null)
|
||||
throw new IllegalArgumentException("Peers must have a public key");
|
||||
return new Peer(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user