Class Socks5Proxy
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(InetAddress)
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:
- only supports the no-authentication authentication method
- only supports the
connect
command and will not answer correctly to other commands - only supports requests with the domain address type and will not correctly answer to requests with other address types
-
Constructor Summary
ModifierConstructorDescriptionprotected
Socks5Proxy
(ServerSocket serverSocket) Constructor a Socks5Proxy with the given socket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocalAddress
(InetAddress 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.static int
Returns an set of the local network addresses that will be used for streamhost candidates of outgoing SOCKS5 Bytestream requests.int
Return the port of the local Socks5 proxy.int
getPort()
Returns the port of the local SOCKS5 proxy server.protected Socket
Returns the socket for the given digest.static Socket
getSocketForDigest
(String digest) static Socks5Proxy
Returns the local SOCKS5 proxy server.static boolean
Returns true if the local Socks5 proxy should be started.boolean
Returnstrue
if the local SOCKS5 proxy server is running, otherwisefalse
.boolean
removeLocalAddress
(InetAddress 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<? extends InetAddress> addresses) Replaces the list of local network addresses.static void
setDefaultLocalSocsk5ProxyPort
(int defaultLocalSocks5ProxyPort) static void
setLocalSocks5ProxyEnabled
(boolean localSocks5ProxyEnabled) Sets if the local Socks5 proxy should be started.void
setLocalSocks5ProxyPort
(int localSocks5ProxyPort) Sets the port of the local Socks5 proxy.start()
Starts the local SOCKS5 proxy server.void
stop()
Stops the local SOCKS5 proxy server.
-
Constructor Details
-
Socks5Proxy
Constructor a Socks5Proxy with the given socket. Used for unit test purposes.- Parameters:
serverSocket
- the server socket to use
-
-
Method Details
-
isLocalSocks5ProxyEnabled
Returns true if the local Socks5 proxy should be started. Default is true.- Returns:
- if the local Socks5 proxy should be started
-
setLocalSocks5ProxyEnabled
Sets if the local Socks5 proxy should be started. Default is true.- Parameters:
localSocks5ProxyEnabled
- if the local Socks5 proxy should be started
-
getDefaultLocalSocks5ProxyPort
-
setDefaultLocalSocsk5ProxyPort
-
getLocalSocks5ProxyPort
Return the port of the local Socks5 proxy. Default is 7777.- Returns:
- the port of the local Socks5 proxy
-
setLocalSocks5ProxyPort
Sets the port of the local Socks5 proxy. Default is 7777. If you set the port to a negative value Smack tries the absolute value and all following until it finds an open port.- Parameters:
localSocks5ProxyPort
- the port of the local Socks5 proxy to set
-
getSocks5Proxy
Returns the local SOCKS5 proxy server.- Returns:
- the local SOCKS5 proxy server
-
start
Starts the local SOCKS5 proxy server. If it is already running, this method does nothing.- Returns:
- the server socket.
-
stop
Stops the local SOCKS5 proxy server. If it is not running this method does nothing. -
addLocalAddress
Adds the given address to the list of local network addresses.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 invokingreplaceLocalAddresses(Collection)
.- Parameters:
address
- the local network address to add
-
removeLocalAddress
Removes the given address from the list of local network addresses. This address will then no longer be used of outgoing SOCKS5 Bytestream requests.- Parameters:
address
- the local network address to remove- Returns:
- true if the address was removed.
-
getLocalAddresses
Returns an set of the local network addresses that will be used for streamhost candidates of outgoing SOCKS5 Bytestream requests.- Returns:
- set of the local network addresses
-
replaceLocalAddresses
Replaces the list of local network 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.
- Parameters:
addresses
- the new list of local network addresses
-
getPort
Returns the port of the local SOCKS5 proxy server. If it is not running -1 will be returned.- Returns:
- the port of the local SOCKS5 proxy server or -1 if proxy is not running
-
getSocket
Returns the socket for the given digest. A socket will be returned if the given digest has been in the list of allowed transfers (seeaddTransfer(String)
) while the peer connected to the SOCKS5 proxy.- Parameters:
digest
- identifying the connection- Returns:
- socket or null if there is no socket for the given digest
-
addTransfer
Add the given digest to the list of allowed transfers. Only connections for allowed transfers are stored and can be retrieved by invokinggetSocket(String)
. All connections to the local SOCKS5 proxy that don't contain an allowed digest are discarded.- Parameters:
digest
- to be added to the list of allowed transfers
-
removeTransfer
Removes the given digest from the list of allowed transfers. After invoking this method already stored connections with the given digest will be removed.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.
- Parameters:
digest
- to be removed from the list of allowed transfers
-
isRunning
Returnstrue
if the local SOCKS5 proxy server is running, otherwisefalse
.- Returns:
true
if the local SOCKS5 proxy server is running, otherwisefalse
-
getSocketForDigest
-