Home / Class/ Socks4ClientDecoder Class — netty Architecture

Socks4ClientDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  5a68ac37_7c65_a197_e5fc_ea06651de05e["Socks4ClientDecoder"]
  65efc313_461b_f5fc_284f_f5b2ee04c71a["Socks4ClientDecoder.java"]
  5a68ac37_7c65_a197_e5fc_ea06651de05e -->|defined in| 65efc313_461b_f5fc_284f_f5b2ee04c71a
  4d1d2451_bbb4_f0f4_0d63_b76b696031d7["Socks4ClientDecoder()"]
  5a68ac37_7c65_a197_e5fc_ea06651de05e -->|method| 4d1d2451_bbb4_f0f4_0d63_b76b696031d7
  231f97ec_4a82_58a7_d4d8_581c91154ac2["decode()"]
  5a68ac37_7c65_a197_e5fc_ea06651de05e -->|method| 231f97ec_4a82_58a7_d4d8_581c91154ac2
  5f51e102_8380_acc7_1864_73c607712375["fail()"]
  5a68ac37_7c65_a197_e5fc_ea06651de05e -->|method| 5f51e102_8380_acc7_1864_73c607712375

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/v4/Socks4ClientDecoder.java lines 36–95

public class Socks4ClientDecoder extends ReplayingDecoder<State> {

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

    public Socks4ClientDecoder() {
        super(State.START);
        setSingleDecode(true);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        try {
            switch (state()) {
            case START: {
                final int version = in.readUnsignedByte();
                if (version != 0) {
                    throw new DecoderException("unsupported reply version: " + version + " (expected: 0)");
                }

                final Socks4CommandStatus status = Socks4CommandStatus.valueOf(in.readByte());
                final int dstPort = ByteBufUtil.readUnsignedShortBE(in);
                final String dstAddr = NetUtil.intToIpAddress(ByteBufUtil.readIntBE(in));

                out.add(new DefaultSocks4CommandResponse(status, dstAddr, dstPort));
                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);
        }

        Socks4CommandResponse m = new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED);
        m.setDecoderResult(DecoderResult.failure(cause));
        out.add(m);

        checkpoint(State.FAILURE);
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free