Package org.apache.hc.core5.reactor
Class SocksProxyProtocolHandler
- java.lang.Object
-
- org.apache.hc.core5.reactor.SocksProxyProtocolHandler
-
- All Implemented Interfaces:
IOEventHandler
final class SocksProxyProtocolHandler extends java.lang.Object implements IOEventHandler
Implements the client side of SOCKS protocol version 5 as per https://tools.ietf.org/html/rfc1928. Supports SOCKS username/password authentication as per https://tools.ietf.org/html/rfc1929.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SocksProxyProtocolHandler.State
-
Field Summary
Fields Modifier and Type Field Description private static byte
ATYP_DOMAINNAME
private java.nio.ByteBuffer
buffer
private static byte
CLIENT_VERSION
private static byte
COMMAND_CONNECT
private InternalDataChannel
dataChannel
private IOEventHandlerFactory
eventHandlerFactory
private static int
MAX_COMMAND_CONNECT_LENGTH
private static int
MAX_DNS_NAME_LENGTH
private static byte
NO_AUTHENTICATION_REQUIRED
private IOReactorConfig
reactorConfig
private IOSessionRequest
sessionRequest
private SocksProxyProtocolHandler.State
state
private static byte
SUCCESS
private static byte
USERNAME_PASSWORD
private static byte
USERNAME_PASSWORD_VERSION
-
Constructor Summary
Constructors Constructor Description SocksProxyProtocolHandler(InternalDataChannel dataChannel, IOSessionRequest sessionRequest, IOEventHandlerFactory eventHandlerFactory, IOReactorConfig reactorConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connected(IOSession session)
Triggered after the given session has been just created.private byte[]
cred(java.lang.String cred)
void
disconnected(IOSession session)
Triggered when the given session has been terminated.void
exception(IOSession session, java.lang.Exception cause)
Triggered when the given session throws a exception.private boolean
fillBuffer(java.nio.channels.ByteChannel channel)
void
inputReady(IOSession session, java.nio.ByteBuffer src)
Triggered when the given session has input pending.void
outputReady(IOSession session)
Triggered when the given session is ready for output.private void
prepareConnectCommand()
private void
setBufferLimit(int newLimit)
void
timeout(IOSession session, Timeout timeout)
Triggered when the given session has timed out.private boolean
writeAndPrepareRead(java.nio.channels.ByteChannel channel, int readSize)
private boolean
writeBuffer(java.nio.channels.ByteChannel channel)
-
-
-
Field Detail
-
MAX_DNS_NAME_LENGTH
private static final int MAX_DNS_NAME_LENGTH
- See Also:
- Constant Field Values
-
MAX_COMMAND_CONNECT_LENGTH
private static final int MAX_COMMAND_CONNECT_LENGTH
- See Also:
- Constant Field Values
-
CLIENT_VERSION
private static final byte CLIENT_VERSION
- See Also:
- Constant Field Values
-
NO_AUTHENTICATION_REQUIRED
private static final byte NO_AUTHENTICATION_REQUIRED
- See Also:
- Constant Field Values
-
USERNAME_PASSWORD
private static final byte USERNAME_PASSWORD
- See Also:
- Constant Field Values
-
USERNAME_PASSWORD_VERSION
private static final byte USERNAME_PASSWORD_VERSION
- See Also:
- Constant Field Values
-
SUCCESS
private static final byte SUCCESS
- See Also:
- Constant Field Values
-
COMMAND_CONNECT
private static final byte COMMAND_CONNECT
- See Also:
- Constant Field Values
-
ATYP_DOMAINNAME
private static final byte ATYP_DOMAINNAME
- See Also:
- Constant Field Values
-
dataChannel
private final InternalDataChannel dataChannel
-
sessionRequest
private final IOSessionRequest sessionRequest
-
eventHandlerFactory
private final IOEventHandlerFactory eventHandlerFactory
-
reactorConfig
private final IOReactorConfig reactorConfig
-
buffer
private java.nio.ByteBuffer buffer
-
state
private SocksProxyProtocolHandler.State state
-
-
Constructor Detail
-
SocksProxyProtocolHandler
SocksProxyProtocolHandler(InternalDataChannel dataChannel, IOSessionRequest sessionRequest, IOEventHandlerFactory eventHandlerFactory, IOReactorConfig reactorConfig)
-
-
Method Detail
-
connected
public void connected(IOSession session) throws java.io.IOException
Description copied from interface:IOEventHandler
Triggered after the given session has been just created.- Specified by:
connected
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.- Throws:
java.io.IOException
-
outputReady
public void outputReady(IOSession session) throws java.io.IOException
Description copied from interface:IOEventHandler
Triggered when the given session is ready for output.- Specified by:
outputReady
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.- Throws:
java.io.IOException
-
cred
private byte[] cred(java.lang.String cred) throws java.io.IOException
- Throws:
java.io.IOException
-
inputReady
public void inputReady(IOSession session, java.nio.ByteBuffer src) throws java.io.IOException
Description copied from interface:IOEventHandler
Triggered when the given session has input pending.- Specified by:
inputReady
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.- Throws:
java.io.IOException
-
prepareConnectCommand
private void prepareConnectCommand() throws java.io.IOException
- Throws:
java.io.IOException
-
setBufferLimit
private void setBufferLimit(int newLimit)
-
writeAndPrepareRead
private boolean writeAndPrepareRead(java.nio.channels.ByteChannel channel, int readSize) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBuffer
private boolean writeBuffer(java.nio.channels.ByteChannel channel) throws java.io.IOException
- Throws:
java.io.IOException
-
fillBuffer
private boolean fillBuffer(java.nio.channels.ByteChannel channel) throws java.io.IOException
- Throws:
java.io.IOException
-
timeout
public void timeout(IOSession session, Timeout timeout) throws java.io.IOException
Description copied from interface:IOEventHandler
Triggered when the given session has timed out.- Specified by:
timeout
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.timeout
- the timeout.- Throws:
java.io.IOException
-
exception
public void exception(IOSession session, java.lang.Exception cause)
Description copied from interface:IOEventHandler
Triggered when the given session throws a exception.- Specified by:
exception
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.
-
disconnected
public void disconnected(IOSession session)
Description copied from interface:IOEventHandler
Triggered when the given session has been terminated.- Specified by:
disconnected
in interfaceIOEventHandler
- Parameters:
session
- the I/O session.
-
-