org.jivesoftware.smackx.jingle.nat
Class STUNResolver

java.lang.Object
  extended by org.jivesoftware.smackx.jingle.nat.TransportResolver
      extended by org.jivesoftware.smackx.jingle.nat.STUNResolver

public class STUNResolver
extends TransportResolver

Transport resolver using the JSTUN library, to discover public IP and use it as a candidate. The goal of this resolver is to take possible to establish and manage out-of-band connections between two XMPP entities, even if they are behind Network Address Translators (NATs) or firewalls.

Author:
Thiago Camargo

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jivesoftware.smackx.jingle.nat.TransportResolver
TransportResolver.Type
 
Field Summary
static java.lang.String STUNSERVERS_FILENAME
           
 
Fields inherited from class org.jivesoftware.smackx.jingle.nat.TransportResolver
CHECK_TIMEOUT, type
 
Constructor Summary
STUNResolver()
          Constructor with default STUN server.
STUNResolver(int defaultPort)
          Constructor with a default port.
 
Method Summary
 void cancel()
          Cancel any operation.
 void clear()
          Clear the list of candidates and start the resolution again.
 java.lang.String getCurrentServerName()
          Get the name of the current STUN server.
 int getCurrentServerPort()
          Get the port of the current STUN server.
 void initialize()
          Initialize the resolver.
 boolean isResolving()
          Return true if the service is working.
 java.util.ArrayList loadSTUNServers()
          Load a list of services: STUN servers and ports.
 java.util.ArrayList loadSTUNServers(java.io.InputStream stunConfigStream)
          Load the STUN configuration from a stream.
 void resolve(JingleSession session)
          Resolve the IP and obtain a valid transport method.
 void setSTUNService(java.lang.String ip, int port)
          Set the STUN server name and port
 
Methods inherited from class org.jivesoftware.smackx.jingle.nat.TransportResolver
addListener, getCandidate, getCandidateCount, getCandidates, getCandidatesList, getListenersList, getPreferredCandidate, getType, initializeAndWait, isInitialized, isResolved, removeListener, setInitialized, setType
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STUNSERVERS_FILENAME

public static final java.lang.String STUNSERVERS_FILENAME
See Also:
Constant Field Values
Constructor Detail

STUNResolver

public STUNResolver()
Constructor with default STUN server.


STUNResolver

public STUNResolver(int defaultPort)
Constructor with a default port.

Parameters:
defaultPort - Port to use by default.
Method Detail

isResolving

public boolean isResolving()
Return true if the service is working.

Overrides:
isResolving in class TransportResolver
Returns:
true if the resolver is working.
See Also:
TransportResolver.isResolving()

setSTUNService

public void setSTUNService(java.lang.String ip,
                           int port)
Set the STUN server name and port

Parameters:
ip - the STUN server name
port - the STUN server port

getCurrentServerName

public java.lang.String getCurrentServerName()
Get the name of the current STUN server.

Returns:
the name of the STUN server

getCurrentServerPort

public int getCurrentServerPort()
Get the port of the current STUN server.

Returns:
the port of the STUN server

loadSTUNServers

public java.util.ArrayList loadSTUNServers(java.io.InputStream stunConfigStream)
Load the STUN configuration from a stream.

Parameters:
stunConfigStream - An InputStream with the configuration file.
Returns:
A list of loaded servers

loadSTUNServers

public java.util.ArrayList loadSTUNServers()
Load a list of services: STUN servers and ports. Some public STUN servers are:

               iphone-stun.freenet.de:3478
               larry.gloo.net:3478
               stun.xten.net:3478
               stun.fwdnet.net
               stun.fwd.org (no DNS SRV record)
               stun01.sipphone.com (no DNS SRV record)
               stun.softjoys.com (no DNS SRV record)
               stun.voipbuster.com (no DNS SRV record)
               stun.voxgratia.org (no DNS SRV record)
               stun.noc.ams-ix.net
 

This list should be contained in a file in the "META-INF" directory

Returns:
a list of services

resolve

public void resolve(JingleSession session)
             throws XMPPException
Resolve the IP and obtain a valid transport method.

Specified by:
resolve in class TransportResolver
Throws:
XMPPException

initialize

public void initialize()
                throws XMPPException
Initialize the resolver.

Specified by:
initialize in class TransportResolver
Throws:
XMPPException

cancel

public void cancel()
            throws XMPPException
Cancel any operation.

Specified by:
cancel in class TransportResolver
Throws:
XMPPException
See Also:
TransportResolver.cancel()

clear

public void clear()
           throws XMPPException
Clear the list of candidates and start the resolution again.

Overrides:
clear in class TransportResolver
Throws:
XMPPException
See Also:
TransportResolver.clear()