summaryrefslogtreecommitdiff
path: root/app/java/src/DNSProxyRunner.java
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-05-11 20:03:37 +0200
committerDaniel Weipert <code@drogueronin.de>2023-05-11 20:03:37 +0200
commiteefe2bdea6e79548ef5a0c0a50b3afc495b034b3 (patch)
tree1ba6f80cd8d2a56de3b0e9a0029603dbd9ff57c6 /app/java/src/DNSProxyRunner.java
parent9919df9457d95e5bd156f313549c8d8b26f09f24 (diff)
next commit
Diffstat (limited to 'app/java/src/DNSProxyRunner.java')
-rw-r--r--app/java/src/DNSProxyRunner.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/java/src/DNSProxyRunner.java b/app/java/src/DNSProxyRunner.java
new file mode 100644
index 0000000..0c136e8
--- /dev/null
+++ b/app/java/src/DNSProxyRunner.java
@@ -0,0 +1,53 @@
+package org.pihole.dnsproxy;
+
+import android.os.ParcelFileDescriptor;
+
+import android.util.Log;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import java.nio.channels.DatagramChannel;
+
+public class DNSProxyRunner implements Runnable {
+ public interface OnEstablishListener {
+ void onEstablish(ParcelFileDescriptor networkInterface);
+ }
+ private OnEstablishListener onEstablishListener;
+
+ private DNSProxyService service;
+
+ DNSProxyRunner(DNSProxyService service) {
+ this.service = service;
+ }
+
+ @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);
+ }
+ }
+
+ public void setOnEstablishListener(OnEstablishListener listener) {
+ this.onEstablishListener = listener;
+ }
+}