From 80b1e303477b32ff432b7cda04017fa240692a23 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 28 Jan 2023 18:25:15 +0100 Subject: WIP peer status observable --- build.gradle | 1 + tunnel/build.gradle | 1 + tunnel/src/main/java/com/wireguard/config/InetEndpoint.java | 8 ++++++-- ui/src/main/res/layout/tunnel_detail_peer.xml | 6 +++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b9f54f9c..9f72bb30 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,7 @@ buildscript { coordinatorLayoutVersion = '1.2.0' coreKtxVersion = '1.8.0' coroutinesVersion = '1.6.4' + databindingVersion = '7.0.3' datastoreVersion = '1.0.0' desugarVersion = '1.1.5' fragmentVersion = '1.5.1' diff --git a/tunnel/build.gradle b/tunnel/build.gradle index d8aa2497..f9bdeb15 100644 --- a/tunnel/build.gradle +++ b/tunnel/build.gradle @@ -68,6 +68,7 @@ android { dependencies { implementation "androidx.annotation:annotation:$annotationsVersion" implementation "androidx.collection:collection:$collectionVersion" + implementation "androidx.databinding:databinding-runtime:$databindingVersion" implementation "io.grpc:grpc-okhttp:$grpcVersion" implementation "io.grpc:grpc-protobuf-lite:$grpcVersion" implementation "io.grpc:grpc-stub:$grpcVersion" diff --git a/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java index 66855f11..801e2a42 100644 --- a/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java +++ b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java @@ -18,6 +18,7 @@ import java.util.Optional; import java.util.regex.Pattern; import androidx.annotation.Nullable; +import androidx.databinding.BaseObservable; /** @@ -26,7 +27,7 @@ import androidx.annotation.Nullable; * Instances of this class are externally immutable. */ @NonNullForAll -public final class InetEndpoint { +public final class InetEndpoint extends BaseObservable { private static final Pattern BARE_IPV6 = Pattern.compile("^[^\\[\\]]*:[^\\[\\]]*"); private static final Pattern FORBIDDEN_CHARACTERS = Pattern.compile("[/?#]"); @@ -105,8 +106,10 @@ public final class InetEndpoint { } resolved = new InetEndpoint(address.getHostAddress(), true, port); lastResolution = Instant.now(); + notifyChange(); } catch (final UnknownHostException e) { resolved = null; + notifyChange(); } } return Optional.ofNullable(resolved); @@ -121,6 +124,7 @@ public final class InetEndpoint { @Override public String toString() { final boolean isBareIpv6 = isResolved && BARE_IPV6.matcher(host).matches(); - return (isBareIpv6 ? '[' + host + ']' : host) + ':' + port; + String ep = (isBareIpv6 ? '[' + host + ']' : host) + ':' + port; + return (isResolved || resolved == null) ? ep : ep + " (" + resolved.host + ')'; } } diff --git a/ui/src/main/res/layout/tunnel_detail_peer.xml b/ui/src/main/res/layout/tunnel_detail_peer.xml index f295bb13..e5796afd 100644 --- a/ui/src/main/res/layout/tunnel_detail_peer.xml +++ b/ui/src/main/res/layout/tunnel_detail_peer.xml @@ -10,6 +10,10 @@ + +