Class 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.
    • Field Detail

      • STUNSERVERS_FILENAME

        public static final java.lang.String STUNSERVERS_FILENAME
        See Also:
        Constant Field Values
      • 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

      • 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<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.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 org.jivesoftware.smack.XMPPException,
                            org.jivesoftware.smack.SmackException.NotConnectedException,
                            java.lang.InterruptedException
        Resolve the IP and obtain a valid transport method.
        Specified by:
        resolve in class TransportResolver
        Parameters:
        session - the Jingle session.
        Throws:
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
        org.jivesoftware.smack.XMPPException - if an XMPP protocol error was received.
      • initialize

        public void initialize()
                        throws org.jivesoftware.smack.XMPPException
        Initialize the resolver.
        Specified by:
        initialize in class TransportResolver
        Throws:
        org.jivesoftware.smack.XMPPException - if an XMPP protocol error was received.
      • cancel

        public void cancel()
                    throws org.jivesoftware.smack.XMPPException
        Cancel any operation.
        Specified by:
        cancel in class TransportResolver
        Throws:
        org.jivesoftware.smack.XMPPException - if an XMPP protocol error was received.
        See Also:
        TransportResolver.cancel()
      • clear

        public void clear()
                   throws org.jivesoftware.smack.XMPPException
        Clear the list of candidates and start the resolution again.
        Overrides:
        clear in class TransportResolver
        Throws:
        org.jivesoftware.smack.XMPPException - if an XMPP protocol error was received.
        See Also:
        TransportResolver.clear()