diff options
author | Samuel Holland <samuel@sholland.org> | 2018-09-05 18:33:42 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-11-11 21:50:23 -0600 |
commit | a264f7ab36bf1335999d53cb4a0d753c54b231d0 (patch) | |
tree | 8adb020e43111ff0420569c16c8c529f69b6a0e5 /app/src/main/java/com/wireguard/config | |
parent | 4e134772d7d2fea02722a87e413947965764fef8 (diff) |
Auto-format the source directories
Blame Jason for writing Java in vim.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Config.java | 2 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Interface.java | 10 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 87 |
3 files changed, 49 insertions, 50 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java index 31fe13cf..61e31838 100644 --- a/app/src/main/java/com/wireguard/config/Config.java +++ b/app/src/main/java/com/wireguard/config/Config.java @@ -105,9 +105,9 @@ public class Config { return new Observable[size]; } }; - @Nullable private String name; private final Interface.Observable observableInterface; private final ObservableList<Peer.Observable> observablePeers; + @Nullable private String name; public Observable(@Nullable final Config parent, @Nullable final String name) { this.name = name; diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index a1b9125a..aa1d986b 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -28,12 +28,12 @@ import java.util.List; public class Interface { private final List<InetNetwork> addressList; + private final Context context = Application.get(); private final List<InetAddress> dnsList; private final List<String> excludedApplications; @Nullable private Keypair keypair; private int listenPort; private int mtu; - private final Context context = Application.get(); public Interface() { addressList = new ArrayList<>(); @@ -94,6 +94,10 @@ public class Interface { return dnsList.toArray(new InetAddress[dnsList.size()]); } + public String[] getExcludedApplications() { + return excludedApplications.toArray(new String[excludedApplications.size()]); + } + @Nullable private String getExcludedApplicationsString() { if (excludedApplications.isEmpty()) @@ -101,10 +105,6 @@ public class Interface { return Attribute.iterableToString(excludedApplications); } - public String[] getExcludedApplications() { - return excludedApplications.toArray(new String[excludedApplications.size()]); - } - public int getListenPort() { return listenPort; } diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index 914516ba..5cf0283c 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -37,11 +37,11 @@ import java9.lang.Iterables; public class Peer { private final List<InetNetwork> allowedIPsList; + private final Context context = Application.get(); @Nullable private InetEndpoint endpoint; private int persistentKeepalive; @Nullable private String preSharedKey; @Nullable private String publicKey; - private final Context context = Application.get(); public Peer() { allowedIPsList = new ArrayList<>(); @@ -201,13 +201,15 @@ public class Peer { return new Observable[size]; } }; + private static final List<String> DEFAULT_ROUTE_MOD_RFC1918_V4 = Arrays.asList("0.0.0.0/5", "8.0.0.0/7", "11.0.0.0/8", "12.0.0.0/6", "16.0.0.0/4", "32.0.0.0/3", "64.0.0.0/2", "128.0.0.0/3", "160.0.0.0/5", "168.0.0.0/6", "172.0.0.0/12", "172.32.0.0/11", "172.64.0.0/10", "172.128.0.0/9", "173.0.0.0/8", "174.0.0.0/7", "176.0.0.0/4", "192.0.0.0/9", "192.128.0.0/11", "192.160.0.0/13", "192.169.0.0/16", "192.170.0.0/15", "192.172.0.0/14", "192.176.0.0/12", "192.192.0.0/10", "193.0.0.0/8", "194.0.0.0/7", "196.0.0.0/6", "200.0.0.0/5", "208.0.0.0/4"); + private static final String DEFAULT_ROUTE_V4 = "0.0.0.0/0"; + private final List<String> interfaceDNSRoutes = new ArrayList<>(); @Nullable private String allowedIPs; @Nullable private String endpoint; + private int numSiblings; @Nullable private String persistentKeepalive; @Nullable private String preSharedKey; @Nullable private String publicKey; - private final List<String> interfaceDNSRoutes = new ArrayList<>(); - private int numSiblings; public Observable(final Peer parent) { loadData(parent); @@ -244,22 +246,9 @@ public class Peer { return 0; } - private static final String DEFAULT_ROUTE_V4 = "0.0.0.0/0"; - private static final List<String> DEFAULT_ROUTE_MOD_RFC1918_V4 = Arrays.asList("0.0.0.0/5", "8.0.0.0/7", "11.0.0.0/8", "12.0.0.0/6", "16.0.0.0/4", "32.0.0.0/3", "64.0.0.0/2", "128.0.0.0/3", "160.0.0.0/5", "168.0.0.0/6", "172.0.0.0/12", "172.32.0.0/11", "172.64.0.0/10", "172.128.0.0/9", "173.0.0.0/8", "174.0.0.0/7", "176.0.0.0/4", "192.0.0.0/9", "192.128.0.0/11", "192.160.0.0/13", "192.169.0.0/16", "192.170.0.0/15", "192.172.0.0/14", "192.176.0.0/12", "192.192.0.0/10", "193.0.0.0/8", "194.0.0.0/7", "196.0.0.0/6", "200.0.0.0/5", "208.0.0.0/4"); - - public void toggleExcludePrivateIPs() { - final Collection<String> ips = new HashSet<>(Arrays.asList(Attribute.stringToList(allowedIPs))); - final boolean hasDefaultRoute = ips.contains(DEFAULT_ROUTE_V4); - final boolean hasDefaultRouteModRFC1918 = ips.containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4); - if ((!hasDefaultRoute && !hasDefaultRouteModRFC1918) || numSiblings > 0) - return; - Iterables.removeIf(ips, ip -> !ip.contains(":")); - if (hasDefaultRoute) { - ips.addAll(DEFAULT_ROUTE_MOD_RFC1918_V4); - ips.addAll(interfaceDNSRoutes); - } else if (hasDefaultRouteModRFC1918) - ips.add(DEFAULT_ROUTE_V4); - setAllowedIPs(Attribute.iterableToString(ips)); + @Bindable @Nullable + public String getAllowedIPs() { + return allowedIPs; } @Bindable @@ -268,21 +257,16 @@ public class Peer { return numSiblings == 0 && (ips.contains(DEFAULT_ROUTE_V4) || ips.containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4)); } - @Bindable - public boolean getIsExcludePrivateIPsOn() { - return numSiblings == 0 && Arrays.asList(Attribute.stringToList(allowedIPs)).containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4); - } - - @Bindable @Nullable - public String getAllowedIPs() { - return allowedIPs; - } - @Bindable @Nullable public String getEndpoint() { return endpoint; } + @Bindable + public boolean getIsExcludePrivateIPsOn() { + return numSiblings == 0 && Arrays.asList(Attribute.stringToList(allowedIPs)).containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4); + } + @Bindable @Nullable public String getPersistentKeepalive() { return persistentKeepalive; @@ -318,21 +302,6 @@ public class Peer { notifyPropertyChanged(BR.endpoint); } - public void setPersistentKeepalive(final String persistentKeepalive) { - this.persistentKeepalive = persistentKeepalive; - notifyPropertyChanged(BR.persistentKeepalive); - } - - public void setPreSharedKey(final String preSharedKey) { - this.preSharedKey = preSharedKey; - notifyPropertyChanged(BR.preSharedKey); - } - - public void setPublicKey(final String publicKey) { - this.publicKey = publicKey; - notifyPropertyChanged(BR.publicKey); - } - public void setInterfaceDNSRoutes(@Nullable final String dnsServers) { final Collection<String> ips = new HashSet<>(Arrays.asList(Attribute.stringToList(allowedIPs))); final boolean modifyAllowedIPs = ips.containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4); @@ -354,6 +323,36 @@ public class Peer { notifyPropertyChanged(BR.isExcludePrivateIPsOn); } + public void setPersistentKeepalive(final String persistentKeepalive) { + this.persistentKeepalive = persistentKeepalive; + notifyPropertyChanged(BR.persistentKeepalive); + } + + public void setPreSharedKey(final String preSharedKey) { + this.preSharedKey = preSharedKey; + notifyPropertyChanged(BR.preSharedKey); + } + + public void setPublicKey(final String publicKey) { + this.publicKey = publicKey; + notifyPropertyChanged(BR.publicKey); + } + + public void toggleExcludePrivateIPs() { + final Collection<String> ips = new HashSet<>(Arrays.asList(Attribute.stringToList(allowedIPs))); + final boolean hasDefaultRoute = ips.contains(DEFAULT_ROUTE_V4); + final boolean hasDefaultRouteModRFC1918 = ips.containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4); + if ((!hasDefaultRoute && !hasDefaultRouteModRFC1918) || numSiblings > 0) + return; + Iterables.removeIf(ips, ip -> !ip.contains(":")); + if (hasDefaultRoute) { + ips.addAll(DEFAULT_ROUTE_MOD_RFC1918_V4); + ips.addAll(interfaceDNSRoutes); + } else if (hasDefaultRouteModRFC1918) + ips.add(DEFAULT_ROUTE_V4); + setAllowedIPs(Attribute.iterableToString(ips)); + } + @Override public void writeToParcel(final Parcel dest, final int flags) { dest.writeString(allowedIPs); |