Examples of Socks4CmdResponse


Examples of io.netty.handler.codec.socksx.v4.Socks4CmdResponse

                    new GenericFutureListener<Future<Channel>>() {
                        @Override
                        public void operationComplete(final Future<Channel> future) throws Exception {
                            final Channel outboundChannel = future.getNow();
                            if (future.isSuccess()) {
                                ctx.channel().writeAndFlush(new Socks4CmdResponse(Socks4CmdStatus.SUCCESS))
                                        .addListener(new ChannelFutureListener() {
                                            @Override
                                            public void operationComplete(ChannelFuture channelFuture) {
                                                ctx.pipeline().remove(SocksServerConnectHandler.this);
                                                outboundChannel.pipeline().addLast(new RelayHandler(ctx.channel()));
                                                ctx.pipeline().addLast(new RelayHandler(outboundChannel));
                                            }
                                        });
                            } else {
                                ctx.channel().writeAndFlush(
                                        new Socks4CmdResponse(Socks4CmdStatus.REJECTED_OR_FAILED)
                                );
                                SocksServerUtils.closeOnFlush(ctx.channel());
                            }
                        }
                    });

            final Channel inboundChannel = ctx.channel();
            b.group(inboundChannel.eventLoop())
                    .channel(NioSocketChannel.class)
                    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                    .option(ChannelOption.SO_KEEPALIVE, true)
                    .handler(new DirectClientHandler(promise));

            b.connect(request.host(), request.port()).addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (future.isSuccess()) {
                        // Connection established use handler provided results
                    } else {
                        // Close the connection if the connection attempt has failed.
                        ctx.channel().writeAndFlush(
                                new Socks4CmdResponse(Socks4CmdStatus.REJECTED_OR_FAILED)
                        );
                        SocksServerUtils.closeOnFlush(ctx.channel());
                    }
                }
            });
View Full Code Here

Examples of io.netty.handler.codec.socksx.v4.Socks4CmdResponse

                username != null? username : "", Socks4CmdType.CONNECT, rhost, raddr.getPort());
    }

    @Override
    protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
        final Socks4CmdResponse res = (Socks4CmdResponse) response;
        final Socks4CmdStatus status = res.cmdStatus();
        if (status == Socks4CmdStatus.SUCCESS) {
            return true;
        }

        throw new ProxyConnectException(exceptionMessage("cmdStatus: " + status));
View Full Code Here

Examples of io.netty.handler.codec.socksx.v4.Socks4CmdResponse

        private SocketAddress intermediaryDestination;

        @Override
        protected boolean handleProxyProtocol(ChannelHandlerContext ctx, Object msg) throws Exception {
            Socks4CmdRequest req = (Socks4CmdRequest) msg;
            Socks4CmdResponse res;

            if (!authenticate(ctx, req)) {
                res = new Socks4CmdResponse(Socks4CmdStatus.IDENTD_AUTH_FAILURE);
            } else {
                res = new Socks4CmdResponse(Socks4CmdStatus.SUCCESS);
                intermediaryDestination = new InetSocketAddress(req.host(), req.port());
            }

            ctx.write(res);
            ctx.pipeline().remove(Socks4MessageEncoder.class);
View Full Code Here

Examples of io.netty.handler.codec.socksx.v4.Socks4CmdResponse

        @Override
        protected boolean handleProxyProtocol(ChannelHandlerContext ctx, Object msg) throws Exception {
            Socks4CmdRequest req = (Socks4CmdRequest) msg;
            boolean authzSuccess = authenticate(ctx, req);

            Socks4CmdResponse res;
            boolean sendGreeting = false;
            if (!authzSuccess) {
                res = new Socks4CmdResponse(Socks4CmdStatus.IDENTD_AUTH_FAILURE);
            } else if (!req.host().equals(destination.getHostString()) ||
                       req.port() != destination.getPort()) {
                res = new Socks4CmdResponse(Socks4CmdStatus.REJECTED_OR_FAILED);
            } else {
                res = new Socks4CmdResponse(Socks4CmdStatus.SUCCESS);
                sendGreeting = true;
            }

            ctx.write(res);
            ctx.pipeline().remove(Socks4MessageEncoder.class);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.