use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.
the class ExtendedLRUCache method gather.
private final void gather(Map<DNSMessage, List<Record<? extends Data>>> extraCaches, DNSMessage q, List<Record<? extends Data>> records, DNSName authoritativeZone) {
for (Record<? extends Data> extraRecord : records) {
if (!shouldGather(extraRecord, q.getQuestion(), authoritativeZone))
continue;
DNSMessage.Builder additionalRecordQuestionBuilder = extraRecord.getQuestionMessage();
if (additionalRecordQuestionBuilder == null)
continue;
additionalRecordQuestionBuilder.copyFlagsFrom(q);
additionalRecordQuestionBuilder.setAdditionalResourceRecords(q.additionalSection);
DNSMessage additionalRecordQuestion = additionalRecordQuestionBuilder.build();
if (additionalRecordQuestion.equals(q)) {
// No need to cache the additional question if it is the same as the original question.
continue;
}
List<Record<? extends Data>> additionalRecords = extraCaches.get(additionalRecordQuestion);
if (additionalRecords == null) {
additionalRecords = new LinkedList<>();
extraCaches.put(additionalRecordQuestion, additionalRecords);
}
additionalRecords.add(extraRecord);
}
}
use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.
the class LRUCache method getNormalized.
@Override
protected synchronized DNSMessage getNormalized(DNSMessage q) {
DNSMessage message = backend.get(q);
if (message == null) {
missCount++;
return null;
}
long ttl = maxTTL;
// shortest TTL to be the effective one.
for (Record<? extends Data> r : message.answerSection) {
ttl = Math.min(ttl, r.ttl);
}
if (message.receiveTimestamp + ttl < System.currentTimeMillis()) {
missCount++;
expireCount++;
backend.remove(q);
return null;
} else {
hitCount++;
return message;
}
}
use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.
the class AbstractDNSClient method queryAsync.
/**
* Default implementation of an asynchronous DNS query which just wraps the synchronous case.
* <p>
* Subclasses override this method to support true asynchronous queries.
* </p>
*
* @param query the query.
* @return a future for this query.
*/
protected MiniDnsFuture<DNSMessage, IOException> queryAsync(DNSMessage.Builder query) {
InternalMiniDnsFuture<DNSMessage, IOException> future = new InternalMiniDnsFuture<>();
DNSMessage result;
try {
result = query(query);
} catch (IOException e) {
future.setException(e);
return future;
}
future.setResult(result);
return future;
}
use of org.minidns.dnsmessage.DNSMessage 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