Example usage for io.netty.handler.codec.socks SocksAuthScheme UNKNOWN

List of usage examples for io.netty.handler.codec.socks SocksAuthScheme UNKNOWN

Introduction

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

Prototype

SocksAuthScheme UNKNOWN

To view the source code for io.netty.handler.codec.socks SocksAuthScheme UNKNOWN.

Click Source Link

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);
        }/*ww  w .j a  v a  2s  .co  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;
    }
}