aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl
diff options
context:
space:
mode:
authorEmil Ivov <emcho@jitsi.org>2010-09-19 10:50:28 +0000
committerEmil Ivov <emcho@jitsi.org>2010-09-19 10:50:28 +0000
commit8bd4856af51578b86aa87dc89843ba354576f5b2 (patch)
tree7d576e566212f5302e8dd5a722333a17bf92fc9a /src/net/java/sip/communicator/impl
parent6a8ce7a6a261bfc91d9daf8e9371cdfe0c4a743d (diff)
downloadjitsi-8bd4856af51578b86aa87dc89843ba354576f5b2.zip
jitsi-8bd4856af51578b86aa87dc89843ba354576f5b2.tar.gz
jitsi-8bd4856af51578b86aa87dc89843ba354576f5b2.tar.bz2
Added STUN server discovery to the network address manager
Diffstat (limited to 'src/net/java/sip/communicator/impl')
-rw-r--r--src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java
index dd56845..a126073 100644
--- a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java
@@ -9,9 +9,12 @@ package net.java.sip.communicator.impl.netaddr;
import java.beans.*;
import java.io.*;
import java.net.*;
+import java.text.*;
import java.util.*;
+import org.ice4j.*;
import org.ice4j.ice.*;
+import org.ice4j.ice.harvest.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.netaddr.*;
@@ -67,6 +70,18 @@ public class NetworkAddressManagerServiceImpl
*/
private NetworkConfigurationWatcher networkConfigurationWatcher = null;
+ /**
+ * The service name to use when discovering TURN servers through DNS using
+ * SRV requests as per RFC 5766.
+ */
+ public static final String TURN_SRV_NAME = "turn";
+
+ /**
+ * The service name to use when discovering STUN servers through DNS using
+ * SRV requests as per RFC 5389.
+ */
+ public static final String STUN_SRV_NAME = "stun";
+
/**
* Initializes this network address manager service implementation.
*/
@@ -506,4 +521,48 @@ public class NetworkAddressManagerServiceImpl
{
return new Agent();
}
+
+ /**
+ * Tries to discover a TURN or a STUN server for the specified
+ * <tt>domainName</tt>. The method would first try to discover a TURN
+ * server and then fall back to STUN only. In both cases we would only care
+ * about a UDP transport.
+ *
+ * @param domainName the domain name that we are trying to discover a
+ * TURN server for.
+ *
+ * @return A {@link StunCandidateHarvester} corresponding to the TURN or
+ * STUN server we discovered or <tt>null</tt> if there were no such records
+ * for the specified <tt>domainName</tt>
+ *
+ * @throws ParseException in case there's an issue with the domain name.
+ */
+ public StunCandidateHarvester discoverStunServer(String domainName)
+ throws ParseException
+ {
+ InetSocketAddress srvrAddress = NetworkUtils.getSRVRecord(
+ TURN_SRV_NAME, Transport.UDP.toString(), domainName);
+
+ if(srvrAddress != null)
+ {
+ //yay! we seem to have a TURN server, so we'll be using it for both
+ //TURN and STUN harvesting.
+ return new TurnCandidateHarvester(
+ new TransportAddress(srvrAddress, Transport.UDP));
+ }
+
+ //srvrAddres was null. try for a STUN only server.
+ srvrAddress = NetworkUtils.getSRVRecord(
+ STUN_SRV_NAME, Transport.UDP.toString(), domainName);
+
+ if(srvrAddress != null)
+ {
+ return new StunCandidateHarvester(
+ new TransportAddress(srvrAddress, Transport.UDP));
+ }
+
+ //srvrAddress was still null. sigh ...
+ return null;
+
+ }
}