Home / Class/ Socks5InitialRequestDecoder Class — netty Architecture

Socks5InitialRequestDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c8dbff5d_17e9_7cbf_4232_15f060dc4a1a["Socks5InitialRequestDecoder"]
  e59e127b_ed56_66b4_a26d_e67beb5cd4e7["Socks5InitialRequestDecoder.java"]
  c8dbff5d_17e9_7cbf_4232_15f060dc4a1a -->|defined in| e59e127b_ed56_66b4_a26d_e67beb5cd4e7
  2ccd248a_225e_f3d9_d4b7_8724e923b70a["Socks5InitialRequestDecoder()"]
  c8dbff5d_17e9_7cbf_4232_15f060dc4a1a -->|method| 2ccd248a_225e_f3d9_d4b7_8724e923b70a
  98cb6c51_918c_ac5e_eeb6_81db52959586["decode()"]
  c8dbff5d_17e9_7cbf_4232_15f060dc4a1a -->|method| 98cb6c51_918c_ac5e_eeb6_81db52959586
  22fe9ae3_fe20_7231_af0c_834285a859b9["fail()"]
  c8dbff5d_17e9_7cbf_4232_15f060dc4a1a -->|method| 22fe9ae3_fe20_7231_af0c_834285a859b9

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5InitialRequestDecoder.java lines 36–98

public class Socks5InitialRequestDecoder extends ReplayingDecoder<State> {

    @UnstableApi
    public enum State {
        INIT,
        SUCCESS,
        FAILURE
    }

    public Socks5InitialRequestDecoder() {
        super(State.INIT);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        try {
            switch (state()) {
            case INIT: {
                final byte version = in.readByte();
                if (version != SocksVersion.SOCKS5.byteValue()) {
                    throw new DecoderException(
                            "unsupported version: " + version + " (expected: " + SocksVersion.SOCKS5.byteValue() + ')');
                }

                final int authMethodCnt = in.readUnsignedByte();

                final Socks5AuthMethod[] authMethods = new Socks5AuthMethod[authMethodCnt];
                for (int i = 0; i < authMethodCnt; i++) {
                    authMethods[i] = Socks5AuthMethod.valueOf(in.readByte());
                }

                out.add(new DefaultSocks5InitialRequest(authMethods));
                checkpoint(State.SUCCESS);
            }
            case SUCCESS: {
                int readableBytes = actualReadableBytes();
                if (readableBytes > 0) {
                    out.add(in.readRetainedSlice(readableBytes));
                }
                break;
            }
            case FAILURE: {
                in.skipBytes(actualReadableBytes());
                break;
            }
            }
        } catch (Exception e) {
            fail(out, e);
        }
    }

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

        checkpoint(State.FAILURE);

        Socks5Message m = new DefaultSocks5InitialRequest(Socks5AuthMethod.NO_AUTH);
        m.setDecoderResult(DecoderResult.failure(cause));
        out.add(m);
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free