test_class.declarator: mockEventLoop
test_class.modifier: private
test_class.original_string: private MockEventLoop mockEventLoop;
test_class.type: MockEventLoop
test_class.var_name: mockEventLoop
test_class.declarator: dnsPacketProxy
test_class.modifier: private
test_class.original_string: private DnsPacketProxy dnsPacketProxy;
test_class.type: DnsPacketProxy
test_class.var_name: dnsPacketProxy
test_class.declarator: ruleDatabase
test_class.modifier: private
test_class.original_string: private RuleDatabase ruleDatabase;
test_class.type: RuleDatabase
test_class.var_name: ruleDatabase
test_class.file: app/src/test/java/org/jak_linux/dns66/vpn/DnsPacketProxyTest.java
test_class.identifier: DnsPacketProxyTest
test_case.body: @Test
      public void testDnsQuery() throws Exception {
          Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
                  0x01,
                  3600,
                  Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
          ));
  
          UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
                  .srcPort(UdpPort.DOMAIN)
                  .dstPort(UdpPort.DOMAIN)
                  .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
                  .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
                  .correctChecksumAtBuild(true)
                  .correctLengthAtBuild(true)
                  .payloadBuilder(
                          new UnknownPacket.Builder()
                                  .rawData(message.toWire())
                  );
  
          IpPacket ipOutPacket = new IpV4Packet.Builder()
                  .version(IpVersion.IPV4)
                  .tos(IpV4Rfc791Tos.newInstance((byte) 0))
                  .protocol(IpNumber.UDP)
                  .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
                  .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
                  .correctChecksumAtBuild(true)
                  .correctLengthAtBuild(true)
                  .payloadBuilder(payLoadBuilder)
                  .build();
  
          dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
  
          assertNull(mockEventLoop.lastResponse);
          assertNotNull(mockEventLoop.lastOutgoing);
          assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
      }
test_case.class_method_signature: DnsPacketProxyTest.testDnsQuery()
test_case.full_signature: @Test public void testDnsQuery()
test_case.identifier: testDnsQuery
test_case.invocations: newQuery getByAddress payloadBuilder correctLengthAtBuild correctChecksumAtBuild dstAddr srcAddr dstPort srcPort getByAddress getByAddress rawData toWire build payloadBuilder correctLengthAtBuild correctChecksumAtBuild dstAddr srcAddr protocol tos version newInstance getByAddress getByAddress handleDnsRequest getRawData assertNull assertNotNull assertEquals getByAddress getAddress
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDnsQuery()
focal_class.declarator: TAG = "DnsPacketProxy"
focal_class.modifier: private static final
focal_class.original_string: private static final String TAG = "DnsPacketProxy";
focal_class.type: String
focal_class.var_name: TAG
focal_class.declarator: NEGATIVE_CACHE_TTL_SECONDS = 5
focal_class.modifier: private static final
focal_class.original_string: private static final int NEGATIVE_CACHE_TTL_SECONDS = 5;
focal_class.type: int
focal_class.var_name: NEGATIVE_CACHE_TTL_SECONDS
focal_class.declarator: NEGATIVE_CACHE_SOA_RECORD
focal_class.modifier: private static final
focal_class.original_string: private static final SOARecord NEGATIVE_CACHE_SOA_RECORD;
focal_class.type: SOARecord
focal_class.var_name: NEGATIVE_CACHE_SOA_RECORD
focal_class.declarator: ruleDatabase
focal_class.modifier: final
focal_class.original_string: final RuleDatabase ruleDatabase;
focal_class.type: RuleDatabase
focal_class.var_name: ruleDatabase
focal_class.declarator: eventLoop
focal_class.modifier: private final
focal_class.original_string: private final EventLoop eventLoop;
focal_class.type: EventLoop
focal_class.var_name: eventLoop
focal_class.declarator: upstreamDnsServers = new ArrayList<>()
focal_class.original_string: ArrayList<InetAddress> upstreamDnsServers = new ArrayList<>();
focal_class.type: ArrayList<InetAddress>
focal_class.var_name: upstreamDnsServers
focal_class.file: app/src/main/java/org/jak_linux/dns66/vpn/DnsPacketProxy.java
focal_class.identifier: DnsPacketProxy
focal_class.class_method_signature: DnsPacketProxy.DnsPacketProxy(EventLoop eventLoop, RuleDatabase database)
focal_class.full_signature: public  DnsPacketProxy(EventLoop eventLoop, RuleDatabase database)
focal_class.identifier: DnsPacketProxy
focal_class.modifiers: public
focal_class.parameters: (EventLoop eventLoop, RuleDatabase database)
focal_class.signature:  DnsPacketProxy(EventLoop eventLoop, RuleDatabase database)
focal_class.class_method_signature: DnsPacketProxy.DnsPacketProxy(EventLoop eventLoop)
focal_class.full_signature: public  DnsPacketProxy(EventLoop eventLoop)
focal_class.identifier: DnsPacketProxy
focal_class.modifiers: public
focal_class.parameters: (EventLoop eventLoop)
focal_class.signature:  DnsPacketProxy(EventLoop eventLoop)
focal_class.class_method_signature: DnsPacketProxy.initialize(Context context, ArrayList<InetAddress> upstreamDnsServers)
focal_class.full_signature:  void initialize(Context context, ArrayList<InetAddress> upstreamDnsServers)
focal_class.identifier: initialize
focal_class.parameters: (Context context, ArrayList<InetAddress> upstreamDnsServers)
focal_class.return: void
focal_class.signature: void initialize(Context context, ArrayList<InetAddress> upstreamDnsServers)
focal_class.class_method_signature: DnsPacketProxy.handleDnsResponse(IpPacket requestPacket, byte[] responsePayload)
focal_class.full_signature:  void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload)
focal_class.identifier: handleDnsResponse
focal_class.parameters: (IpPacket requestPacket, byte[] responsePayload)
focal_class.return: void
focal_class.signature: void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload)
focal_class.class_method_signature: DnsPacketProxy.handleDnsRequest(byte[] packetData)
focal_class.full_signature:  void handleDnsRequest(byte[] packetData)
focal_class.identifier: handleDnsRequest
focal_class.parameters: (byte[] packetData)
focal_class.return: void
focal_class.signature: void handleDnsRequest(byte[] packetData)
focal_class.class_method_signature: DnsPacketProxy.translateDestinationAdress(IpPacket parsedPacket)
focal_class.full_signature: private InetAddress translateDestinationAdress(IpPacket parsedPacket)
focal_class.identifier: translateDestinationAdress
focal_class.modifiers: private
focal_class.parameters: (IpPacket parsedPacket)
focal_class.return: InetAddress
focal_class.signature: InetAddress translateDestinationAdress(IpPacket parsedPacket)
focal_method.body: void handleDnsRequest(byte[] packetData) throws AdVpnThread.VpnNetworkException {
  
          IpPacket parsedPacket = null;
          try {
              parsedPacket = (IpPacket) IpSelector.newPacket(packetData, 0, packetData.length);
          } catch (Exception e) {
              Log.i(TAG, "handleDnsRequest: Discarding invalid IP packet", e);
              return;
          }
  
          UdpPacket parsedUdp;
          Packet udpPayload;
  
          try {
              parsedUdp = (UdpPacket) parsedPacket.getPayload();
              udpPayload = parsedUdp.getPayload();
          } catch (Exception e) {
              try {
                  Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getHeader(), e);
              } catch (Exception e1) {
                  Log.i(TAG, "handleDnsRequest: Discarding unknown packet type, could not log packet info", e1);
              }
              return;
          }
  
          InetAddress destAddr = translateDestinationAdress(parsedPacket);
          if (destAddr == null)
              return;
  
          if (udpPayload == null) {
              try {
                  Log.i(TAG, "handleDnsRequest: Sending UDP packet without payload: " + parsedUdp);
              } catch (Exception e1) {
                  Log.i(TAG, "handleDnsRequest: Sending UDP packet without payload");
              }
  
              // Let's be nice to Firefox. Firefox uses an empty UDP packet to
              // the gateway to reduce the RTT. For further details, please see
              // https://bugzilla.mozilla.org/show_bug.cgi?id=888268
              try {
                  DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0 /* length */, destAddr, parsedUdp.getHeader().getDstPort().valueAsInt());
                  eventLoop.forwardPacket(outPacket, null);
              } catch (Exception e) {
                  Log.i(TAG, "handleDnsRequest: Could not send empty UDP packet", e);
              }
              return;
          }
  
          byte[] dnsRawData = udpPayload.getRawData();
          Message dnsMsg;
          try {
              dnsMsg = new Message(dnsRawData);
          } catch (IOException e) {
              Log.i(TAG, "handleDnsRequest: Discarding non-DNS or invalid packet", e);
              return;
          }
          if (dnsMsg.getQuestion() == null) {
              Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
              return;
          }
          String dnsQueryName = dnsMsg.getQuestion().getName().toString(true);
          if (!ruleDatabase.isBlocked(dnsQueryName.toLowerCase(Locale.ENGLISH))) {
              Log.i(TAG, "handleDnsRequest: DNS Name " + dnsQueryName + " Allowed, sending to " + destAddr);
              DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr, parsedUdp.getHeader().getDstPort().valueAsInt());
              eventLoop.forwardPacket(outPacket, parsedPacket);
          } else {
              Log.i(TAG, "handleDnsRequest: DNS Name " + dnsQueryName + " Blocked!");
              dnsMsg.getHeader().setFlag(Flags.QR);
              dnsMsg.getHeader().setRcode(Rcode.NOERROR);
              dnsMsg.addRecord(NEGATIVE_CACHE_SOA_RECORD, Section.AUTHORITY);
              handleDnsResponse(parsedPacket, dnsMsg.toWire());
          }
      }
focal_method.class_method_signature: DnsPacketProxy.handleDnsRequest(byte[] packetData)
focal_method.full_signature:  void handleDnsRequest(byte[] packetData)
focal_method.identifier: handleDnsRequest
focal_method.invocations: newPacket i getPayload getPayload i getHeader i translateDestinationAdress i i valueAsInt getDstPort getHeader forwardPacket i getRawData i getQuestion i toString getName getQuestion isBlocked toLowerCase i valueAsInt getDstPort getHeader forwardPacket i setFlag getHeader setRcode getHeader addRecord handleDnsResponse toWire
focal_method.parameters: (byte[] packetData)
focal_method.return: void
focal_method.signature: void handleDnsRequest(byte[] packetData)