summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-10-28 23:14:12 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2024-01-08 00:15:09 +0100
commit8ab1a26560868f947adf9a2774d3712ae45c9ac0 (patch)
treed42889a1bd52b292ed7e6f201933bef78d718fbe
parentf95f7d93d98a385a0d2ebf91de5a558c3671da05 (diff)
WIP: add persistent keepalive to observable tunnel
WIP: add default persistent keepalive to bgp code WIP: tunnel: fix onPersistentKeepaliveChange WIP: ui: fix onPersistentKeepaliveChange WIP: ui: fix onPersistentKeepaliveChanged WIP: fix peer detail persistent keepalive WIP: ui: notify persistentKeepalive
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Backend.java1
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Bgp.java3
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java3
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java2
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java1
-rw-r--r--ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt12
-rw-r--r--ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt4
7 files changed, 24 insertions, 2 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
index fc281072..7e40da3f 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
@@ -72,5 +72,6 @@ public interface Backend {
void addAllowedIps(Tunnel tunnel, Key publicKey, List<InetNetwork> addNetworks);
void setPeer(Tunnel tunnel, Key publicKey, @Nullable InetEndpoint endpoint,
+ Integer persistentKeepalive,
List<InetNetwork> addAllowedIps, List<InetNetwork> removeAllowedIps);
}
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Bgp.java b/tunnel/src/main/java/com/wireguard/android/backend/Bgp.java
index ddf01199..092b91b7 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Bgp.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Bgp.java
@@ -198,10 +198,11 @@ public class Bgp implements BGPListener {
}
}
+ tunnel.onPersistentKeepaliveChange(publicKey, 24550);
tunnel.onAllowedIpsChange(publicKey, addNetworks, removeNetworks);
// backend.addAllowedIps(tunnel, publicKey, addNetworks);
// backend.removeAllowedIps(tunnel, publicKey, addNetworks); // TODO
- backend.setPeer(tunnel, publicKey, endpoint, addNetworks, removeNetworks);
+ backend.setPeer(tunnel, publicKey, endpoint, 24550, addNetworks, removeNetworks);
} catch (KeyFormatException ex) {
Log.w(TAG, "Key.fromBytes " + ex);
}
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
index 635c04f0..0e9668d0 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -342,6 +342,7 @@ public final class GoBackend implements Backend {
@Override
public void setPeer(Tunnel tunnel, Key publicKey, @Nullable InetEndpoint endpoint,
+ Integer persistentKeepalive,
List<InetNetwork> addAllowedIps, List<InetNetwork> removeAllowedIps) {
if (tunnel != currentTunnel) {
// TODO logerror and/or return error/throw.
@@ -362,7 +363,7 @@ public final class GoBackend implements Backend {
endpoint.getResolved(resolver, true).ifPresent(ep -> sb.append("endpoint=").append(ep).append('\n'));
}
- sb.append("persistent_keepalive_interval=").append(24550).append('\n');
+ sb.append("persistent_keepalive_interval=").append(persistentKeepalive).append('\n');
String goConfig = sb.toString();
// TODO removed removeNetworks
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java b/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java
index fc94375b..8c6eacda 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java
@@ -70,5 +70,7 @@ public interface Tunnel {
void onEndpointChange(Key publicKey, @Nullable InetEndpoint newEndpoint);
+ void onPersistentKeepaliveChange(Key publicKey, @Nullable Integer newPersistentKeepalive);
+
void onAllowedIpsChange(Key publicKey, @Nullable List<InetNetwork> addNetworks, @Nullable List<InetNetwork> removeNetworks);
}
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index 3cc1c822..645b2fe0 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -176,6 +176,7 @@ public final class WgQuickBackend implements Backend {
@Override
public void setPeer(Tunnel tunnel, Key publicKey, @Nullable InetEndpoint endpoint,
+ Integer persistentKeepalive,
List<InetNetwork> addAllowedIps, List<InetNetwork> removeAllowedIps) {
throw new RuntimeException("Not implemented");
}
diff --git a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
index 97aae280..03529454 100644
--- a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
+++ b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
@@ -228,6 +228,18 @@ class ObservableTunnel internal constructor(
return peer
}
+ override fun onPersistentKeepaliveChange(publicKey: Key, newPersistentKeepalive: Int?) {
+ Application.getCoroutineScope().launch {
+ onPersistentKeepaliveChanged(publicKey, newPersistentKeepalive)
+ }
+ }
+
+ private fun onPersistentKeepaliveChanged(publicKey: Key, newPersistentKeepalive: Int?) {
+ var peer: PeerDetail = lookupPeer(publicKey)
+
+ peer.persistentKeepalive = Optional.ofNullable(newPersistentKeepalive)
+ }
+
override fun onAllowedIpsChange(publicKey: Key, addNetworks: List<InetNetwork>?, removeNetworks: List<InetNetwork>?) {
Application.getCoroutineScope().launch {
onAllowedIpsChanged(publicKey, addNetworks, removeNetworks)
diff --git a/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt b/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt
index 80b32fd5..3b6f42be 100644
--- a/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt
+++ b/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt
@@ -46,6 +46,10 @@ class PeerDetail : BaseObservable {
@get:Bindable
var persistentKeepalive: Optional<Int> = Optional.empty()
+ set(value) {
+ field = value
+ notifyPropertyChanged(BR.persistentKeepalive)
+ }
constructor(other: Peer) {
peer = other