Search in sources :

Example 1 with ResolverApi

use of de.measite.minidns.hla.ResolverApi in project Smack by igniterealtime.

the class MiniDnsResolver method lookupHostAddress0.

@Override
protected List<InetAddress> lookupHostAddress0(final String name, List<HostAddress> failedAddresses, 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) {
        failedAddresses.add(new HostAddress(name, e));
        return null;
    }
    if (!aResult.wasSuccessful() && !aaaaResult.wasSuccessful()) {
        // Both results where not successful.
        failedAddresses.add(new HostAddress(name, getExceptionFrom(aResult)));
        failedAddresses.add(new HostAddress(name, getExceptionFrom(aaaaResult)));
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, aResult, failedAddresses) || shouldAbortIfNotAuthentic(name, dnssecMode, aaaaResult, failedAddresses)) {
        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, aaaa.getIp());
        } catch (UnknownHostException e) {
            continue;
        }
        inetAddresses.add(inetAddress);
    }
    return inetAddresses;
}
Also used : AAAA(de.measite.minidns.record.AAAA) A(de.measite.minidns.record.A) UnknownHostException(java.net.UnknownHostException) ResolverApi(de.measite.minidns.hla.ResolverApi) DnssecResolverApi(de.measite.minidns.hla.DnssecResolverApi) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HostAddress(org.jivesoftware.smack.util.dns.HostAddress) InetAddress(java.net.InetAddress) AAAA(de.measite.minidns.record.AAAA)

Example 2 with ResolverApi

use of de.measite.minidns.hla.ResolverApi in project Smack by igniterealtime.

the class MiniDnsResolver method lookupSRVRecords0.

@Override
protected List<SRVRecord> lookupSRVRecords0(final String name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) {
    final ResolverApi resolver = getResolver(dnssecMode);
    ResolverResult<SRV> result;
    try {
        result = resolver.resolve(name, SRV.class);
    } catch (IOException e) {
        failedAddresses.add(new HostAddress(name, e));
        return null;
    }
    // TODO: Use ResolverResult.getResolutionUnsuccessfulException() found in newer MiniDNS versions.
    if (!result.wasSuccessful()) {
        ResolutionUnsuccessfulException resolutionUnsuccessfulException = getExceptionFrom(result);
        failedAddresses.add(new HostAddress(name, resolutionUnsuccessfulException));
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, result, failedAddresses)) {
        return null;
    }
    List<SRVRecord> res = new LinkedList<SRVRecord>();
    for (SRV srv : result.getAnswers()) {
        String hostname = srv.name.ace;
        List<InetAddress> hostAddresses = lookupHostAddress0(hostname, failedAddresses, dnssecMode);
        if (hostAddresses == null) {
            continue;
        }
        SRVRecord srvRecord = new SRVRecord(hostname, srv.port, srv.priority, srv.weight, hostAddresses);
        res.add(srvRecord);
    }
    return res;
}
Also used : SRV(de.measite.minidns.record.SRV) ResolutionUnsuccessfulException(de.measite.minidns.hla.ResolutionUnsuccessfulException) ResolverApi(de.measite.minidns.hla.ResolverApi) DnssecResolverApi(de.measite.minidns.hla.DnssecResolverApi) IOException(java.io.IOException) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) HostAddress(org.jivesoftware.smack.util.dns.HostAddress) InetAddress(java.net.InetAddress) LinkedList(java.util.LinkedList)

Aggregations

DnssecResolverApi (de.measite.minidns.hla.DnssecResolverApi)2 ResolverApi (de.measite.minidns.hla.ResolverApi)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 HostAddress (org.jivesoftware.smack.util.dns.HostAddress)2 ResolutionUnsuccessfulException (de.measite.minidns.hla.ResolutionUnsuccessfulException)1 A (de.measite.minidns.record.A)1 AAAA (de.measite.minidns.record.AAAA)1 SRV (de.measite.minidns.record.SRV)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 SRVRecord (org.jivesoftware.smack.util.dns.SRVRecord)1