From 3b117e4ad2a0f927262597ebbebd9e89a90e6619 Mon Sep 17 00:00:00 2001 From: jyyi1 Date: Wed, 21 Feb 2024 14:22:15 -0500 Subject: [PATCH] make Probe a global function instead of DoHServer's --- Android/app/src/go/backend/doh.go | 4 ++-- Android/app/src/go/doh/doh.go | 2 +- .../main/java/app/intra/net/go/GoProber.java | 3 ++- .../java/app/intra/net/go/GoVpnAdapter.java | 20 +++++++++---------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Android/app/src/go/backend/doh.go b/Android/app/src/go/backend/doh.go index 831719de..6334e2bd 100644 --- a/Android/app/src/go/backend/doh.go +++ b/Android/app/src/go/backend/doh.go @@ -71,10 +71,10 @@ var dohQuery = []byte{ 0, 1, // QCLASS = IN (Internet) } -// Probe checks if this server can handle DNS-over-HTTPS (DoH) requests. +// Probe checks whether the [DoHServer] server can handle DNS-over-HTTPS (DoH) requests. // // If the server responds correctly, the function returns nil. Otherwise, the function returns an error. -func (s *DoHServer) Probe() error { +func Probe(s *DoHServer) error { resp, err := s.r.Query(context.Background(), dohQuery) if err != nil { return fmt.Errorf("failed to send query: %w", err) diff --git a/Android/app/src/go/doh/doh.go b/Android/app/src/go/doh/doh.go index 71686267..cb7abf19 100644 --- a/Android/app/src/go/doh/doh.go +++ b/Android/app/src/go/doh/doh.go @@ -70,7 +70,7 @@ type Summary struct { } // A Token is an opaque handle used to match responses to queries. -type Token = interface{} +type Token interface{} // Listener receives Summaries. type Listener interface { diff --git a/Android/app/src/main/java/app/intra/net/go/GoProber.java b/Android/app/src/main/java/app/intra/net/go/GoProber.java index c2f4ea25..261dcba1 100644 --- a/Android/app/src/main/java/app/intra/net/go/GoProber.java +++ b/Android/app/src/main/java/app/intra/net/go/GoProber.java @@ -20,6 +20,7 @@ import android.os.Build.VERSION_CODES; import app.intra.net.doh.Prober; import app.intra.sys.VpnController; +import backend.Backend; import backend.DoHServer; import protect.Protector; @@ -42,7 +43,7 @@ public void probe(String url, Callback callback) { // Protection isn't needed for Lollipop+, or if the VPN is not active. Protector protector = VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP ? null : VpnController.getInstance().getIntraVpnService(); - Probe(new DoHServer(url, dohIPs, protector, null)); + Backend.probe(new DoHServer(url, dohIPs, protector, null)); callback.onCompleted(true); } catch (Exception e) { callback.onCompleted(false); diff --git a/Android/app/src/main/java/app/intra/net/go/GoVpnAdapter.java b/Android/app/src/main/java/app/intra/net/go/GoVpnAdapter.java index 29c0220a..6b0d379e 100644 --- a/Android/app/src/main/java/app/intra/net/go/GoVpnAdapter.java +++ b/Android/app/src/main/java/app/intra/net/go/GoVpnAdapter.java @@ -88,7 +88,7 @@ String make(String template) { private ParcelFileDescriptor tunFd; // The Intra session object from go-tun2socks. Initially null. - private Session tunnel; + private Session session; private GoIntraListener listener; public static GoVpnAdapter establish(@NonNull IntraVpnService vpnService) { @@ -109,7 +109,7 @@ public synchronized void start() { } private void connectTunnel() { - if (tunnel != null) { + if (session != null) { return; } // VPN parameters @@ -123,7 +123,7 @@ private void connectTunnel() { LogWrapper.log(Log.INFO, LOG_TAG, "Starting go-tun2socks"); DoHServer server = makeDoHServer(dohURL); // connectIntraTunnel makes a copy of the file descriptor. - tunnel = Backend.connectSession(tunFd.getFd(), fakeDns, + session = Backend.connectSession(tunFd.getFd(), fakeDns, server, getProtector(), listener); } catch (Exception e) { LogWrapper.logException(e); @@ -150,7 +150,7 @@ private void enableChoir() { } String file = vpnService.getFilesDir() + File.separator + CHOIR_FILENAME; try { - tunnel.enableSNIReporter(file, "intra.metrics.gstatic.com", country); + session.enableSNIReporter(file, "intra.metrics.gstatic.com", country); } catch (Exception e) { // Choir setup failure is logged but otherwise ignored, because it does not prevent Intra // from functioning correctly. @@ -189,8 +189,8 @@ private static ParcelFileDescriptor establishVpn(IntraVpnService vpnService) { } public synchronized void close() { - if (tunnel != null) { - tunnel.disconnect(); + if (session != null) { + session.disconnect(); } if (tunFd != null) { try { @@ -229,7 +229,7 @@ public synchronized void updateDohUrl() { // Adapter is closed. return; } - if (tunnel == null) { + if (session == null) { // Attempt to re-create the tunnel. Creation may have failed originally because the DoH // server could not be reached. This will update the DoH URL as well. connectTunnel(); @@ -241,11 +241,11 @@ public synchronized void updateDohUrl() { // out. String url = PersistentState.getServerUrl(vpnService); try { - tunnel.setDoHServer(makeDoHServer(url)); + session.setDoHServer(makeDoHServer(url)); } catch (Exception e) { LogWrapper.logException(e); - tunnel.disconnect(); - tunnel = null; + session.disconnect(); + session = null; VpnController.getInstance().onConnectionStateChanged(vpnService, IntraVpnService.State.FAILING); } }