public final class Socks5Proxy extends Object
setLocalSocks5ProxyEnabled(boolean)
. The proxy is enabled by default.
The port of the local SOCKS5 proxy can be configured by invoking
setLocalSocks5ProxyPort(int)
. Default port is 7777. If you set the port to a negative
value Smack tries to the absolute value and all following until it finds an open port.
If your application is running on a machine with multiple network interfaces or if you want to
provide your public address in case you are behind a NAT router, invoke
addLocalAddress(String)
or replaceLocalAddresses(Collection)
to modify the list of
local network addresses used for outgoing SOCKS5 Bytestream requests.
The local SOCKS5 proxy server refuses all connections except the ones that are explicitly allowed
in the process of establishing a SOCKS5 Bytestream (
Socks5BytestreamManager.establishSession(org.jxmpp.jid.Jid)
).
This Implementation has the following limitations:
connect
command and will not answer correctly to other
commandsModifier and Type | Method and Description |
---|---|
void |
addLocalAddress(String address)
Adds the given address to the list of local network addresses.
|
void |
addTransfer(String digest)
Add the given digest to the list of allowed transfers.
|
List<String> |
getLocalAddresses()
Returns an set of the local network addresses that will be used for streamhost
candidates of outgoing SOCKS5 Bytestream requests.
|
static int |
getLocalSocks5ProxyPort()
Return the port of the local Socks5 proxy.
|
int |
getPort()
Returns the port of the local SOCKS5 proxy server.
|
protected Socket |
getSocket(String digest)
Returns the socket for the given digest.
|
static Socks5Proxy |
getSocks5Proxy()
Returns the local SOCKS5 proxy server.
|
static boolean |
isLocalSocks5ProxyEnabled()
Returns true if the local Socks5 proxy should be started.
|
boolean |
isRunning()
Returns
true if the local SOCKS5 proxy server is running, otherwise
false . |
boolean |
removeLocalAddress(String address)
Removes the given address from the list of local network addresses.
|
protected void |
removeTransfer(String digest)
Removes the given digest from the list of allowed transfers.
|
void |
replaceLocalAddresses(Collection<String> addresses)
Replaces the list of local network addresses.
|
static void |
setLocalSocks5ProxyEnabled(boolean localSocks5ProxyEnabled)
Sets if the local Socks5 proxy should be started.
|
static void |
setLocalSocks5ProxyPort(int localSocks5ProxyPort)
Sets the port of the local Socks5 proxy.
|
void |
start()
Starts the local SOCKS5 proxy server.
|
void |
stop()
Stops the local SOCKS5 proxy server.
|
public static boolean isLocalSocks5ProxyEnabled()
public static void setLocalSocks5ProxyEnabled(boolean localSocks5ProxyEnabled)
localSocks5ProxyEnabled
- if the local Socks5 proxy should be startedpublic static int getLocalSocks5ProxyPort()
public static void setLocalSocks5ProxyPort(int localSocks5ProxyPort)
localSocks5ProxyPort
- the port of the local Socks5 proxy to setpublic static Socks5Proxy getSocks5Proxy()
public void start()
public void stop()
public void addLocalAddress(String address)
Use this method if you want to provide multiple addresses in a SOCKS5 Bytestream request. This may be necessary if your application is running on a machine with multiple network interfaces or if you want to provide your public address in case you are behind a NAT router.
The order of the addresses used is determined by the order you add addresses.
Note that the list of addresses initially contains the address returned by
InetAddress.getLocalHost().getHostAddress()
. You can replace the list of
addresses by invoking replaceLocalAddresses(Collection)
.
address
- the local network address to addpublic boolean removeLocalAddress(String address)
address
- the local network address to removepublic List<String> getLocalAddresses()
public void replaceLocalAddresses(Collection<String> addresses)
Use this method if you want to provide multiple addresses in a SOCKS5 Bytestream request and want to define their order. This may be necessary if your application is running on a machine with multiple network interfaces or if you want to provide your public address in case you are behind a NAT router.
addresses
- the new list of local network addressespublic int getPort()
protected Socket getSocket(String digest)
addTransfer(String)
) while the peer
connected to the SOCKS5 proxy.digest
- identifying the connectionpublic void addTransfer(String digest)
getSocket(String)
. All connections to
the local SOCKS5 proxy that don't contain an allowed digest are discarded.digest
- to be added to the list of allowed transfersprotected void removeTransfer(String digest)
The digest should be removed after establishing the SOCKS5 Bytestream is finished, an error occurred while establishing the connection or if the connection is not allowed anymore.
digest
- to be removed from the list of allowed transferspublic boolean isRunning()
true
if the local SOCKS5 proxy server is running, otherwise
false
.true
if the local SOCKS5 proxy server is running, otherwise
false