Class STUNResolver
- java.lang.Object
-
- org.jivesoftware.smackx.jingleold.nat.TransportResolver
-
- org.jivesoftware.smackx.jingleold.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
STUNResolver.STUNService
STUN service definition.-
Nested classes/interfaces inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
TransportResolver.Type
-
-
Field Summary
Fields Modifier and Type Field Description protected STUNResolver.STUNService
currentServer
protected int
defaultPort
protected String
resolvedLocalIP
protected String
resolvedPublicIP
protected Thread
resolverThread
static String
STUNSERVERS_FILENAME
-
Fields inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
candidates, CHECK_TIMEOUT, type
-
-
Constructor Summary
Constructors Constructor Description STUNResolver()
Constructor with default STUN server.STUNResolver(int defaultPort)
Constructor with a default port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancel any operation.void
clear()
Clear the list of candidates and start the resolution again.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.ArrayList<STUNResolver.STUNService>
loadSTUNServers()
Load a list of services: STUN servers and ports.ArrayList<STUNResolver.STUNService>
loadSTUNServers(InputStream stunConfigStream)
Load the STUN configuration from a stream.void
resolve(JingleSession session)
Resolve the IP and obtain a valid transport method.void
setSTUNService(String ip, int port)
Set the STUN server name and port.-
Methods inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
addCandidate, addListener, clearCandidates, getCandidate, getCandidateCount, getCandidates, getCandidatesList, getFreePort, getListenersList, getPreferredCandidate, getType, initializeAndWait, isInitialized, isResolved, removeListener, setInitialized, setResolveEnd, setResolveInit, setType, triggerCandidateAdded
-
-
-
-
Field Detail
-
STUNSERVERS_FILENAME
public static final String STUNSERVERS_FILENAME
- See Also:
- Constant Field Values
-
currentServer
protected STUNResolver.STUNService currentServer
-
resolverThread
protected Thread resolverThread
-
defaultPort
protected int defaultPort
-
resolvedPublicIP
protected String resolvedPublicIP
-
resolvedLocalIP
protected String resolvedLocalIP
-
-
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 classTransportResolver
- Returns:
- true if the resolver is working.
- See Also:
TransportResolver.isResolving()
-
setSTUNService
public void setSTUNService(String ip, int port)
Set the STUN server name and port.- Parameters:
ip
- the STUN server nameport
- the STUN server port
-
getCurrentServerName
public 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 ArrayList<STUNResolver.STUNService> loadSTUNServers(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 ArrayList<STUNResolver.STUNService> 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, SmackException.NotConnectedException, InterruptedException
Resolve the IP and obtain a valid transport method.- Specified by:
resolve
in classTransportResolver
- Parameters:
session
- the Jingle session.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.XMPPException
- if an XMPP protocol error was received.
-
initialize
public void initialize() throws XMPPException
Initialize the resolver.- Specified by:
initialize
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.
-
cancel
public void cancel() throws XMPPException
Cancel any operation.- Specified by:
cancel
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.- See Also:
TransportResolver.cancel()
-
clear
public void clear() throws XMPPException
Clear the list of candidates and start the resolution again.- Overrides:
clear
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.- See Also:
TransportResolver.clear()
-
-