1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-13 22:41:08 +01:00

Merge pull request #537 from MF1-MS/mf1-ms/use_xmpp_connection_as_local_socks5_address

Use XMPP connection as local socks5 address
This commit is contained in:
Florian Schmaus 2023-04-26 11:35:04 +00:00 committed by GitHub
commit 19b20fefec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 124 additions and 1 deletions

View file

@ -656,13 +656,23 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
*/
public List<StreamHost> getLocalStreamHost() {
// Ensure that the local SOCKS5 proxy is running (if enabled).
Socks5Proxy.getSocks5Proxy();
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
List<StreamHost> streamHosts = new ArrayList<>();
XMPPConnection connection = connection();
EntityFullJid myJid = connection.getUser();
// 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.
InetAddress xmppLocalAddress = connection.getLocalAddress();
if (xmppLocalAddress != null) {
socks5Proxy.replaceLocalAddresses(Collections.singletonList(xmppLocalAddress));
}
for (Socks5Proxy socks5Server : Socks5Proxy.getRunningProxies()) {
List<InetAddress> addresses = socks5Server.getLocalAddresses();
if (addresses.isEmpty()) {