Example usage for io.netty.handler.codec.socks SocksRequest protocolVersion

List of usage examples for io.netty.handler.codec.socks SocksRequest protocolVersion

Introduction

In this page you can find the example usage for io.netty.handler.codec.socks SocksRequest protocolVersion.

Prototype

public SocksProtocolVersion protocolVersion() 

Source Link

Document

Returns the SocksProtocolVersion of this SocksMessage

Usage

From source file:cc.agentx.client.net.nio.Socks5Handler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest request) throws Exception {
    switch (request.protocolVersion()) {
    case SOCKS4a:
        log.warn("\tBad Handshake! (protocol version not supported: 4)");
        ctx.write(new SocksInitResponse(SocksAuthScheme.UNKNOWN));
        if (ctx.channel().isActive()) {
            ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
        }/*from w w  w  .j  a v a2  s . c o m*/
        break;
    case SOCKS5:
        switch (request.requestType()) {
        case INIT:
            ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
            ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
            break;
        case AUTH:
            ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
            ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
            break;
        case CMD:
            if (((SocksCmdRequest) request).cmdType() == SocksCmdType.CONNECT) {
                ctx.pipeline().addLast(new XConnectHandler());
                ctx.pipeline().remove(this);
                ctx.fireChannelRead(request);
            } else {
                ctx.close();
                log.warn("\tBad Handshake! (command not support: {})", ((SocksCmdRequest) request).cmdType());
            }
            break;
        case UNKNOWN:
            log.warn("\tBad Handshake! (unknown request type)");
        }
        break;
    case UNKNOWN:
        log.warn("\tBad Handshake! (protocol version not support: {}", request.protocolVersion());
        ctx.close();
        break;
    }
}