Home / Class/ Socks5InitialResponseDecoder Class — netty Architecture

Socks5InitialResponseDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  3875fc9f_0b12_49d8_83a3_c89642f3f7ef["Socks5InitialResponseDecoder"]
  cde9c1e3_0189_0cd8_6cbb_bf4fdf6537e3["Socks5InitialResponseDecoder.java"]
  3875fc9f_0b12_49d8_83a3_c89642f3f7ef -->|defined in| cde9c1e3_0189_0cd8_6cbb_bf4fdf6537e3
  70bfc2c0_05f3_5936_759d_be1d82b0e1e4["Socks5InitialResponseDecoder()"]
  3875fc9f_0b12_49d8_83a3_c89642f3f7ef -->|method| 70bfc2c0_05f3_5936_759d_be1d82b0e1e4
  97560ce2_ac38_2b11_972d_9e85668ceeae["decode()"]
  3875fc9f_0b12_49d8_83a3_c89642f3f7ef -->|method| 97560ce2_ac38_2b11_972d_9e85668ceeae
  60c48342_fab0_ff78_a4a7_1c54183a06e1["fail()"]
  3875fc9f_0b12_49d8_83a3_c89642f3f7ef -->|method| 60c48342_fab0_ff78_a4a7_1c54183a06e1

Relationship Graph

Source Code

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

public class Socks5InitialResponseDecoder extends ReplayingDecoder<State> {

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

    public Socks5InitialResponseDecoder() {
        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 Socks5AuthMethod authMethod = Socks5AuthMethod.valueOf(in.readByte());
                out.add(new DefaultSocks5InitialResponse(authMethod));
                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 DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED);
        m.setDecoderResult(DecoderResult.failure(cause));
        out.add(m);
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free