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 classSTUNResolver.STUNServiceSTUN 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.STUNServicecurrentServerprotected intdefaultPortprotected java.lang.StringresolvedLocalIPprotected java.lang.StringresolvedPublicIPprotected java.lang.ThreadresolverThreadstatic java.lang.StringSTUNSERVERS_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 voidcancel()Cancel any operation.voidclear()Clear the list of candidates and start the resolution again.java.lang.StringgetCurrentServerName()Get the name of the current STUN server.intgetCurrentServerPort()Get the port of the current STUN server.voidinitialize()Initialize the resolver.booleanisResolving()Return true if the service is working.java.util.ArrayList<STUNResolver.STUNService>loadSTUNServers()Load a list of services: STUN servers and ports.java.util.ArrayList<STUNResolver.STUNService>loadSTUNServers(java.io.InputStream stunConfigStream)Load the STUN configuration from a stream.voidresolve(JingleSession session)Resolve the IP and obtain a valid transport method.voidsetSTUNService(java.lang.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 java.lang.String STUNSERVERS_FILENAME
- See Also:
- Constant Field Values
-
currentServer
protected STUNResolver.STUNService currentServer
-
resolverThread
protected java.lang.Thread resolverThread
-
defaultPort
protected int defaultPort
-
resolvedPublicIP
protected java.lang.String resolvedPublicIP
-
resolvedLocalIP
protected java.lang.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:
isResolvingin classTransportResolver- 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 nameport- 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<STUNResolver.STUNService> 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<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.netThis 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, java.lang.InterruptedException
Resolve the IP and obtain a valid transport method.- Specified by:
resolvein classTransportResolver- Parameters:
session- the Jingle session.- Throws:
SmackException.NotConnectedException- if the XMPP connection is not connected.java.lang.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:
initializein classTransportResolver- Throws:
XMPPException- if an XMPP protocol error was received.
-
cancel
public void cancel() throws XMPPException
Cancel any operation.- Specified by:
cancelin 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:
clearin classTransportResolver- Throws:
XMPPException- if an XMPP protocol error was received.- See Also:
TransportResolver.clear()
-
-