+ * 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 + */ +public interface CustomResolver + extends Resolver +{ + /** + * The default number of milliseconds it takes us to get into redundant + * mode while waiting for a DNS query response. + */ + public static final int DNS_PATIENCE = 1500; + + /** + * The name of the property that allows us to override the default + * DNS_PATIENCE value. + */ + public static final String PNAME_DNS_PATIENCE + = "net.java.sip.communicator.util.dns.DNS_PATIENCE"; + + /** + * 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. + */ + public static final int DNS_REDEMPTION = 3; + + /** + * The name of the property that allows us to override the default + * DNS_REDEMPTION value. + */ + public static final String PNAME_DNS_REDEMPTION + = "net.java.sip.communicator.util.dns.DNS_REDEMPTION"; + + /** + * 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. + */ + public static int currentDnsRedemption = DNS_REDEMPTION; + + /** + * The name of the property that enables or disables the DNSSEC resolver + * (instead of a normal, non-validating local resolver). + */ + public static final String PNAME_DNSSEC_RESOLVER_ENABLED + = "net.java.sip.communicator.util.dns.DNSSEC_ENABLED"; + + /** + * Default value of @see PNAME_DNSSEC_RESOLVER_ENABLED. + */ + public static final boolean PDEFAULT_DNSSEC_RESOLVER_ENABLED = false; + + /** + * Resets resolver configuration and populate our default resolver + * with the newly configured servers. + */ + public void reset(); +} diff --git a/src/net/java/sip/communicator/service/dns/ParallelResolver.java b/src/net/java/sip/communicator/service/dns/ParallelResolver.java deleted file mode 100644 index 7c172d4b0..000000000 --- a/src/net/java/sip/communicator/service/dns/ParallelResolver.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.service.dns; - -import java.io.*; -import java.net.*; -import java.util.*; - -import org.xbill.DNS.*; - -/** - * 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
- */
-public interface ParallelResolver
- extends Resolver
-{
- /**
- * The default number of milliseconds it takes us to get into redundant
- * mode while waiting for a DNS query response.
- */
- public static final int DNS_PATIENCE = 1500;
-
- /**
- * The name of the property that allows us to override the default
- * DNS_PATIENCE value.
- */
- public static final String PNAME_DNS_PATIENCE
- = "net.java.sip.communicator.util.dns.DNS_PATIENCE";
-
- /**
- * 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.
- */
- public static final int DNS_REDEMPTION = 3;
-
- /**
- * The name of the property that allows us to override the default
- * DNS_REDEMPTION value.
- */
- public static final String PNAME_DNS_REDEMPTION
- = "net.java.sip.communicator.util.dns.DNS_REDEMPTION";
-
- /**
- * 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.
- */
- public static int currentDnsRedemption = DNS_REDEMPTION;
-
- /**
- * The name of the property that enables or disables the DNSSEC resolver
- * (instead of a normal, non-validating local resolver).
- */
- public static final String PNAME_DNSSEC_RESOLVER_ENABLED
- = "net.java.sip.communicator.util.dns.DNSSEC_ENABLED";
-
- /**
- * Default value of @see PNAME_DNSSEC_RESOLVER_ENABLED.
- */
- public static final boolean PDEFAULT_DNSSEC_RESOLVER_ENABLED = false;
-
- /**
- * Replaces the default resolver used by this class. Mostly meant for
- * debugging.
- *
- * @param resolver the resolver we'd like to use by default from now on.
- */
- public void setDefaultResolver(Resolver resolver);
-
- /**
- * Returns the default resolver used by this class. Mostly meant for
- * debugging.
- *
- * @return the resolver this class consults first.
- */
- public Resolver getDefaultResolver();
-
- /**
- * Creates a ParallelResolver that would use the specified array
- * of backupServers if the default DNS doesn't seem to be doing
- * that well.
- *
- * @param 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.
- */
- public void setBackupServers(InetSocketAddress[] backupServers);
-
- /**
- * Sends a message and waits for a response.
- *
- * @param query The query to send.
- * @return The response
- *
- * @throws IOException An error occurred while sending or receiving.
- */
- public Message send(Message query)
- throws IOException;
- /**
- * Supposed to asynchronously send messages but not currently implemented.
- *
- * @param query The query to send
- * @param listener The object containing the callbacks.
- * @return An identifier, which is also a parameter in the callback
- */
- public Object sendAsync(final Message query,
- final ResolverListener listener);
-
- /**
- * Sets the port to communicate on with the default servers.
- *
- * @param port The port to send messages to
- */
- public void setPort(int port);
-
- /**
- * Sets whether TCP connections will be sent by default with the default
- * resolver. Backup servers would always be contacted the same way.
- *
- * @param flag Indicates whether TCP connections are made
- */
- public void setTCP(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.
- *
- * @param flag Indicates whether truncated responses should be ignored.
- */
- public void setIgnoreTruncation(boolean flag);
-
- /**
- * Sets the EDNS version used on outgoing messages.
- *
- * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no
- * EDNS.
- * @throws IllegalArgumentException An invalid level was indicated.
- */
- public void setEDNS(int level);
-
- /**
- * Sets the EDNS information on outgoing messages.
- *
- * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no
- * EDNS.
- * @param payloadSize The maximum DNS packet size that this host is capable
- * of receiving over UDP. If 0 is specified, the default (1280) is used.
- * @param flags EDNS extended flags to be set in the OPT record.
- * @param 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 OPTRecord
- */
- @SuppressWarnings("rawtypes") // that's the way it is in dnsjava
- public void setEDNS(int level, int payloadSize, int flags, List options);
-
- /**
- * Specifies the TSIG key that messages will be signed with
- * @param key The key
- */
- public void setTSIGKey(TSIG key);
-
- /**
- * Sets the amount of time to wait for a response before giving up.
- *
- * @param secs The number of seconds to wait.
- * @param msecs The number of milliseconds to wait.
- */
- public void setTimeout(int secs, int msecs);
-
- /**
- * Sets the amount of time to wait for a response before giving up.
- *
- * @param secs The number of seconds to wait.
- */
- public void setTimeout(int secs);
-
- /**
- * Resets resolver configuration and populate our default resolver
- * with the newly configured servers.
- */
- public void reset();
-
- /**
- * Sets a DNSSEC resolver as default resolver on lookup when DNSSEC is
- * enabled; creates a standard lookup otherwise.
- */
- public void refreshResolver();
-}
diff --git a/src/net/java/sip/communicator/util/NetworkUtils.java b/src/net/java/sip/communicator/util/NetworkUtils.java
index 1099b861c..fe481ea71 100644
--- a/src/net/java/sip/communicator/util/NetworkUtils.java
+++ b/src/net/java/sip/communicator/util/NetworkUtils.java
@@ -6,14 +6,11 @@
*/
package net.java.sip.communicator.util;
-import java.beans.*;
import java.net.*;
import java.text.*;
import java.util.*;
-import java.util.concurrent.atomic.*;
import net.java.sip.communicator.service.dns.*;
-import net.java.sip.communicator.service.netaddr.event.*;
import net.java.sip.communicator.util.SRVRecord;
@@ -82,47 +79,6 @@ public class NetworkUtils
*/
private static Random portNumberGenerator = new Random();
- /**
- * The name of the property that users may use to override the
- * address of our backup DNS resolver.
- */
- public static final String PNAME_BACKUP_RESOLVER
- = "net.java.sip.communicator.util.dns.BACKUP_RESOLVER";
-
- /**
- * The name of the property that users may use to disable
- * our backup DNS resolver.
- */
- public static final String PNAME_BACKUP_RESOLVER_ENABLED
- = "net.java.sip.communicator.util.dns.BACKUP_RESOLVER_ENABLED";
-
- /**
- * The default of the property that users may use to disable
- * our backup DNS resolver.
- */
- public static final boolean PDEFAULT_BACKUP_RESOLVER_ENABLED = true;
-
- /**
- * The name of the property that users may use to override the port
- * of our backup DNS resolver.
- */
- public static final String PNAME_BACKUP_RESOLVER_PORT
- = "net.java.sip.communicator.util.dns.BACKUP_RESOLVER_PORT";
-
- /**
- * The address of the backup resolver we would use by default.
- */
- public static final String DEFAULT_BACKUP_RESOLVER
- = "backup-resolver.jitsi.net";
-
- /**
- * The name of the property that users may use to override the
- * IP address of our backup DNS resolver. This is only used when the
- * backup resolver name cannot be determined.
- */
- public static final String PNAME_BACKUP_RESOLVER_FALLBACK_IP
- = "net.java.sip.communicator.util.dns.BACKUP_RESOLVER_FALLBACK_IP";
-
/**
* The name of the boolean property that defines whether all domain names
* looked up from Jitsi should be treated as absolute.
@@ -135,27 +91,6 @@ public class NetworkUtils
*/
public static final boolean PDEFAULT_DNS_ALWAYS_ABSOLUTE = false;
- /**
- * The DNSjava resolver that we use with SRV and NAPTR queries in order to
- * try and smooth the problem of DNS servers that silently drop them.
- */
- private static Resolver parallelResolver = null;
-
- /**
- * Monitor object to set or reset the parallel resolver.
- */
- private final static Object parallelResolverLock = new Object();
-
- /**
- * Initialization flag for {@link #netListener}
- */
- private static final AtomicBoolean netListenerAdded = new AtomicBoolean();
-
- /**
- * Listener for network change events to reset the DNS resolvers.
- */
- private static final NetworkListener netListener = new NetworkListener();
-
/**
* A random number generator.
*/
@@ -1269,17 +1204,6 @@ private static boolean isMappedIPv4Addr(byte[] address)
private static Lookup createLookup(String domain, int type)
throws TextParseException
{
- // listens for network changes up/down so we can reset
- // dns configuration
- if(netListenerAdded.compareAndSet(false, true))
- {
- if(logger.isDebugEnabled())
- logger.debug("NetConfigChange listener added: "
- + netListener.hashCode());
- UtilActivator.getNetworkAddressManagerService()
- .addNetworkConfigurationChangeListener(netListener);
- }
-
// make domain name absolute if requested
if(UtilActivator.getConfigurationService().getBoolean(
PNAME_DNS_ALWAYS_ABSOLUTE,
@@ -1303,198 +1227,9 @@ private static Lookup createLookup(String domain, int type)
logger.trace(sb.toString());
}
- if(!UtilActivator.getConfigurationService()
- .getBoolean(PNAME_BACKUP_RESOLVER_ENABLED,
- PDEFAULT_BACKUP_RESOLVER_ENABLED)
- || UtilActivator.getConfigurationService().getBoolean(
- ParallelResolver.PNAME_DNSSEC_RESOLVER_ENABLED,
- ParallelResolver.PDEFAULT_DNSSEC_RESOLVER_ENABLED
- ))
- {
- return lookup;
- }
-
- //Initiate our global parallel resolver if this is our first ever
- //DNS query. The lock here is heavy but necessary as a) the config
- //form can cause an intermittent reset and b) multiple accounts signing
- //in at the same time could cause multiple ParallelResolver instances
- synchronized(parallelResolverLock)
- {
- if(parallelResolver == null)
- {
- try
- {
- String rslvrAddrStr
- = UtilActivator.getConfigurationService()
- .getString(PNAME_BACKUP_RESOLVER,
- DEFAULT_BACKUP_RESOLVER);
- String customRslvrIP
- = UtilActivator.getConfigurationService().getString(
- PNAME_BACKUP_RESOLVER_FALLBACK_IP,
- UtilActivator.getResources().getSettingsString(
- PNAME_BACKUP_RESOLVER_FALLBACK_IP));
-
- InetAddress resolverAddress = null;
-
- try
- {
- resolverAddress = getInetAddress(rslvrAddrStr);
- }
- catch(UnknownHostException exc)
- {
- logger.warn("Oh! Seems like our primary DNS is down!"
- + "Don't panic! We'll try to fall back to "
- + customRslvrIP);
- }
-
- if(resolverAddress == null)
- {
- /* name resolution failed for backup DNS resolver,
- * try with the IP address of the default backup resolver
- */
- resolverAddress = getInetAddress(customRslvrIP);
- }
-
- int rslvrPort = UtilActivator.getConfigurationService().getInt(
- PNAME_BACKUP_RESOLVER_PORT, SimpleResolver.DEFAULT_PORT);
-
- InetSocketAddress resolverSockAddr
- = new InetSocketAddress(resolverAddress, rslvrPort);
-
- parallelResolver = UtilActivator.getParallelResolver();
- if (parallelResolver != null
- && parallelResolver instanceof ParallelResolver)
- {
- ((ParallelResolver) parallelResolver).setBackupServers(
- new InetSocketAddress[]{resolverSockAddr});
- }
-
- //listens for changes on the parallel DNS settings
- UtilActivator.getConfigurationService()
- .addPropertyChangeListener(
- new DnsConfigurationChangeListener());
- }
- catch(Throwable t)
- {
- //We don't want to a problem with our parallel resolver to
- //make our entire DNS resolution to fail so in case something
- //goes wrong during initialization so we default to the
- //dns java default resolver
- logger.info("failed to initialize parallel resolver. we will "
- +"be using dnsjava's default one instead");
-
- if(logger.isDebugEnabled())
- logger.debug("exception was: ", t);
-
- parallelResolver = Lookup.getDefaultResolver();
- }
- }
-
- lookup.setResolver(parallelResolver);
- }
-
return lookup;
}
- /**
- * Gets the default port used by DNS servers obtained through
- * SimpleResolver.DEFAULT_PORT.
- * @return The default DNS server port
- */
- public static short getDefaultDnsPort()
- {
- return SimpleResolver.DEFAULT_PORT;
- }
-
- /**
- * Listens when network is going from down to up and
- * resets dns configuration.
- */
- private static class NetworkListener
- implements NetworkConfigurationChangeListener
- {
- /**
- * Fired when a change has occurred in the
- * computer network configuration.
- *
- * @param event the change event.
- */
- public void configurationChanged(ChangeEvent event)
- {
- if((event.getType() == ChangeEvent.IFACE_UP
- || event.getType() == ChangeEvent.DNS_CHANGE)
- && !event.isInitial())
- {
- reloadDnsResolverConfig();
- }
- }
- }
-
- /**
- * Listens for changes in the DNS configuration and resets
- * the parallelResolver when necessary
- */
- private static class DnsConfigurationChangeListener
- implements PropertyChangeListener
- {
- @SuppressWarnings("serial")
- private final Set