Skip to content
Permalink
Browse files
Minor cleanup (#354)
  • Loading branch information
jkmcl committed Jul 1, 2022
1 parent 171210d commit 96849fa3d799ca7258d74e1f9b2dbd04c51cc478
Showing 1 changed file with 3 additions and 6 deletions.
@@ -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;
@@ -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 {
@@ -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();
}

0 comments on commit 96849fa

Please sign in to comment.