Home / Class/ SocksCmdRequestDecoder Class — netty Architecture

SocksCmdRequestDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  91b58b47_5dce_76fa_582c_5f8d7c1ad016["SocksCmdRequestDecoder"]
  e62af65a_308d_e554_9ef8_5b990b3f424d["SocksCmdRequestDecoder.java"]
  91b58b47_5dce_76fa_582c_5f8d7c1ad016 -->|defined in| e62af65a_308d_e554_9ef8_5b990b3f424d
  09977f21_b226_3f00_4495_f231de2818f7["SocksCmdRequestDecoder()"]
  91b58b47_5dce_76fa_582c_5f8d7c1ad016 -->|method| 09977f21_b226_3f00_4495_f231de2818f7
  4266ae65_270e_7a74_0d4b_ed9ac9277ec2["decode()"]
  91b58b47_5dce_76fa_582c_5f8d7c1ad016 -->|method| 4266ae65_270e_7a74_0d4b_ed9ac9277ec2

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdRequestDecoder.java lines 33–104

public class SocksCmdRequestDecoder extends ReplayingDecoder<State> {

    private SocksCmdType cmdType;
    private SocksAddressType addressType;

    public SocksCmdRequestDecoder() {
        super(State.CHECK_PROTOCOL_VERSION);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
        switch (state()) {
            case CHECK_PROTOCOL_VERSION: {
                if (byteBuf.readByte() != SocksProtocolVersion.SOCKS5.byteValue()) {
                    out.add(SocksCommonUtils.UNKNOWN_SOCKS_REQUEST);
                    break;
                }
                checkpoint(State.READ_CMD_HEADER);
            }
            case READ_CMD_HEADER: {
                cmdType = SocksCmdType.valueOf(byteBuf.readByte());
                byteBuf.skipBytes(1); // reserved
                addressType = SocksAddressType.valueOf(byteBuf.readByte());
                checkpoint(State.READ_CMD_ADDRESS);
            }
            case READ_CMD_ADDRESS: {
                switch (addressType) {
                    case IPv4: {
                        String host = NetUtil.intToIpAddress(ByteBufUtil.readIntBE(byteBuf));
                        int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
                        out.add(new SocksCmdRequest(cmdType, addressType, host, port));
                        break;
                    }
                    case DOMAIN: {
                        int fieldLength = byteBuf.readByte();
                        String host = byteBuf.readString(fieldLength, CharsetUtil.US_ASCII);
                        int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
                        out.add(new SocksCmdRequest(cmdType, addressType, host, port));
                        break;
                    }
                    case IPv6: {
                        byte[] bytes = new byte[16];
                        byteBuf.readBytes(bytes);
                        String host = SocksCommonUtils.ipv6toStr(bytes);
                        int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
                        out.add(new SocksCmdRequest(cmdType, addressType, host, port));
                        break;
                    }
                    case UNKNOWN: {
                        out.add(SocksCommonUtils.UNKNOWN_SOCKS_REQUEST);
                        break;
                    }
                    default: {
                        throw new Error("Unexpected address type: " + addressType);
                    }
                }
                break;
            }
            default: {
                throw new Error("Unexpected request decoder type: " + state());
            }
        }
        ctx.pipeline().remove(this);
    }

    @UnstableApi
    public enum State {
        CHECK_PROTOCOL_VERSION,
        READ_CMD_HEADER,
        READ_CMD_ADDRESS
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free