Skip to content

Commit

Permalink
make Probe a global function instead of DoHServer's
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Feb 21, 2024
1 parent 72ef2cd commit 3b117e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Android/app/src/go/backend/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/go/doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion Android/app/src/main/java/app/intra/net/go/GoProber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions Android/app/src/main/java/app/intra/net/go/GoVpnAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -109,7 +109,7 @@ public synchronized void start() {
}

private void connectTunnel() {
if (tunnel != null) {
if (session != null) {
return;
}
// VPN parameters
Expand All @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 3b117e4

Please sign in to comment.