diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-05-12 13:12:57 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-05-12 13:12:57 +0200 |
commit | 7f0436aa2a782d926a81bd5bdf76baf0253582da (patch) | |
tree | 2f6e86364060ff8ee11a948febbac6a3f451f4e3 /app/java/src/DNSProxyRunner.java | |
parent | eefe2bdea6e79548ef5a0c0a50b3afc495b034b3 (diff) |
working commit
Diffstat (limited to 'app/java/src/DNSProxyRunner.java')
-rw-r--r-- | app/java/src/DNSProxyRunner.java | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/app/java/src/DNSProxyRunner.java b/app/java/src/DNSProxyRunner.java index 0c136e8..6a45413 100644 --- a/app/java/src/DNSProxyRunner.java +++ b/app/java/src/DNSProxyRunner.java @@ -1,5 +1,7 @@ package org.pihole.dnsproxy; +import android.net.VpnService; + import android.os.ParcelFileDescriptor; import android.util.Log; @@ -14,6 +16,7 @@ import java.net.SocketAddress; import java.nio.channels.DatagramChannel; public class DNSProxyRunner implements Runnable { + public interface OnEstablishListener { void onEstablish(ParcelFileDescriptor networkInterface); } @@ -28,22 +31,15 @@ public class DNSProxyRunner implements Runnable { @Override public void run() { try { - DatagramChannel tunnel = DatagramChannel.open(); - - if(!this.service.protect(tunnel.socket())) { - throw new IllegalStateException("Cannot protect tunnel"); - } - - // SocketAddress server = new InetSocketAddress("servername", "serverport"); - // - // tunnel.connect(server); - // tunnel.configureBlocking(false); - // - // ParcelFileDescriptor networkInterface = this.handshake(tunnel); - // FileInputStream in = new FileInputStream(networkInterface.getFileDescriptor()); - // FileOutputStream out = new FileOutputStream(networkInterface.getFileDescriptor()); - } catch (IOException exception) { - Log.e(DNSProxyService.LOG_TAG, "Cannot use socket", exception); + VpnService.Builder builder = this.service.newBuilder() + .setSession("Pihole DNS Proxy") + .addAddress("10.111.222.1", 24) + .addDnsServer(DNSProxyService.PIHOLE_ADDRESS) + .setBlocking(true); + + this.onEstablishListener.onEstablish(builder.establish()); + } catch (Exception exception) { + Log.e(DNSProxyService.LOG_TAG, "Failed to establish VPN connection", exception); } } |