Package org.minidns
Class AbstractDnsClient
java.lang.Object
org.minidns.AbstractDnsClient
- Direct Known Subclasses:
DnsClient
,IterativeDnsClient
,ReliableDnsClient
A minimal DNS client for SRV/A/AAAA/NS and CNAME lookups, with IDN support.
This circumvents the missing javax.naming package on android.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected final DnsCache
The internal DNS cache.protected DnsDataSource
protected static final LruCache
protected static AbstractDnsClient.IpVersionSetting
protected final Random
protected AbstractDnsClient.IpVersionSetting
protected static final Logger
protected final Random
The internal random class for sequence generation. -
Constructor Summary
ModifierConstructorDescriptionprotected
Create a new DNS client using the global default cache.protected
AbstractDnsClient
(DnsCache cache) Create a new DNS client with the given DNS cache. -
Method Summary
Modifier and TypeMethodDescriptiongetCache()
Get the cache used by this DNS client.getCachedIPv4AddressesFor
(DnsName dnsName) getCachedIPv6AddressesFor
(DnsName dnsName) getCachedNameserverRecordsFor
(DnsName dnsName) Returns the currently usedDnsDataSource
.protected DnsMessage
protected boolean
isResponseCacheable
(Question q, DnsQueryResult result) Whether a response from the DNS system should be cached or not.protected abstract DnsMessage.Builder
newQuestion
(DnsMessage.Builder questionMessage) final DnsQueryResult
query
(CharSequence name, Record.TYPE type) Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).query
(String name, Record.TYPE type, InetAddress address) Query a nameserver for a single entry of class IN.final DnsQueryResult
query
(String name, Record.TYPE type, Record.CLASS clazz) Query the system nameservers for a single entry of any class.query
(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address) Query a nameserver for a single entry.query
(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address, int port) Query a nameserver for a single entry.protected abstract DnsQueryResult
query
(DnsMessage.Builder query) Send a query request to the DNS system.final DnsQueryResult
query
(DnsMessage query, InetAddress host) final DnsQueryResult
query
(DnsMessage requestMessage, InetAddress address, int port) query
(Question q, InetAddress address) Query a specific server for one entry.final DnsQueryResult
query
(Question q, InetAddress server, int port) final DnsQueryResult
query
(DnsName name, Record.TYPE type) Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).queryAsync
(CharSequence name, Record.TYPE type) protected MiniDnsFuture
<DnsQueryResult, IOException> queryAsync
(DnsMessage.Builder query) Default implementation of an asynchronous DNS query which just wraps the synchronous case.queryAsync
(DnsMessage query, InetAddress dnsServer) queryAsync
(DnsMessage requestMessage, InetAddress address, int port) void
setDataSource
(DnsDataSource dataSource) Set aDnsDataSource
to be used by the DnsClient.static void
setDefaultIpVersion
(AbstractDnsClient.IpVersionSetting preferedIpVersion) void
setPreferedIpVersion
(AbstractDnsClient.IpVersionSetting preferedIpVersion)
-
Field Details
-
DEFAULT_CACHE
-
LOGGER
-
random
The internal random class for sequence generation. -
insecureRandom
-
cache
The internal DNS cache. -
dataSource
-
DEFAULT_IP_VERSION_SETTING
-
ipVersionSetting
-
-
Constructor Details
-
AbstractDnsClient
Create a new DNS client with the given DNS cache.- Parameters:
cache
- The backend DNS cache.
-
AbstractDnsClient
protected AbstractDnsClient()Create a new DNS client using the global default cache.
-
-
Method Details
-
setDefaultIpVersion
-
setPreferedIpVersion
-
getPreferedIpVersion
-
query
public final DnsQueryResult query(String name, Record.TYPE type, Record.CLASS clazz) throws IOException Query the system nameservers for a single entry of any class. This can be used to determine the name server version, if name is version.bind, type is TYPE.TXT and clazz is CLASS.CH.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).- Returns:
- The response (or null on timeout/error).
- Throws:
IOException
- if an IO error occurs.
-
query
Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).- Returns:
- The response (or null on timeout/error).
- Throws:
IOException
- if an IO error occurs.
-
query
Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).- Returns:
- The response (or null on timeout/error).
- Throws:
IOException
- if an IO error occurs.
-
query
- Throws:
IOException
-
query
Send a query request to the DNS system.- Parameters:
query
- The query to send to the server.- Returns:
- The response (or null).
- Throws:
IOException
- if an IO error occurs.
-
queryAsync
public final MiniDnsFuture<DnsQueryResult,IOException> queryAsync(CharSequence name, Record.TYPE type) -
queryAsync
-
queryAsync
Default implementation of an asynchronous DNS query which just wraps the synchronous case.Subclasses override this method to support true asynchronous queries.
- Parameters:
query
- the query.- Returns:
- a future for this query.
-
query
- Throws:
IOException
-
query
public final DnsQueryResult query(DnsMessage requestMessage, InetAddress address, int port) throws IOException - Throws:
IOException
-
queryAsync
public final MiniDnsFuture<DnsQueryResult,IOException> queryAsync(DnsMessage requestMessage, InetAddress address, int port) -
isResponseCacheable
Whether a response from the DNS system should be cached or not.- Parameters:
q
- The question the response message should answer.result
- The DNS query result.- Returns:
- True, if the response should be cached, false otherwise.
-
newQuestion
-
query
public DnsQueryResult query(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address, int port) throws IOException Query a nameserver for a single entry.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).address
- The DNS server address.port
- The DNS server port.- Returns:
- The response (or null on timeout / failure).
- Throws:
IOException
- On IO Errors.
-
query
public DnsQueryResult query(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address) throws IOException Query a nameserver for a single entry.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).address
- The DNS server host.- Returns:
- The response (or null on timeout / failure).
- Throws:
IOException
- On IO Errors.
-
query
Query a nameserver for a single entry of class IN.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).address
- The DNS server host.- Returns:
- The response (or null on timeout / failure).
- Throws:
IOException
- On IO Errors.
-
query
- Throws:
IOException
-
query
Query a specific server for one entry.- Parameters:
q
- The question section of the DNS query.address
- The dns server address.- Returns:
- The a DNS query result.
- Throws:
IOException
- On IOErrors.
-
queryAsync
public final MiniDnsFuture<DnsQueryResult,IOException> queryAsync(DnsMessage query, InetAddress dnsServer) -
getDataSource
Returns the currently usedDnsDataSource
. SeesetDataSource(DnsDataSource)
for details.- Returns:
- The currently used
DnsDataSource
-
setDataSource
Set aDnsDataSource
to be used by the DnsClient. The default implementation will direct all queries directly to the Internet. This can be used to define a non-default handling for outgoing data. This can be useful to redirect the requests to a proxy or to modify requests after or responses before they are handled by the DnsClient implementation.- Parameters:
dataSource
- An implementation of DNSDataSource that shall be used.
-
getCache
Get the cache used by this DNS client.- Returns:
- the cached used by this DNS client or
null
.
-
getQueryFor
-
getCachedNameserverRecordsFor
-
getCachedIPv4AddressesFor
-
getCachedIPv6AddressesFor
-
getCachedIPv4NameserverAddressesFor
-
getCachedIPv6NameserverAddressesFor
-