summaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-19 18:50:35 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-19 18:50:35 -0500
commit9026317b0ef5c32292c8f500105785cb8efde912 (patch)
tree32436517871c1cabb6207f30cfb797cc40c2a210 /app/src/main
parentfbd923a0606befd2b116d35dbb3f271d1e7c234a (diff)
Peer: Associate with a Config
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java17
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java16
2 files changed, 29 insertions, 4 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index 3f98cbcb..b2885710 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -34,6 +34,18 @@ public class Config extends BaseObservable
private String name;
private final ObservableList<Peer> peers = new ObservableArrayList<>();
+ public Peer addPeer() {
+ final Peer peer = new Peer(this);
+ peers.add(peer);
+ return peer;
+ }
+
+ private Peer addPeer(final Peer peer) {
+ final Peer copy = peer.copy(this);
+ peers.add(copy);
+ return copy;
+ }
+
@Override
public int compareTo(@NonNull final Config config) {
return getName().compareTo(config.getName());
@@ -53,7 +65,7 @@ public class Config extends BaseObservable
name = source.name;
peers.clear();
for (final Peer peer : source.peers)
- peers.add(peer.copy());
+ addPeer(peer);
}
public Interface getInterface() {
@@ -92,8 +104,7 @@ public class Config extends BaseObservable
if ("[Interface]".equals(line)) {
currentPeer = null;
} else if ("[Peer]".equals(line)) {
- currentPeer = new Peer();
- peers.add(currentPeer);
+ currentPeer = addPeer();
} else if (currentPeer == null) {
iface.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 5a8c6789..f0e24162 100644
--- a/app/src/main/java/com/wireguard/config/Peer.java
+++ b/app/src/main/java/com/wireguard/config/Peer.java
@@ -12,13 +12,22 @@ import com.android.databinding.library.baseAdapters.BR;
public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
private String allowedIPs;
+ private Config config;
private String endpoint;
private String persistentKeepalive;
private String publicKey;
+ public Peer(final Config config) {
+ this.config = config;
+ }
+
@Override
public Peer copy() {
- final Peer copy = new Peer();
+ return copy(config);
+ }
+
+ public Peer copy(final Config config) {
+ final Peer copy = new Peer(config);
copy.copyFrom(this);
return copy;
}
@@ -65,6 +74,11 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
throw new IllegalArgumentException(line);
}
+ public void removeSelf() {
+ config.getPeers().remove(this);
+ config = null;
+ }
+
public void setAllowedIPs(String allowedIPs) {
if (allowedIPs != null && allowedIPs.isEmpty())
allowedIPs = null;