AnsweredAssumed Answered

Smack version 4.2.0-beta3 XMPPTCPConnectionConfiguration sethost() cannot have ip.addr as parameter

Question asked by cmeng on Dec 9, 2016
Latest reply on Dec 28, 2016 by Flow

I have just completed ported aTalk to use Smack version 4.2.0-beta3 and have the following comments with reference to the following source: XMPPTCPConnection#connectUsingConfiguration() and AbstractXMPPConnection#populateHostAddresses()

 

I found that populateHostAddresses() only accepts FQDN and not ip.addr e.g. "55.222.13.34" as parameter in setHost(hostAddress).

Should it also allow ipAddress as parameter to support server without a FQDN?

 

The connectUsingConfiguration().failedAddresses.add(hostAddress) just adds hostAddress without checking duplication. atalk attempts 3 login retrials during user login, I found that failedAddresses hence contains duplicated failed hostAddress's. Not sure if this is design intent.

 

=========================================

private void connectUsingConfiguration() throws ConnectionException, IOException {
   List<HostAddress> failedAddresses = populateHostAddresses();
   SocketFactory socketFactory = config.getSocketFactory();
   ProxyInfo proxyInfo = config.getProxyInfo();
   int timeout = config.getConnectTimeout();
   if (socketFactory == null) {
   socketFactory = SocketFactory.getDefault();
   }
   for (HostAddress hostAddress : hostAddresses) {
   Iterator<InetAddress> inetAddresses = null;
   String host = hostAddress.getFQDN();
   int port = hostAddress.getPort();
   if (proxyInfo == null) {
   inetAddresses = hostAddress.getInetAddresses().iterator();
   assert(inetAddresses.hasNext());

   innerloop: while (inetAddresses.hasNext()) {
   // Create a *new* Socket before every connection attempt, i.e. connect() call, since Sockets are not
  // re-usable after a failed connection attempt. See also SMACK-724.
   socket = socketFactory.createSocket();

   final InetAddress inetAddress = inetAddresses.next();
   final String inetAddressAndPort = inetAddress + " at port " + port;
   LOGGER.finer("Trying to establish TCP connection to " + inetAddressAndPort);
   try {
   socket.connect(new InetSocketAddress(inetAddress, port), timeout);
   } catch (Exception e) {
   hostAddress.setException(inetAddress, e);
   if (inetAddresses.hasNext()) {
   continue innerloop;
   } else {
   break innerloop;
   }
  }
   LOGGER.finer("Established TCP connection to " + inetAddressAndPort);
   // We found a host to connect to, return here
   this.host = host;
   this.port = port;
   return;
   }
   failedAddresses.add(hostAddress);
   } else {
   final String hostAndPort = host + " at port " + port;
   LOGGER.finer("Trying to establish TCP connection via Proxy to " + hostAndPort);
   try {
   proxyInfo.getProxySocketConnection().connect(socket, host, port, timeout);
   } catch (IOException e) {
   hostAddress.setException(e);
   continue;
   }
   LOGGER.finer("Established TCP connection to " + hostAndPort);
   // We found a host to connect to, return here
   this.host = host;
   this.port = port;
   return;
   }
  }
   // There are no more host addresses to try
  // throw an exception and report all tried
  // HostAddresses in the exception
   throw ConnectionException.from(failedAddresses);
}

Outcomes