Home / Class/ Socks5PrivateAuthResponseDecoder Class — netty Architecture

Socks5PrivateAuthResponseDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  1eb0d1c8_4306_0987_abef_474fe9a99790["Socks5PrivateAuthResponseDecoder"]
  bda1d68b_8589_cf1a_a80a_983d7db86d2b["Socks5PrivateAuthResponseDecoder.java"]
  1eb0d1c8_4306_0987_abef_474fe9a99790 -->|defined in| bda1d68b_8589_cf1a_a80a_983d7db86d2b
  ab7dfc3f_38ae_2242_0527_ac688ded9e73["decode()"]
  1eb0d1c8_4306_0987_abef_474fe9a99790 -->|method| ab7dfc3f_38ae_2242_0527_ac688ded9e73
  a75059f8_bc15_8624_6822_b4c350cb3525["fail()"]
  1eb0d1c8_4306_0987_abef_474fe9a99790 -->|method| a75059f8_bc15_8624_6822_b4c350cb3525

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5PrivateAuthResponseDecoder.java lines 49–125

public final class Socks5PrivateAuthResponseDecoder extends ByteToMessageDecoder {

    /**
     * Decoder states for SOCKS5 private authentication responses.
     */
    private enum State {
        /**
         * Initial state.
         */
        INIT,
        /**
         * Authentication successful.
         */
        SUCCESS,
        /**
         * Authentication failed.
         */
        FAILURE
    }

    private State state = State.INIT;

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in,
                          List<Object> out) throws Exception {
        try {
            switch (state) {
                case INIT:
                    if (in.readableBytes() < 2) {
                        return;
                    }

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

                    out.add(new DefaultSocks5PrivateAuthResponse(
                        Socks5PrivateAuthStatus.valueOf(in.readByte())));
                    state = State.SUCCESS;
                    break;
                case SUCCESS:
                    int readableBytes = in.readableBytes();
                    if (readableBytes > 0) {
                        out.add(in.readRetainedSlice(readableBytes));
                    }
                    break;
                case FAILURE:
                    in.skipBytes(in.readableBytes());
                    break;
                default:
                    throw new Error("Unexpected response decoder state: " + state);
            }
        } catch (Exception e) {
            fail(out, e);
        }
    }

    /**
     * Handles decoder failures by setting the appropriate error state.
     *
     * @param out   the output list to add the failure message to
     * @param cause the exception that caused the failure
     */
    private void fail(List<Object> out, Exception cause) {
        if (!(cause instanceof DecoderException)) {
            cause = new DecoderException(cause);
        }

        state = State.FAILURE;

        Socks5Message m = new DefaultSocks5PrivateAuthResponse(Socks5PrivateAuthStatus.FAILURE);
        m.setDecoderResult(DecoderResult.failure(cause));
        out.add(m);
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free