Search in sources :

Example 21 with Question

use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.

the class DNSWorld method applyZones.

public static DNSWorld applyZones(AbstractDNSClient client, Zone... zones) {
    DNSWorld world = new DNSWorld();
    client.setDataSource(world);
    for (Zone zone : zones) {
        for (RRSet rrSet : zone.getRRSets()) {
            DNSMessage.Builder req = client.buildMessage(new Question(rrSet.name, rrSet.type, rrSet.clazz, false));
            DNSMessage.Builder resp = DNSMessage.builder();
            resp.setAnswers(rrSet.records);
            resp.setAuthoritativeAnswer(true);
            attachGlues(resp, rrSet.records, zone.records);
            attachSignatures(resp, zone.records);
            DNSMessage request = req.build();
            DNSMessage response = resp.build();
            if (zone.isRootZone()) {
                world.addPreparedResponse(new RootAnswerResponse(request, response));
            } else {
                world.addPreparedResponse(new AddressedAnswerResponse(zone.address, request, response));
            }
            if (rrSet.type == TYPE.NS) {
                DNSMessage.Builder hintsResp = DNSMessage.builder();
                hintsResp.setNameserverRecords(rrSet.records);
                hintsResp.setAdditionalResourceRecords(response.additionalSection);
                DNSMessage hintsResponse = hintsResp.build();
                if (zone.isRootZone()) {
                    world.addPreparedResponse(new RootHintsResponse(rrSet.name, hintsResponse));
                } else {
                    world.addPreparedResponse(new AddressedHintsResponse(zone.address, rrSet.name, hintsResponse));
                }
            }
        }
    }
    return world;
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 22 with Question

use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.

the class LRUCacheTest method testOutdatedCacheEntry.

@Test
public void testOutdatedCacheEntry() {
    DNSMessage message = createSampleMessage(1);
    Question q = new Question("", Record.TYPE.A);
    DNSMessage question = q.asQueryMessage();
    lruCache.put(question, message);
    assertNull(lruCache.get(question));
    assertNull(lruCache.get(question));
    assertEquals(1, lruCache.getExpireCount());
    assertEquals(2, lruCache.getMissCount());
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 23 with Question

use of org.minidns.dnsmessage.Question in project Smack by igniterealtime.

the class MiniDnsResolver method getExceptionFrom.

private static ResolutionUnsuccessfulException getExceptionFrom(ResolverResult<?> result) {
    Question question = result.getQuestion();
    RESPONSE_CODE responseCode = result.getResponseCode();
    ResolutionUnsuccessfulException resolutionUnsuccessfulException = new ResolutionUnsuccessfulException(question, responseCode);
    return resolutionUnsuccessfulException;
}
Also used : RESPONSE_CODE(org.minidns.dnsmessage.DnsMessage.RESPONSE_CODE) ResolutionUnsuccessfulException(org.minidns.hla.ResolutionUnsuccessfulException) Question(org.minidns.dnsmessage.Question)

Example 24 with Question

use of org.minidns.dnsmessage.Question in project Smack by igniterealtime.

the class DnsOverXmppMiniDnsResolver method resolve.

@Override
public DnsMessage resolve(DnsMessage query) throws IOException {
    Question question = query.getQuestion();
    final DnsQueryResult dnsQueryResult;
    if (query.isDnssecOk()) {
        DnssecQueryResult dnssecQueryResult = dnssecClient.queryDnssec(question);
        dnsQueryResult = dnssecQueryResult.dnsQueryResult;
    } else {
        dnsQueryResult = dnsClient.query(question);
    }
    return dnsQueryResult.response;
}
Also used : DnsQueryResult(org.minidns.dnsqueryresult.DnsQueryResult) DnssecQueryResult(org.minidns.dnssec.DnssecQueryResult) Question(org.minidns.dnsmessage.Question)

Example 25 with Question

use of org.minidns.dnsmessage.Question in project Smack by igniterealtime.

the class DnsOverXmppMiniDnsResolverTest method dnsOverXmppMiniDnsResolverTest.

@Test
public void dnsOverXmppMiniDnsResolverTest() throws IOException {
    TestDnsDataSource dnsSource = new TestDnsDataSource();
    TestDnsDataSource dnssecSource = new TestDnsDataSource();
    DnsClient dnsClient = new DnsClient(NoopDnsCache.INSTANCE);
    dnsClient.setDataSource(dnsSource);
    DnssecClient dnssecClient = new DnssecClient(NoopDnsCache.INSTANCE);
    dnssecClient.setDataSource(dnssecSource);
    DnsOverXmppMiniDnsResolver doxResolver = new DnsOverXmppMiniDnsResolver(dnsClient, dnssecClient);
    Question question = new Question("example.org", TYPE.A);
    {
        DnsMessage nondnssecQuery = question.asQueryMessage();
        doxResolver.resolve(nondnssecQuery);
        assertTrue(dnsSource.getAndResetWasQueried());
        assertFalse(dnssecSource.getAndResetWasQueried());
    }
    {
        DnsMessage.Builder dnssecQueryBuilder = question.asMessageBuilder();
        dnssecQueryBuilder.getEdnsBuilder().setDnssecOk();
        DnsMessage dnssecQuery = dnssecQueryBuilder.build();
        DnssecValidationFailedException dnssecValidationFailedException = null;
        try {
            doxResolver.resolve(dnssecQuery);
        } catch (DnssecValidationFailedException e) {
            dnssecValidationFailedException = e;
        }
        // This exception is expected since we don't have a realy DNS source.
        assertNotNull(dnssecValidationFailedException);
        assertFalse(dnsSource.getAndResetWasQueried());
        assertTrue(dnssecSource.getAndResetWasQueried());
    }
}
Also used : DnssecClient(org.minidns.dnssec.DnssecClient) DnssecValidationFailedException(org.minidns.dnssec.DnssecValidationFailedException) DnsClient(org.minidns.DnsClient) Question(org.minidns.dnsmessage.Question) DnsMessage(org.minidns.dnsmessage.DnsMessage) Test(org.junit.jupiter.api.Test)

Aggregations

Question (org.minidns.dnsmessage.Question)25 DNSMessage (org.minidns.dnsmessage.DNSMessage)15 Test (org.junit.Test)6 IOException (java.io.IOException)4 InetAddress (java.net.InetAddress)4 DNSName (org.minidns.dnsname.DNSName)3 Data (org.minidns.record.Data)3 Record (org.minidns.record.Record)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Level (java.util.logging.Level)2 DnsMessage (org.minidns.dnsmessage.DnsMessage)2 TYPE (org.minidns.record.Record.TYPE)2 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)1 DnsOverXmppManager (org.jivesoftware.smackx.dox.DnsOverXmppManager)1 Test (org.junit.jupiter.api.Test)1 Jid (org.jxmpp.jid.Jid)1 DNSClient (org.minidns.DNSClient)1 DnsClient (org.minidns.DnsClient)1 Builder (org.minidns.dnsmessage.DNSMessage.Builder)1