Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.util.dns
Class ParallelResolver

java.lang.Object
  extended by net.java.sip.communicator.util.dns.ParallelResolver
All Implemented Interfaces:
org.xbill.DNS.Resolver

public class ParallelResolver
extends Object
implements org.xbill.DNS.Resolver

The purpose of this class is to help avoid the significant delays that occur in networks where DNS servers would ignore SRV, NAPTR, and sometimes even A/AAAA queries (i.e. without even sending an error response). We also try to handle cases where DNS servers may return empty responses to some records.

We achieve this by entering a redundant mode whenever we detect an abnormal delay (longer than DNS_PATIENCE) while waiting for a DNS resonse, or when that response is not considered satisfying.

Once we enter redundant mode, we start duplicating all queries and sending them to both our primary and backup resolvers (in case we have any). We then always return the first response we get, regardless of who sent it.

We exit redundant mode after receiving DNS_REDEMPTION consecutive timely and correct responses from our primary resolver.

Author:
Emil Ivov

Field Summary
static int currentDnsRedemption
          The currently configured number of times that the primary DNS would have to provide a faster response than the backup resolver before we consider it safe enough to exit redundant mode.
static int DNS_PATIENCE
          The default number of milliseconds it takes us to get into redundant mode while waiting for a DNS query response.
static int DNS_REDEMPTION
          The default number of times that the primary DNS would have to provide a faster response than the backup resolver before we consider it safe enough to exit redundant mode.
static String PNAME_DNS_PATIENCE
          The name of the property that allows us to override the default DNS_PATIENCE value.
static String PNAME_DNS_REDEMPTION
          The name of the property that allows us to override the default DNS_REDEMPTION value.
 
Constructor Summary
ParallelResolver(InetSocketAddress[] backupServers)
          Creates a ParallelResolver that would use the specified array of backupServers if the default DNS doesn't seem to be doing that well.
 
Method Summary
static org.xbill.DNS.Resolver getDefaultResolver()
          Returns the default resolver used by this class.
 void reset()
          Resets resolver configuration and populate our default resolver with the newly configured servers.
 org.xbill.DNS.Message send(org.xbill.DNS.Message query)
          Sends a message and waits for a response.
 Object sendAsync(org.xbill.DNS.Message query, org.xbill.DNS.ResolverListener listener)
          Supposed to asynchronously send messages but not currently implemented.
static void setDefaultResolver(org.xbill.DNS.Resolver resolver)
          Replaces the default resolver used by this class.
 void setEDNS(int level)
          Sets the EDNS version used on outgoing messages.
 void setEDNS(int level, int payloadSize, int flags, List options)
          Sets the EDNS information on outgoing messages.
 void setIgnoreTruncation(boolean flag)
          Sets whether truncated responses will be ignored.
 void setPort(int port)
          Sets the port to communicate on with the default servers.
 void setTCP(boolean flag)
          Sets whether TCP connections will be sent by default with the default resolver.
 void setTimeout(int secs)
          Sets the amount of time to wait for a response before giving up.
 void setTimeout(int secs, int msecs)
          Sets the amount of time to wait for a response before giving up.
 void setTSIGKey(org.xbill.DNS.TSIG key)
          Specifies the TSIG key that messages will be signed with
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DNS_PATIENCE

public static final int DNS_PATIENCE
The default number of milliseconds it takes us to get into redundant mode while waiting for a DNS query response.

See Also:
Constant Field Values

PNAME_DNS_PATIENCE

public static final String PNAME_DNS_PATIENCE
The name of the property that allows us to override the default DNS_PATIENCE value.

See Also:
Constant Field Values

DNS_REDEMPTION

public static final int DNS_REDEMPTION
The default number of times that the primary DNS would have to provide a faster response than the backup resolver before we consider it safe enough to exit redundant mode.

See Also:
Constant Field Values

PNAME_DNS_REDEMPTION

public static final String PNAME_DNS_REDEMPTION
The name of the property that allows us to override the default DNS_REDEMPTION value.

See Also:
Constant Field Values

currentDnsRedemption

public static int currentDnsRedemption
The currently configured number of times that the primary DNS would have to provide a faster response than the backup resolver before we consider it safe enough to exit redundant mode.

Constructor Detail

ParallelResolver

public ParallelResolver(InetSocketAddress[] backupServers)
Creates a ParallelResolver that would use the specified array of backupServers if the default DNS doesn't seem to be doing that well.

Parameters:
backupServers - the list of backup DNS servers that we should use if, and only if, the default servers don't seem to work that well.
Method Detail

setDefaultResolver

public static void setDefaultResolver(org.xbill.DNS.Resolver resolver)
Replaces the default resolver used by this class. Mostly meant for debugging.

Parameters:
resolver - the resolver we'd like to use by default from now on.

getDefaultResolver

public static org.xbill.DNS.Resolver getDefaultResolver()
Returns the default resolver used by this class. Mostly meant for debugging.

Returns:
the resolver this class consults first.

send

public org.xbill.DNS.Message send(org.xbill.DNS.Message query)
                           throws IOException
Sends a message and waits for a response.

Specified by:
send in interface org.xbill.DNS.Resolver
Parameters:
query - The query to send.
Returns:
The response
Throws:
IOException - An error occurred while sending or receiving.

sendAsync

public Object sendAsync(org.xbill.DNS.Message query,
                        org.xbill.DNS.ResolverListener listener)
Supposed to asynchronously send messages but not currently implemented.

Specified by:
sendAsync in interface org.xbill.DNS.Resolver
Parameters:
query - The query to send
listener - The object containing the callbacks.
Returns:
An identifier, which is also a parameter in the callback

setPort

public void setPort(int port)
Sets the port to communicate on with the default servers.

Specified by:
setPort in interface org.xbill.DNS.Resolver
Parameters:
port - The port to send messages to

setTCP

public void setTCP(boolean flag)
Sets whether TCP connections will be sent by default with the default resolver. Backup servers would always be contacted the same way.

Specified by:
setTCP in interface org.xbill.DNS.Resolver
Parameters:
flag - Indicates whether TCP connections are made

setIgnoreTruncation

public void setIgnoreTruncation(boolean flag)
Sets whether truncated responses will be ignored. If not, a truncated response over UDP will cause a retransmission over TCP. Backup servers would always be contacted the same way.

Specified by:
setIgnoreTruncation in interface org.xbill.DNS.Resolver
Parameters:
flag - Indicates whether truncated responses should be ignored.

setEDNS

public void setEDNS(int level)
Sets the EDNS version used on outgoing messages.

Specified by:
setEDNS in interface org.xbill.DNS.Resolver
Parameters:
level - The EDNS level to use. 0 indicates EDNS0 and -1 indicates no EDNS.
Throws:
IllegalArgumentException - An invalid level was indicated.

setEDNS

public void setEDNS(int level,
                    int payloadSize,
                    int flags,
                    List options)
Sets the EDNS information on outgoing messages.

Specified by:
setEDNS in interface org.xbill.DNS.Resolver
Parameters:
level - The EDNS level to use. 0 indicates EDNS0 and -1 indicates no EDNS.
payloadSize - The maximum DNS packet size that this host is capable of receiving over UDP. If 0 is specified, the default (1280) is used.
flags - EDNS extended flags to be set in the OPT record.
options - EDNS options to be set in the OPT record, specified as a List of OPTRecord.Option elements.
Throws:
IllegalArgumentException - An invalid field was specified.
See Also:
OPTRecord

setTSIGKey

public void setTSIGKey(org.xbill.DNS.TSIG key)
Specifies the TSIG key that messages will be signed with

Specified by:
setTSIGKey in interface org.xbill.DNS.Resolver
Parameters:
key - The key

setTimeout

public void setTimeout(int secs,
                       int msecs)
Sets the amount of time to wait for a response before giving up.

Specified by:
setTimeout in interface org.xbill.DNS.Resolver
Parameters:
secs - The number of seconds to wait.
msecs - The number of milliseconds to wait.

setTimeout

public void setTimeout(int secs)
Sets the amount of time to wait for a response before giving up.

Specified by:
setTimeout in interface org.xbill.DNS.Resolver
Parameters:
secs - The number of seconds to wait.

reset

public void reset()
Resets resolver configuration and populate our default resolver with the newly configured servers.


Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.