Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ private enum State {
// a 32 byte buffer is enough for all usual SOCKS negotiations, we expand it if necessary during the processing
private ByteBuffer buffer = ByteBuffer.allocate(32);
private State state = State.SEND_AUTH;
private int remainingResponseSize = -1;

SocksProxyProtocolHandler(final ProtocolIOSession ioSession, final Object attachment, final InetSocketAddress targetAddress,
final String username, final String password, final IOEventHandlerFactory eventHandlerFactory) {
this.ioSession = ioSession;
Expand Down Expand Up @@ -220,10 +218,10 @@ public void inputReady(final IOSession session, final ByteBuffer src) throws IOE
} else {
throw new IOException("SOCKS server returned unsupported address type: " + aType);
}
this.remainingResponseSize = addressSize + 2;
final int remainingResponseSize = addressSize + 2;
this.buffer.compact();
// make sure we only read what we need to, don't read too much
this.buffer.limit(this.remainingResponseSize);
this.buffer.limit(remainingResponseSize);
this.state = State.RECEIVE_ADDRESS;
// deliberate fall-through
} else {
Expand Down Expand Up @@ -262,13 +260,12 @@ private void prepareConnectCommand() throws IOException {
this.buffer.put((byte) 0); // reserved
if (address instanceof Inet4Address) {
this.buffer.put(InetAddressUtils.IPV4);
this.buffer.put(address.getAddress());
} else if (address instanceof Inet6Address) {
this.buffer.put(InetAddressUtils.IPV6);
this.buffer.put(address.getAddress());
} else {
throw new IOException("Unsupported remote address class: " + address.getClass().getName());
}
this.buffer.put(address.getAddress());
this.buffer.putShort((short) port);
this.buffer.flip();
}
Expand Down