Home / Class/ Socks5PrivateAuthRequestDecoder Class — netty Architecture

Socks5PrivateAuthRequestDecoder Class — netty Architecture

Architecture documentation for the Socks5PrivateAuthRequestDecoder class in Socks5PrivateAuthRequestDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6b9f8608_de9b_43e5_4557_9bcfe906f178["Socks5PrivateAuthRequestDecoder"]
  b52204f2_bea2_d386_2133_c7033aee7e44["Socks5PrivateAuthRequestDecoder.java"]
  6b9f8608_de9b_43e5_4557_9bcfe906f178 -->|defined in| b52204f2_bea2_d386_2133_c7033aee7e44
  85085e10_d562_1c92_11bc_28add682c167["decode()"]
  6b9f8608_de9b_43e5_4557_9bcfe906f178 -->|method| 85085e10_d562_1c92_11bc_28add682c167
  95528e6d_620a_0dd2_5d13_e3be7eee7c28["fail()"]
  6b9f8608_de9b_43e5_4557_9bcfe906f178 -->|method| 95528e6d_620a_0dd2_5d13_e3be7eee7c28

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5PrivateAuthRequestDecoder.java lines 32–94

public final class Socks5PrivateAuthRequestDecoder extends ByteToMessageDecoder {

    private boolean decoded;

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        try {
            if (decoded) {
                int readableBytes = in.readableBytes();
                if (readableBytes > 0) {
                    out.add(in.readRetainedSlice(readableBytes));
                }
                return;
            }

            // Check if we have enough data to decode the message
            if (in.readableBytes() < 2) {
                return;
            }

            final int startOffset = in.readerIndex();
            final byte version = in.getByte(startOffset);
            if (version != 1) {
                throw new DecoderException("unsupported subnegotiation version: " + version + " (expected: 1)");
            }

            final int tokenLength = in.getUnsignedByte(startOffset + 1);

            // Check if the full message is available
            if (in.readableBytes() < 2 + tokenLength) {
                return;
            }

            // Read the version and token length
            in.skipBytes(2);

            // Read the token
            byte[] token = new byte[tokenLength];
            in.readBytes(token);

            // Add the decoded token to the output list
            out.add(new DefaultSocks5PrivateAuthRequest(token));

            // Mark as decoded to handle remaining bytes in future calls
            decoded = true;
        } catch (Exception e) {
            fail(out, e);
        }
    }

    private void fail(List<Object> out, Exception cause) {
        if (!(cause instanceof DecoderException)) {
            cause = new DecoderException(cause);
        }

        decoded = true;

        Socks5Message m = new
            DefaultSocks5PrivateAuthRequest(EmptyArrays.EMPTY_BYTES);
        m.setDecoderResult(DecoderResult.failure(cause));
        out.add(m);
    }
}

Frequently Asked Questions

What is the Socks5PrivateAuthRequestDecoder class?
Socks5PrivateAuthRequestDecoder is a class in the netty codebase, defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5PrivateAuthRequestDecoder.java.
Where is Socks5PrivateAuthRequestDecoder defined?
Socks5PrivateAuthRequestDecoder is defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5PrivateAuthRequestDecoder.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free