summaryrefslogtreecommitdiff
path: root/app/java/src/DNSProxyRunner.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/java/src/DNSProxyRunner.java')
-rw-r--r--app/java/src/DNSProxyRunner.java28
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);
}
}