Skip to content

Commit

Permalink
DNSProxy -> DNSResolver; clenaup unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmold committed Feb 16, 2022
1 parent 5142d0e commit e4454a6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 128 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.torproject.android.service.vpn;

import org.xbill.DNS.Message;
import org.xbill.DNS.SimpleResolver;

import java.io.IOException;

public class DNSResolver {

private final SimpleResolver mResolver;

public DNSResolver(String localDns, int localPort) throws IOException {
mResolver = new SimpleResolver(localDns);
mResolver.setPort(localPort);
}

public byte[] processDNS(byte[] payload) throws IOException {
Message msgRequest = new Message(payload);

if (msgRequest.getQuestion() != null) {
Message queryMessage = Message.newQuery(msgRequest.getQuestion());
Message answer = mResolver.send(queryMessage);
return answer.toWire();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class OrbotVpnManager implements Handler.Callback {
private ProxyServer mSocksProxyServer;
private final VpnService mService;
private final SharedPreferences prefs;
private DNSProxy mDnsProxy;
private DNSResolver mDnsResolver;

private final ExecutorService mExec = Executors.newFixedThreadPool(10);
private Thread mThreadPacket;
Expand Down Expand Up @@ -210,11 +210,6 @@ private void stopVPN() {
}
}

if (mDnsProxy != null) {
mDnsProxy.stopProxy();
mDnsProxy = null;
}

if (mThreadPacket != null && mThreadPacket.isAlive()) {
mThreadPacket.interrupt();
}
Expand Down Expand Up @@ -294,7 +289,7 @@ private synchronized void setupTun2Socks(final VpnService.Builder builder) {
FileInputStream fis = new FileInputStream(mInterface.getFileDescriptor());
DataOutputStream fos = new DataOutputStream(new FileOutputStream(mInterface.getFileDescriptor()));

mDnsProxy = new DNSProxy(localhost, mTorDns);
mDnsResolver = new DNSResolver(localhost, mTorDns);

//write packets back out to TUN
PacketFlow pFlow = (PacketFlow) packet -> {
Expand Down Expand Up @@ -327,7 +322,7 @@ public void run () {
if (packet instanceof IpPacket) {
IpPacket ipPacket = (IpPacket) packet;
if (isPacketDNS(ipPacket))
mExec.execute(new RequestPacketHandler(ipPacket, pFlow, mDnsProxy));
mExec.execute(new RequestPacketHandler(ipPacket, pFlow, mDnsResolver));
else
IPtProxy.inputPacket(pdata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,35 @@
import android.util.Log;

import org.pcap4j.packet.DnsPacket;
import org.pcap4j.packet.IllegalRawDataException;
import org.pcap4j.packet.IpPacket;
import org.pcap4j.packet.IpSelector;
import org.pcap4j.packet.IpV4Packet;
import org.pcap4j.packet.IpV6Packet;
import org.pcap4j.packet.Packet;
import org.pcap4j.packet.UdpPacket;
import org.pcap4j.packet.UnknownPacket;
import org.pcap4j.packet.namednumber.IpNumber;
import org.pcap4j.packet.namednumber.UdpPort;

import java.net.Inet6Address;

import IPtProxy.PacketFlow;
import IPtProxy.IPtProxy;


public class RequestPacketHandler implements Runnable {

IpPacket packet;
PacketFlow pFlow;
DNSProxy mDnsProxy;
DNSResolver mDnsResolver;

public RequestPacketHandler (IpPacket packet, PacketFlow pFLow, DNSProxy dnsProxy)
public RequestPacketHandler (IpPacket packet, PacketFlow pFLow, DNSResolver dnsResolver)
{
this.packet = packet;
this.pFlow = pFLow;
this.mDnsProxy = dnsProxy;
this.mDnsResolver = dnsResolver;
}
public void run() {


try {
UdpPacket udpPacket = (UdpPacket) packet.getPayload();

byte[] dnsResp = mDnsProxy.processDNS(udpPacket.getPayload().getRawData());
byte[] dnsResp = mDnsResolver.processDNS(udpPacket.getPayload().getRawData());

if (dnsResp != null) {

Expand Down

0 comments on commit e4454a6

Please sign in to comment.