summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-23 23:43:58 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-23 23:43:58 -0500
commit95384851cd829b33dee99b3e7d5c5423cb69716f (patch)
treea1310bdea0873029b51c6624420ad44bc5ab0886 /app/src/main/java/com/wireguard
parentd1a5c1a72e5181d4e6c3dfff7b9d0552f4500587 (diff)
Config/Interface/Peer: Fix some missed change notifications
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java5
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java11
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java17
3 files changed, 18 insertions, 15 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index 8f61dbdd..7745d4e5 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -76,6 +76,7 @@ public class Config extends BaseObservable
name = null;
peers.clear();
}
+ notifyChange();
}
public Interface getInterface() {
@@ -116,9 +117,9 @@ public class Config extends BaseObservable
} else if ("[Peer]".equals(line)) {
currentPeer = addPeer();
} else if (currentPeer == null) {
- iface.parseFrom(line);
+ iface.parse(line);
} else {
- currentPeer.parseFrom(line);
+ currentPeer.parse(line);
}
}
}
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java
index b81b6d99..a4ea4b81 100644
--- a/app/src/main/java/com/wireguard/config/Interface.java
+++ b/app/src/main/java/com/wireguard/config/Interface.java
@@ -42,6 +42,7 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
mtu = null;
setPrivateKey(null);
}
+ notifyChange();
}
public void generateKeypair() {
@@ -81,16 +82,16 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
return keypair != null ? keypair.getPublicKey() : null;
}
- public void parseFrom(final String line) {
+ public void parse(final String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ADDRESS)
- address = key.parseFrom(line);
+ setAddress(key.parseFrom(line));
else if (key == Attribute.DNS)
- dns = key.parseFrom(line);
+ setDns(key.parseFrom(line));
else if (key == Attribute.LISTEN_PORT)
- listenPort = key.parseFrom(line);
+ setListenPort(key.parseFrom(line));
else if (key == Attribute.MTU)
- mtu = key.parseFrom(line);
+ setMtu(key.parseFrom(line));
else if (key == Attribute.PRIVATE_KEY)
setPrivateKey(key.parseFrom(line));
else
diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java
index f0e24162..912e8bf5 100644
--- a/app/src/main/java/com/wireguard/config/Peer.java
+++ b/app/src/main/java/com/wireguard/config/Peer.java
@@ -12,7 +12,7 @@ import com.android.databinding.library.baseAdapters.BR;
public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
private String allowedIPs;
- private Config config;
+ private final Config config;
private String endpoint;
private String persistentKeepalive;
private String publicKey;
@@ -38,6 +38,7 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
endpoint = source.endpoint;
persistentKeepalive = source.persistentKeepalive;
publicKey = source.publicKey;
+ notifyChange();
}
@Bindable
@@ -60,23 +61,23 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
return publicKey;
}
- public void parseFrom(final String line) {
+ public void parse(final String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ALLOWED_IPS)
- allowedIPs = key.parseFrom(line);
+ setAllowedIPs(key.parseFrom(line));
else if (key == Attribute.ENDPOINT)
- endpoint = key.parseFrom(line);
+ setEndpoint(key.parseFrom(line));
else if (key == Attribute.PERSISTENT_KEEPALIVE)
- persistentKeepalive = key.parseFrom(line);
+ setPersistentKeepalive(key.parseFrom(line));
else if (key == Attribute.PUBLIC_KEY)
- publicKey = key.parseFrom(line);
+ setPublicKey(key.parseFrom(line));
else
throw new IllegalArgumentException(line);
}
public void removeSelf() {
- config.getPeers().remove(this);
- config = null;
+ if (!config.getPeers().remove(this))
+ throw new IllegalStateException("This peer was already removed from its config");
}
public void setAllowedIPs(String allowedIPs) {