summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-03-11 23:10:42 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-06-01 21:08:03 +0200
commit8baaf454b485fafa17ee25d1be0e1ddc58c41a4f (patch)
treec1eddf36059e2c45d9b972c9dbe3f23a34b05762 /tunnel/src/main
parent3b88b17aa0ed4ad0929d67552580c181b73ed607 (diff)
WIP: Add TrafficStats
Diffstat (limited to 'tunnel/src/main')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java3
-rw-r--r--tunnel/src/main/java/com/wireguard/util/Resolver.java4
2 files changed, 7 insertions, 0 deletions
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 6e8d565c..f2fa8342 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -15,6 +15,7 @@ import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
+import android.net.TrafficStats;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
@@ -99,6 +100,7 @@ import androidx.collection.ArraySet;
public final class GoBackend implements Backend {
private static final int DNS_RESOLUTION_RETRIES = 10;
private static final String TAG = "WireGuard/GoBackend";
+ private static final int STATS_TAG = 2;
@Nullable private static AlwaysOnCallback alwaysOnCallback;
private static GhettoCompletableFuture<VpnService> vpnService = new GhettoCompletableFuture<>();
private final Context context;
@@ -305,6 +307,7 @@ public final class GoBackend implements Backend {
StringBuffer buf = new StringBuffer();
try {
URL url = new URL(pacFileUrl.toString());
+ TrafficStats.setThreadStatsTag(STATS_TAG);
urlConnection = (HttpURLConnection) network.openConnection(url);
InputStream in = urlConnection.getInputStream();
diff --git a/tunnel/src/main/java/com/wireguard/util/Resolver.java b/tunnel/src/main/java/com/wireguard/util/Resolver.java
index 62b11286..24f5ab88 100644
--- a/tunnel/src/main/java/com/wireguard/util/Resolver.java
+++ b/tunnel/src/main/java/com/wireguard/util/Resolver.java
@@ -17,6 +17,7 @@ import java.net.UnknownHostException;
import android.net.IpPrefix;
import android.net.LinkProperties;
import android.net.Network;
+import android.net.TrafficStats;
import android.util.Log;
import androidx.annotation.Nullable;
@@ -24,6 +25,7 @@ import androidx.annotation.Nullable;
@NonNullForAll
public class Resolver {
private static final String TAG = "WireGuard/Resolver";
+ private static final int STATS_TAG = 3; // FIXME
@Nullable private final Network network;
@Nullable private final LinkProperties linkProps;
@Nullable private IpPrefix nat64Prefix;
@@ -82,6 +84,7 @@ public class Resolver {
}
public InetAddress resolve(String host) throws UnknownHostException {
+ TrafficStats.setThreadStatsTag(STATS_TAG);
final InetAddress[] candidates = network != null ? network.getAllByName(host) : InetAddress.getAllByName(host);
InetAddress address = candidates[0];
for (final InetAddress candidate : candidates) {
@@ -89,6 +92,7 @@ public class Resolver {
try {
sock = new DatagramSocket();
+ TrafficStats.tagDatagramSocket(sock);
if (network != null) {
network.bindSocket(sock);
}