Config/Interface: Allow copyFrom() to work on null

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-23 18:02:37 -05:00
parent d3e6b311ca
commit 0e46f95668
2 changed files with 28 additions and 11 deletions

View File

@ -61,12 +61,21 @@ public class Config extends BaseObservable
@Override @Override
public void copyFrom(final Config source) { public void copyFrom(final Config source) {
iface.copyFrom(source.iface); if (source != null) {
isEnabled = source.isEnabled; iface.copyFrom(source.iface);
name = source.name; isEnabled = source.isEnabled;
peers.clear(); isPrimary = source.isPrimary;
for (final Peer peer : source.peers) name = source.name;
addPeer(peer); peers.clear();
for (final Peer peer : source.peers)
addPeer(peer);
} else {
iface.copyFrom(null);
isEnabled = false;
isPrimary = false;
name = null;
peers.clear();
}
} }
public Interface getInterface() { public Interface getInterface() {

View File

@ -29,11 +29,19 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
@Override @Override
public void copyFrom(final Interface source) { public void copyFrom(final Interface source) {
address = source.address; if (source != null) {
dns = source.dns; address = source.address;
listenPort = source.listenPort; dns = source.dns;
setPrivateKey(source.privateKey); listenPort = source.listenPort;
mtu = source.mtu; mtu = source.mtu;
setPrivateKey(source.privateKey);
} else {
address = null;
dns = null;
listenPort = null;
mtu = null;
setPrivateKey(null);
}
} }
public void generateKeypair() { public void generateKeypair() {