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:
parent
f6c85d9fb3
commit
ffd027cc7d
7 changed files with 124 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue