public final class Socks5BytestreamManager extends Manager implements BytestreamManager
A SOCKS5 Bytestream is negotiated partly over the XMPP XML stream and partly over a separate socket. The actual transfer though takes place over a separately created socket.
A SOCKS5 Bytestream generally has three parties, the initiator, the target, and the stream host. The stream host is a specialized SOCKS5 proxy setup on a server, or, the initiator can act as the stream host.
To establish a SOCKS5 Bytestream invoke the establishSession(String)
method. This will
negotiate a SOCKS5 Bytestream with the given target JID and return a socket.
If a session ID for the SOCKS5 Bytestream was already negotiated (e.g. while negotiating a file
transfer) invoke establishSession(String, String)
.
To handle incoming SOCKS5 Bytestream requests add an Socks5BytestreamListener
to the
manager. There are two ways to add this listener. If you want to be informed about incoming
SOCKS5 Bytestreams from a specific user add the listener by invoking
addIncomingBytestreamListener(BytestreamListener, String)
. If the listener should
respond to all SOCKS5 Bytestream requests invoke
addIncomingBytestreamListener(BytestreamListener)
.
Note that the registered Socks5BytestreamListener
will NOT be notified on incoming Socks5
bytestream requests sent in the context of XEP-0096 file transfer. (See
FileTransferManager
)
If no Socks5BytestreamListener
s are registered, all incoming SOCKS5 Bytestream requests
will be rejected by returning a <not-acceptable/> error to the initiator.
Modifier and Type | Method and Description |
---|---|
void |
addIncomingBytestreamListener(BytestreamListener listener)
Adds BytestreamListener that is called for every incoming SOCKS5 Bytestream request unless
there is a user specific BytestreamListener registered.
|
void |
addIncomingBytestreamListener(BytestreamListener listener,
String initiatorJID)
Adds BytestreamListener that is called for every incoming SOCKS5 Bytestream request from the
given user.
|
void |
disableService()
Disables the SOCKS5 Bytestream manager by removing the SOCKS5 Bytestream feature from the
service discovery, disabling the listener for SOCKS5 Bytestream initiation requests and
resetting its internal state, which includes removing this instance from the managers map.
|
Socks5BytestreamSession |
establishSession(String targetJID)
Establishes a SOCKS5 Bytestream with the given user and returns the Socket to send/receive
data to/from the user.
|
Socks5BytestreamSession |
establishSession(String targetJID,
String sessionID)
Establishes a SOCKS5 Bytestream with the given user using the given session ID and returns
the Socket to send/receive data to/from the user.
|
protected List<BytestreamListener> |
getAllRequestListeners()
Returns a list of
BytestreamListener that are informed if there are no listeners for
a specific initiator. |
static Socks5BytestreamManager |
getBytestreamManager(XMPPConnection connection)
Returns the Socks5BytestreamManager to handle SOCKS5 Bytestreams for a given
XMPPConnection . |
protected XMPPConnection |
getConnection()
Returns the XMPP connection.
|
protected List<String> |
getIgnoredBytestreamRequests()
Returns the list of session IDs that should be ignored by the InitialtionListener
|
int |
getProxyConnectionTimeout()
Returns the timeout for connecting to the SOCKS5 proxy selected by the target.
|
int |
getTargetResponseTimeout()
Returns the timeout to wait for the response to the SOCKS5 Bytestream initialization request.
|
protected BytestreamListener |
getUserListener(String initiator)
Returns the
BytestreamListener that should be informed if a SOCKS5 Bytestream request
from the given initiator JID is received. |
void |
ignoreBytestreamRequestOnce(String sessionID)
Use this method to ignore the next incoming SOCKS5 Bytestream request containing the given
session ID.
|
boolean |
isProxyPrioritizationEnabled()
Returns if the prioritization of the last working SOCKS5 proxy on successive SOCKS5
Bytestream connections is enabled.
|
void |
removeIncomingBytestreamListener(BytestreamListener listener)
Removes the given listener from the list of listeners for all incoming SOCKS5 Bytestream
requests.
|
void |
removeIncomingBytestreamListener(String initiatorJID)
Removes the listener for the given user.
|
protected void |
replyRejectPacket(IQ packet)
Responses to the given packet's sender with an XMPP error that a SOCKS5 Bytestream is not
accepted.
|
void |
setProxyConnectionTimeout(int proxyConnectionTimeout)
Sets the timeout for connecting to the SOCKS5 proxy selected by the target.
|
void |
setProxyPrioritizationEnabled(boolean proxyPrioritizationEnabled)
Enable/disable the prioritization of the last working SOCKS5 proxy on successive SOCKS5
Bytestream connections.
|
void |
setTargetResponseTimeout(int targetResponseTimeout)
Sets the timeout to wait for the response to the SOCKS5 Bytestream initialization request.
|
connection
public static Socks5BytestreamManager getBytestreamManager(XMPPConnection connection)
XMPPConnection
.
If no manager exists a new is created and initialized.
connection
- the XMPP connection or null
if given connection is
null
public void addIncomingBytestreamListener(BytestreamListener listener)
If no listeners are registered all SOCKS5 Bytestream request are rejected with a <not-acceptable/> error.
Note that the registered BytestreamListener
will NOT be notified on incoming Socks5
bytestream requests sent in the context of XEP-0096 file transfer. (See
FileTransferManager
)
addIncomingBytestreamListener
in interface BytestreamManager
listener
- the listener to registerpublic void removeIncomingBytestreamListener(BytestreamListener listener)
removeIncomingBytestreamListener
in interface BytestreamManager
listener
- the listener to removepublic void addIncomingBytestreamListener(BytestreamListener listener, String initiatorJID)
Use this method if you are awaiting an incoming SOCKS5 Bytestream request from a specific user.
If no listeners are registered all SOCKS5 Bytestream request are rejected with a <not-acceptable/> error.
Note that the registered BytestreamListener
will NOT be notified on incoming Socks5
bytestream requests sent in the context of XEP-0096 file transfer. (See
FileTransferManager
)
addIncomingBytestreamListener
in interface BytestreamManager
listener
- the listener to registerinitiatorJID
- the JID of the user that wants to establish a SOCKS5 Bytestreampublic void removeIncomingBytestreamListener(String initiatorJID)
removeIncomingBytestreamListener
in interface BytestreamManager
initiatorJID
- the JID of the user the listener should be removedpublic void ignoreBytestreamRequestOnce(String sessionID)
This method should be used if you are awaiting a SOCKS5 Bytestream request as a reply to another stanza(/packet) (e.g. file transfer).
sessionID
- to be ignoredpublic void disableService()
To re-enable the SOCKS5 Bytestream feature invoke getBytestreamManager(XMPPConnection)
.
Using the file transfer API will automatically re-enable the SOCKS5 Bytestream feature.
public int getTargetResponseTimeout()
public void setTargetResponseTimeout(int targetResponseTimeout)
targetResponseTimeout
- the timeout to setpublic int getProxyConnectionTimeout()
public void setProxyConnectionTimeout(int proxyConnectionTimeout)
proxyConnectionTimeout
- the timeout to setpublic boolean isProxyPrioritizationEnabled()
true
.true
if prioritization is enabled, false
otherwisepublic void setProxyPrioritizationEnabled(boolean proxyPrioritizationEnabled)
proxyPrioritizationEnabled
- enable/disable the prioritization of the last working
SOCKS5 proxypublic Socks5BytestreamSession establishSession(String targetJID) throws XMPPException, IOException, InterruptedException, SmackException
Use this method to establish SOCKS5 Bytestreams to users accepting all incoming Socks5 bytestream requests since this method doesn't provide a way to tell the user something about the data to be sent.
To establish a SOCKS5 Bytestream after negotiation the kind of data to be sent (e.g. file
transfer) use establishSession(String, String)
.
establishSession
in interface BytestreamManager
targetJID
- the JID of the user a SOCKS5 Bytestream should be establishedXMPPException
- if the user doesn't support or accept SOCKS5 Bytestreams, if no Socks5
Proxy could be found, if the user couldn't connect to any of the SOCKS5 ProxiesIOException
- if the bytestream could not be establishedInterruptedException
- if the current thread was interrupted while waitingSmackException
- if there was no response from the server.public Socks5BytestreamSession establishSession(String targetJID, String sessionID) throws IOException, InterruptedException, SmackException.NoResponseException, SmackException, XMPPException
establishSession
in interface BytestreamManager
targetJID
- the JID of the user a SOCKS5 Bytestream should be establishedsessionID
- the session ID for the SOCKS5 Bytestream requestIOException
- if the bytestream could not be establishedInterruptedException
- if the current thread was interrupted while waitingSmackException.NoResponseException
SmackException
- if the target does not support SOCKS5.XMPPException
protected void replyRejectPacket(IQ packet) throws SmackException.NotConnectedException
Specified in XEP-65 5.3.1 (Example 13)
packet
- Stanza(/Packet) that should be answered with a not-acceptable errorSmackException.NotConnectedException
protected XMPPConnection getConnection()
protected BytestreamListener getUserListener(String initiator)
BytestreamListener
that should be informed if a SOCKS5 Bytestream request
from the given initiator JID is received.initiator
- the initiator's JIDprotected List<BytestreamListener> getAllRequestListeners()
BytestreamListener
that are informed if there are no listeners for
a specific initiator.protected List<String> getIgnoredBytestreamRequests()