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
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
@ -160,6 +161,14 @@ public interface XMPPConnection {
|
|||
*/
|
||||
EntityFullJid getUser();
|
||||
|
||||
/**
|
||||
* Returns the local address currently in use for this connection, or <code>null</code> if
|
||||
* this is invalid for the type of underlying connection.
|
||||
*
|
||||
* @return the local address currently in use for this connection
|
||||
*/
|
||||
InetAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* Returns the stream ID for this connection, which is the value set by the server
|
||||
* when opening an XMPP stream. This value will be <code>null</code> if not connected to the server.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smack.c2s;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -1128,6 +1129,11 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
|
|||
walkStateGraph(walkStateGraphContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getLocalAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Object> getFilterStats() {
|
||||
Collection<XmppInputOutputFilter> filters;
|
||||
synchronized (this) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
@ -139,6 +140,11 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getLocalAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of packets that's sent through {@link #sendStanza(Stanza)} and
|
||||
* that has not been returned by {@link #getSentPacket()}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue