1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02:00

Use XMPP connection as local SOCKS5 address

The default local address is often just "the first address found in the list of addresses read from the OS" and this might mean an internal IP address that cannot reach external servers. So wherever possible use the same IP address being used to connect to the XMPP server because this local address has a better chance of being suitable.

This MR adds the above behaviour, and two UTs to test that we use the local XMPP connection IP when connected, and the previous behaviour when not.
This commit is contained in:
Martin Fidczuk 2022-08-15 16:51:22 +01:00
parent f6c85d9fb3
commit ffd027cc7d
No known key found for this signature in database
GPG key ID: 8B533F18DF43D922
7 changed files with 124 additions and 1 deletions

View file

@ -1938,4 +1938,20 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
this.bundleAndDeferCallback = bundleAndDeferCallback;
}
/**
* Returns the local address currently in use for this connection.
*
* @return the local address
*/
@Override
public InetAddress getLocalAddress() {
final Socket socket = this.socket;
if (socket == null) return null;
InetAddress localAddress = socket.getLocalAddress();
if (localAddress.isAnyLocalAddress()) return null;
return localAddress;
}
}