Update Pcap4J and fixed DNS test
This commit is contained in:
parent
c376c61b65
commit
d0c03dfe8e
@ -48,8 +48,8 @@ dependencies {
|
||||
compile 'com.android.support:percent:25.3.1'
|
||||
compile 'com.android.support:cardview-v7:25.3.1'
|
||||
|
||||
compile 'org.pcap4j:pcap4j-core:1.7.0'
|
||||
compile 'org.pcap4j:pcap4j-packetfactory-propertiesbased:1.7.0'
|
||||
compile 'org.pcap4j:pcap4j-core:1.7.1'
|
||||
compile 'org.pcap4j:pcap4j-packetfactory-static:1.7.1'
|
||||
compile 'de.measite.minidns:minidns-core:0.2.2'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
|
||||
|
@ -163,7 +163,9 @@ public class DNSTestFragment extends ToolbarFragment {
|
||||
message.addQuestion(new Question(domain, type));
|
||||
message.setId((new Random()).nextInt());
|
||||
message.setRecursionDesired(true);
|
||||
message.getEdnsBuilder().setUdpPayloadSize(1024).setDnssecOk(false);
|
||||
message.setOpcode(DNSMessage.OPCODE.QUERY);
|
||||
message.setResponseCode(DNSMessage.RESPONSE_CODE.NO_ERROR);
|
||||
message.setQrFlag(false);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
DNSMessage response = dnsQuery.query(message.build(), InetAddress.getByName(server.getAddress()), server.getPort());
|
||||
|
@ -111,9 +111,6 @@ public class TcpProvider extends UdpProvider {
|
||||
Log.d(TAG, "Read from device");
|
||||
readPacketFromDevice(inputStream, packet);
|
||||
}
|
||||
|
||||
checkCache();
|
||||
|
||||
service.providerLoopCallback();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -16,14 +16,11 @@ import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.RuleResolver;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.pcap4j.packet.*;
|
||||
import org.pcap4j.packet.factory.PacketFactoryPropertiesLoader;
|
||||
import org.pcap4j.util.PropertiesLoader;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@ -49,11 +46,6 @@ public class UdpProvider extends Provider {
|
||||
FileDescriptor mInterruptFd = null;
|
||||
final Queue<byte[]> deviceWrites = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* Number of iterations since we last cleared the pcap4j cache
|
||||
*/
|
||||
private int pcap4jFactoryClearCacheCounter = 0;
|
||||
|
||||
public UdpProvider(ParcelFileDescriptor descriptor, DaedalusVpnService service) {
|
||||
super(descriptor, service);
|
||||
}
|
||||
@ -148,8 +140,6 @@ public class UdpProvider extends Provider {
|
||||
Log.d(TAG, "Read from device");
|
||||
readPacketFromDevice(inputStream, packet);
|
||||
}
|
||||
|
||||
checkCache();
|
||||
service.providerLoopCallback();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -157,25 +147,6 @@ public class UdpProvider extends Provider {
|
||||
}
|
||||
}
|
||||
|
||||
void checkCache() {
|
||||
// pcap4j has some sort of properties cache in the packet factory. This cache leaks, so
|
||||
// we need to clean it up.
|
||||
if (++pcap4jFactoryClearCacheCounter % 1024 == 0) {
|
||||
try {
|
||||
PacketFactoryPropertiesLoader l = PacketFactoryPropertiesLoader.getInstance();
|
||||
Field field = l.getClass().getDeclaredField("loader");
|
||||
field.setAccessible(true);
|
||||
PropertiesLoader loader = (PropertiesLoader) field.get(l);
|
||||
Log.d(TAG, "Cleaning cache");
|
||||
loader.clearCache();
|
||||
} catch (NoSuchFieldException e) {
|
||||
Log.e(TAG, "Cannot find declared loader field", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "Cannot get declared loader field", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeToDevice(FileOutputStream outFd) throws DaedalusVpnService.VpnNetworkException {
|
||||
try {
|
||||
outFd.write(deviceWrites.poll());
|
||||
|
Loading…
Reference in New Issue
Block a user