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;
}
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());
}
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;
}
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;
}
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());
}
}
Aggregations