Home / Class/ SocksPortUnificationServerHandler Class — netty Architecture

SocksPortUnificationServerHandler Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  0295c15b_38be_42b9_fdbc_ae5ee231d25e["SocksPortUnificationServerHandler"]
  0b93d152_ea14_0d5a_e33d_d3dd83304792["SocksPortUnificationServerHandler.java"]
  0295c15b_38be_42b9_fdbc_ae5ee231d25e -->|defined in| 0b93d152_ea14_0d5a_e33d_d3dd83304792
  17927958_b77a_0dcb_dde0_340b421bd775["SocksPortUnificationServerHandler()"]
  0295c15b_38be_42b9_fdbc_ae5ee231d25e -->|method| 17927958_b77a_0dcb_dde0_340b421bd775
  84dd1d49_0500_3b6c_a98b_9bbe4994771e["decode()"]
  0295c15b_38be_42b9_fdbc_ae5ee231d25e -->|method| 84dd1d49_0500_3b6c_a98b_9bbe4994771e
  ade776af_6b34_0df9_6137_2fd6f40c6c84["logKnownVersion()"]
  0295c15b_38be_42b9_fdbc_ae5ee231d25e -->|method| ade776af_6b34_0df9_6137_2fd6f40c6c84
  2318dec9_16fd_0df0_0412_2c11eec763d6["logUnknownVersion()"]
  0295c15b_38be_42b9_fdbc_ae5ee231d25e -->|method| 2318dec9_16fd_0df0_0412_2c11eec763d6

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/SocksPortUnificationServerHandler.java lines 38–101

public class SocksPortUnificationServerHandler extends ByteToMessageDecoder {

    private static final InternalLogger logger =
            InternalLoggerFactory.getInstance(SocksPortUnificationServerHandler.class);

    private final Socks5ServerEncoder socks5encoder;

    /**
     * Creates a new instance with the default configuration.
     */
    public SocksPortUnificationServerHandler() {
        this(Socks5ServerEncoder.DEFAULT);
    }

    /**
     * Creates a new instance with the specified {@link Socks5ServerEncoder}.
     * This constructor is useful when a user wants to use an alternative {@link Socks5AddressEncoder}.
     */
    public SocksPortUnificationServerHandler(Socks5ServerEncoder socks5encoder) {
        this.socks5encoder = ObjectUtil.checkNotNull(socks5encoder, "socks5encoder");
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        final int readerIndex = in.readerIndex();
        if (in.writerIndex() == readerIndex) {
            return;
        }

        ChannelPipeline p = ctx.pipeline();
        final byte versionVal = in.getByte(readerIndex);
        SocksVersion version = SocksVersion.valueOf(versionVal);

        switch (version) {
        case SOCKS4a:
            logKnownVersion(ctx, version);
            p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE);
            p.addAfter(ctx.name(), null, new Socks4ServerDecoder());
            break;
        case SOCKS5:
            logKnownVersion(ctx, version);
            p.addAfter(ctx.name(), null, socks5encoder);
            p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder());
            break;
        default:
            logUnknownVersion(ctx, versionVal);
            in.skipBytes(in.readableBytes());
            ctx.close();
            return;
        }

        p.remove(this);
    }

    private static void logKnownVersion(ChannelHandlerContext ctx, SocksVersion version) {
        logger.debug("{} Protocol version: {}({})", ctx.channel(), version);
    }

    private static void logUnknownVersion(ChannelHandlerContext ctx, byte versionVal) {
        if (logger.isDebugEnabled()) {
            logger.debug("{} Unknown protocol version: {}", ctx.channel(), versionVal & 0xFF);
        }
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free