io.netty.handler.codec.socks.SocksCmdRequest Java Examples

The following examples show how to use io.netty.handler.codec.socks.SocksCmdRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocksServerConnectHandler.java    From NSS with Apache License 2.0 5 votes vote down vote up
/**
 * 获取远程ip地址
 * @param request
 * @return
 */
private String getIpAddr(SocksCmdRequest request) {
	if(isProxy) {
		return config.get_ipAddr();
	} else {
		return request.host();
	}
}
 
Example #2
Source File: SocksServerConnectHandler.java    From NSS with Apache License 2.0 5 votes vote down vote up
/**
 * 获取远程端口
 * @param request
 * @return
 */
private int getPort(SocksCmdRequest request) {
	if(isProxy) {
		return config.get_port();
	} else {
		return request.port();
	}
}
 
Example #3
Source File: SocksServerConnectHandler.java    From NSS with Apache License 2.0 5 votes vote down vote up
/**
 * localserver和remoteserver进行connect发送的数据
 * 
 * @param request
 * @param outboundChannel
 */
private void sendConnectRemoteMessage(SocksCmdRequest request,
		Channel outboundChannel) {
	ByteBuf buff = Unpooled.buffer();
	request.encodeAsByteBuf(buff);
	if (buff.hasArray()) {
		int len = buff.readableBytes();
		byte[] arr = new byte[len];
		buff.getBytes(0, arr);
		byte[] data = remoteByte(arr);
		sendRemote(data, data.length, outboundChannel);
	}
}
 
Example #4
Source File: SocksServerHandler.java    From NSS with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead0(ChannelHandlerContext ctx,
		SocksRequest socksRequest) throws Exception {
	switch (socksRequest.requestType()) {
	case INIT: {
		logger.info("localserver 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:
		SocksCmdRequest req = (SocksCmdRequest) socksRequest;
		if (req.cmdType() == SocksCmdType.CONNECT) {
			logger.info("localserver connect");
			ctx.pipeline().addLast(new SocksServerConnectHandler(config));
			ctx.pipeline().remove(this);
			ctx.fireChannelRead(socksRequest);
		} else {
			ctx.close();
		}
		break;
	case UNKNOWN:
		ctx.close();
		break;
	}
}
 
Example #5
Source File: SocksServerHandler.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
    switch (socksRequest.requestType()) {
        case INIT: {
            // auth support example
            //ctx.pipeline().addFirst(new SocksAuthRequestDecoder());
            //ctx.write(new SocksInitResponse(SocksAuthScheme.AUTH_PASSWORD));
            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:
            SocksCmdRequest req = (SocksCmdRequest) socksRequest;
            if (req.cmdType() == SocksCmdType.CONNECT) {
                ctx.pipeline().addLast(new SocksServerConnectHandler());
                ctx.pipeline().remove(this);
                ctx.fireChannelRead(socksRequest);
            } else {
                ctx.close();
            }
            break;
        case UNKNOWN:
            ctx.close();
            break;
    }
}
 
Example #6
Source File: Socks5ProxyServerHandlerBuilder.java    From sissi with Apache License 2.0 5 votes vote down vote up
private ChannelHandlerContext prepare(final ChannelHandlerContext ctx, Object msg, ChannelFuture future) throws IOException {
	if (msg.getClass() == SocksCmdRequest.class) {
		SocksCmdRequest cmd = SocksCmdRequest.class.cast(msg);
		return Socks5ProxyServerHandlerBuilder.this.exchangerContext.exists(cmd.host()) ? this.activate(Socks5ProxyServerHandlerBuilder.this.exchangerContext.activate(cmd.host()), future, ctx) : this.wait(cmd, ctx);
	}
	return ctx;
}
 
Example #7
Source File: SocksServerConnectHandler.java    From NSS with Apache License 2.0 4 votes vote down vote up
private SocksCmdResponse getSuccessResponse(SocksCmdRequest request) {
	return new SocksCmdResponse(SocksCmdStatus.SUCCESS,
			request.addressType());
}
 
Example #8
Source File: SocksServerConnectHandler.java    From NSS with Apache License 2.0 4 votes vote down vote up
private SocksCmdResponse getFailureResponse(SocksCmdRequest request) {
	return new SocksCmdResponse(SocksCmdStatus.FAILURE,
			request.addressType());
}
 
Example #9
Source File: Socks5ProxyServerHandlerBuilder.java    From sissi with Apache License 2.0 2 votes vote down vote up
/**
 * 禁止关闭接收方,cascade = false
 * 
 * @param cmd
 * @param ctx
 * @return
 * @throws IOException
 */
private ChannelHandlerContext wait(SocksCmdRequest cmd, ChannelHandlerContext ctx) throws IOException {
	ctx.attr(Socks5ProxyServerHandlerBuilder.this.exchanger).set(Socks5ProxyServerHandlerBuilder.this.exchangerContext.wait(cmd.host(), false, new NetworkTransfer(ctx)));
	return ctx;
}