I created a patch to improve the support of the Socks5 bytestream feature of XMPP for Smack. With this patch comes a new API to establish Socks5 bytestreams. This can be useful for applications that exchange data not only via XMPP messages but also via streams. Socks5 bytestreams can also be a good fallback if Jingle doesn’t work.
Here is a list of changes:
- full implementation of XEP-0065 (except the optional UDP Support)
- Smack now replies with error message “not_acceptable” if an unexpected Socks5 bytestream request is received
- if target fails to connect to all Socks5 proxies it replies with “remote_server_not_found” error (before: “not_acceptable”)
- extracted API for Socks5 bytestreams from file transfer API
- Socks5 bytestream feature can now be used detached from the file transfer API
- file transfer API is now based on that extracted Socks5 bytestream API
- use Socks5ByteStreamManager#establishConnection() to initiate a Socks5 bytestream
- use Socks5ByteStreamManager#addIncomingByteStreamListener() to listen for incoming Socks5 bytestream requests
- use Socks5ByteStreamRequest#accept() to accept incoming Socks5 bytestream
- improved timeout behavior for Socks5 bytestreams
- response timeout to a Socks5 bytestream request is now configurable through Socks5ByteStreamManager#setTargetResponseTimeout() (was a constant)
- timeout for target to connect to Socks5 proxies is now configurable through Socks5ByteStreamRequest#setTotalConnectTimeout() and Socks5ByteStreamRequest#setMinimumConnectTimeout()
- every connection attempt to a Socks5 proxy now has a timeout so that connecting to an unreachable Socks5 proxy doesn’t consume the whole timeout for answering the Socks5 bytestream request
- improved prioritizing of Socks5 proxies
- Socks5 bytestream manager will set the last working Socks5 proxy to the top of the list of Socks5 proxies when establishing a new Socks5 bytestream
- Socks5 bytestream feature can now be enabled/disabled
- improved local Socks5 proxy server
- port of the local Socks5 proxy server can now be configured by editing the smack-config.xml file or by SmackConfiguration#setLocalSocks5ProxyPort()
- local Socks5 proxy can now be enabled/disabled by editing the smack-config.xml file or by SmackConfiguration#setLocalSocks5ProxyEnabled()
- local Socks5 proxy replies to some bad Socks5 request with appropriate error messages to be more client-friendly
- improved documentation of the implementation for maintainability
- added about 40 tests with almost 100% code coverage of the changed code
- added testing utilities to be able to test the code without using an XMPP server by mocking the XMPPConnection class
The patch is based on the current trunk of the Smack svn repository (rev 11621).
To run the tests the mocking libraries mockito and PowerMock are required.
Download the libraries here:
Copy all files from the archive except the junit-4.7.jar and the *.pom files to Smacks “build” directory.
Note: The support of Socks5 bytestreams depends on the XMPP server (respectively the Socks5 proxy server) implementation. For example Openfire only supports Socks5 bytestreams within the scope of a file transfer by default. You can change this behavior by setting the “xmpp.proxy.transfer.required” flag to false. Additionally not all Socks5 proxy implementations support bidirectional Socks5 bytestream. Openfire only supports a directed Socks5 bytestream from the initiator to the target.
I hope you like the patch.
socks5bytestream.patch.zip (46638 Bytes)