From d8056a134b0021650cef914d0985e556802c095e Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Thu, 10 Nov 2022 23:26:24 +0100 Subject: ui,tunnel: add lastest handshake to peer details Signed-off-by: Mikael Magnusson --- .../com/wireguard/android/backend/GoBackend.java | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java') 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 cf98e106..968f2ade 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -49,6 +49,8 @@ import io.grpc.ManagedChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.stub.StreamObserver; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -179,10 +181,17 @@ public final class GoBackend implements Backend { Key key = null; long rx = 0; long tx = 0; + long handshakeSec = 0; + int handshakeNSec = 0; for (final String line : config.split("\\n")) { if (line.startsWith("public_key=")) { - if (key != null) - stats.add(key, rx, tx); + if (key != null) { + LocalDateTime handshake = null; + if (handshakeSec > 0) { + handshake = LocalDateTime.ofEpochSecond(handshakeSec, handshakeNSec, ZoneOffset.UTC); + } + stats.add(key, rx, tx, handshake); + } rx = 0; tx = 0; try { @@ -206,10 +215,31 @@ public final class GoBackend implements Backend { } catch (final NumberFormatException ignored) { tx = 0; } + } else if (line.startsWith("last_handshake_time_sec=")) { + if (key == null) + continue; + try { + handshakeSec = Long.parseLong(line.substring(24)); + } catch (final NumberFormatException ignored) { + handshakeSec = 0; + } + } else if (line.startsWith("last_handshake_time_nsec=")) { + if (key == null) + continue; + try { + handshakeNSec = Integer.parseInt(line.substring(25)); + } catch (final NumberFormatException ignored) { + handshakeNSec = 0; + } + } + } + if (key != null) { + LocalDateTime handshake = null; + if (handshakeSec > 0) { + handshake = LocalDateTime.ofEpochSecond(handshakeSec, handshakeNSec, ZoneOffset.UTC); } + stats.add(key, rx, tx, handshake); } - if (key != null) - stats.add(key, rx, tx); return stats; } -- cgit v1.2.3