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

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 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 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);
}

Right, we probably should add

ConnectionConfiguration.setHostAddress(InetAddress)

Thanks for pointing this out.

Fixed with Add ConnectionConfiguration.setHostAddress(InetAddress) · igniterealtime/Smack@3129165 · GitHub

Thanks again for reporting.

Please make setHost() also accept IP addresses passed as strings. A client that implements a “custom servername” config field shouldn’t have to figure out whether the passed parameter is a hostname or an IP address (which is non-trivial with IPv4 and IPv6), but the library should instead allow the usage of setHost() or at least a new function setHostOrIP(String).

Your wish is my command:

scheduled for Smack 4.3.2.

Awesome, thanks! Works with IPv4 and IPv6 addresses and hostnames!