Search in sources :

Example 1 with Socks5InitialRequestDecoder

use of io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder in project netty by netty.

the class SocksPortUnificationServerHandler method decode.

@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);
}
Also used : Socks5InitialRequestDecoder(io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder) Socks4ServerDecoder(io.netty.handler.codec.socksx.v4.Socks4ServerDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with Socks5InitialRequestDecoder

use of io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder in project netty by netty.

the class Socks5ProxyServer method configure.

@Override
protected void configure(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    switch(testMode) {
        case INTERMEDIARY:
            p.addLast(DECODER, new Socks5InitialRequestDecoder());
            p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
            p.addLast(new Socks5IntermediaryHandler());
            break;
        case TERMINAL:
            p.addLast(DECODER, new Socks5InitialRequestDecoder());
            p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
            p.addLast(new Socks5TerminalHandler());
            break;
        case UNRESPONSIVE:
            p.addLast(UnresponsiveHandler.INSTANCE);
            break;
    }
}
Also used : Socks5InitialRequestDecoder(io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)2 Socks5InitialRequestDecoder (io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder)2 Socks4ServerDecoder (io.netty.handler.codec.socksx.v4.Socks4ServerDecoder)1