Search in sources :

Example 1 with ResolverApi

use of org.minidns.hla.ResolverApi in project Smack by igniterealtime.

the class MiniDnsResolver method lookupHostAddress0.

@Override
protected List<InetAddress> lookupHostAddress0(final DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
    final ResolverApi resolver = getResolver(dnssecMode);
    final ResolverResult<A> aResult;
    final ResolverResult<AAAA> aaaaResult;
    try {
        aResult = resolver.resolve(name, A.class);
        aaaaResult = resolver.resolve(name, AAAA.class);
    } catch (IOException e) {
        RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
        lookupFailures.add(failure);
        return null;
    }
    if (!aResult.wasSuccessful() && !aaaaResult.wasSuccessful()) {
        // Both results where not successful.
        RemoteConnectionEndpointLookupFailure failureA = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aResult));
        lookupFailures.add(failureA);
        RemoteConnectionEndpointLookupFailure failureAaaa = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aaaaResult));
        lookupFailures.add(failureAaaa);
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, aResult, lookupFailures) || shouldAbortIfNotAuthentic(name, dnssecMode, aaaaResult, lookupFailures)) {
        return null;
    }
    // TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
    Set<A> aResults;
    if (aResult.wasSuccessful()) {
        aResults = aResult.getAnswers();
    } else {
        aResults = Collections.emptySet();
    }
    // TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
    Set<AAAA> aaaaResults;
    if (aaaaResult.wasSuccessful()) {
        aaaaResults = aaaaResult.getAnswers();
    } else {
        aaaaResults = Collections.emptySet();
    }
    List<InetAddress> inetAddresses = new ArrayList<>(aResults.size() + aaaaResults.size());
    for (A a : aResults) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByAddress(a.getIp());
        } catch (UnknownHostException e) {
            continue;
        }
        inetAddresses.add(inetAddress);
    }
    for (AAAA aaaa : aaaaResults) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByAddress(name.ace, aaaa.getIp());
        } catch (UnknownHostException e) {
            continue;
        }
        inetAddresses.add(inetAddress);
    }
    return inetAddresses;
}
Also used : AAAA(org.minidns.record.AAAA) A(org.minidns.record.A) UnknownHostException(java.net.UnknownHostException) RemoteConnectionEndpointLookupFailure(org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure) DnssecResolverApi(org.minidns.hla.DnssecResolverApi) ResolverApi(org.minidns.hla.ResolverApi) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InetAddress(java.net.InetAddress) AAAA(org.minidns.record.AAAA)

Example 2 with ResolverApi

use of org.minidns.hla.ResolverApi in project Smack by igniterealtime.

the class MiniDnsResolver method lookupSrvRecords0.

@Override
protected Set<SRV> lookupSrvRecords0(final DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
    final ResolverApi resolver = getResolver(dnssecMode);
    SrvResolverResult result;
    try {
        result = resolver.resolveSrv(name);
    } catch (IOException e) {
        RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
        lookupFailures.add(failure);
        return null;
    }
    ResolutionUnsuccessfulException resolutionUnsuccessfulException = result.getResolutionUnsuccessfulException();
    if (resolutionUnsuccessfulException != null) {
        RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, resolutionUnsuccessfulException);
        lookupFailures.add(failure);
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, result, lookupFailures)) {
        return null;
    }
    return result.getAnswers();
}
Also used : RemoteConnectionEndpointLookupFailure(org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure) ResolutionUnsuccessfulException(org.minidns.hla.ResolutionUnsuccessfulException) DnssecResolverApi(org.minidns.hla.DnssecResolverApi) ResolverApi(org.minidns.hla.ResolverApi) IOException(java.io.IOException) SrvResolverResult(org.minidns.hla.SrvResolverResult)

Aggregations

IOException (java.io.IOException)2 RemoteConnectionEndpointLookupFailure (org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure)2 DnssecResolverApi (org.minidns.hla.DnssecResolverApi)2 ResolverApi (org.minidns.hla.ResolverApi)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 ResolutionUnsuccessfulException (org.minidns.hla.ResolutionUnsuccessfulException)1 SrvResolverResult (org.minidns.hla.SrvResolverResult)1 A (org.minidns.record.A)1 AAAA (org.minidns.record.AAAA)1