summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-03-15 22:39:56 +0000
committerMikael Magnusson <mikma@users.sourceforge.net>2023-02-07 22:43:23 +0100
commit279e9297b9700c6db9cef22d86755f5f8337ad35 (patch)
tree3ef226c1c23c9e37ea2918c7a110098d517de443 /tunnel/src/main/java/com/wireguard/android
parent421bae85375dbef7fb64759eae22134d3c42a1fe (diff)
WIP: add dhcp information to detail
Diffstat (limited to 'tunnel/src/main/java/com/wireguard/android')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Backend.java2
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/DhcpInfo.java57
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java11
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java6
4 files changed, 76 insertions, 0 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 5aaad826..1d9be593 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
@@ -18,6 +18,8 @@ import androidx.annotation.Nullable;
@NonNullForAll
public interface Backend {
+ DhcpInfo getDhcpInfo(Tunnel tunnel) throws Exception;
+
/**
* Enumerate names of currently-running tunnels.
*
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/DhcpInfo.java b/tunnel/src/main/java/com/wireguard/android/backend/DhcpInfo.java
new file mode 100644
index 00000000..35a7dd43
--- /dev/null
+++ b/tunnel/src/main/java/com/wireguard/android/backend/DhcpInfo.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2020 WireGuard LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.wireguard.android.backend;
+
+import android.os.SystemClock;
+import android.util.Pair;
+
+import com.wireguard.crypto.Key;
+import com.wireguard.util.NonNullForAll;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class representing DHCP info for a {@link Tunnel} instance.
+ */
+@NonNullForAll
+public class DhcpInfo {
+ private String info;
+ private long lastTouched = SystemClock.elapsedRealtime();
+
+ DhcpInfo() {
+ }
+
+ /**
+ * Add a peer and its current data usage to the internal map.
+ *
+ * @param key A WireGuard public key bound to a particular peer
+ * @param rx The received traffic for the {@link com.wireguard.config.Peer} referenced by
+ * the provided {@link Key}. This value is in bytes
+ * @param tx The transmitted traffic for the {@link com.wireguard.config.Peer} referenced by
+ * the provided {@link Key}. This value is in bytes.
+ */
+ void set(final String info) {
+ this.info = info;
+ lastTouched = SystemClock.elapsedRealtime();
+ }
+
+ /**
+ * Check if the statistics are stale, indicating the need for the {@link Backend} to update them.
+ *
+ * @return boolean indicating if the current statistics instance has stale values.
+ */
+ public boolean isStale() {
+ return SystemClock.elapsedRealtime() - lastTouched > 900;
+ }
+
+ /**
+ */
+ public String get() {
+ return info;
+ }
+
+}
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 f077189a..fdbf0e9c 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -88,6 +88,17 @@ public final class GoBackend implements Backend, EventHandler {
private static native String wgVersion();
+ @Override
+ public DhcpInfo getDhcpInfo(final Tunnel tunnel) {
+ final DhcpInfo info = new DhcpInfo();
+ if (tunnel != currentTunnel) {
+ return info;
+ }
+ // TODO update info
+ info.set("FIXME");
+ return info;
+ }
+
/**
* Method to get the names of running tunnels.
*
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 3121c996..9c9dfbc1 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -58,6 +58,12 @@ public final class WgQuickBackend implements Backend {
}
@Override
+ public DhcpInfo getDhcpInfo(final Tunnel tunnel) {
+ final DhcpInfo info = new DhcpInfo();
+ return info;
+ }
+
+ @Override
public Set<String> getRunningTunnelNames() {
final List<String> output = new ArrayList<>();
// Don't throw an exception here or nothing will show up in the UI.