Java 类io.netty.handler.codec.socksx.v5.Socks5CommandStatus 实例源码

项目:nitmproxy    文件:SocksProxyHandler.java   
private void onSocksSuccess(ChannelHandlerContext ctx, Socks5CommandRequest request) {
    Address serverAddr = new Address(request.dstAddr(), request.dstPort());
    createServerChannel(ctx, serverAddr).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                ConnectionInfo newConnectionInfo = new ConnectionInfo(
                        connectionInfo.getClientAddr(), serverAddr);
                ctx.writeAndFlush(new DefaultSocks5CommandResponse(
                        Socks5CommandStatus.SUCCESS,
                        request.dstAddrType(),
                        request.dstAddr(),
                        request.dstPort()));

                onServerConnected(ctx, newConnectionInfo, future.channel());
            } else {
                ctx.channel().writeAndFlush(new DefaultSocks5CommandResponse(
                        Socks5CommandStatus.FAILURE,
                        request.dstAddrType(),
                        request.dstAddr(),
                        request.dstPort()));
                ctx.close();
            }
        }
    });
}