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.
  • Field Details

    • STUNSERVERS_FILENAME

      public static final String STUNSERVERS_FILENAME
      See Also:
    • currentServer

      protected STUNResolver.STUNService currentServer
    • resolverThread

      protected Thread resolverThread
    • defaultPort

      protected int defaultPort
    • resolvedPublicIP

      protected String resolvedPublicIP
    • resolvedLocalIP

      protected String resolvedLocalIP
  • Constructor Details

    • 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 Details

    • 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:
    • setSTUNService

      public void setSTUNService(String ip, int port)
      Set the STUN server name and port.
      Parameters:
      ip - the STUN server name
      port - 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 List<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 List<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, 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.
      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:
    • 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: