io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder Java Examples

The following examples show how to use io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder. 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: Socks5ProxyServer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    switch (testMode) {
    case INTERMEDIARY:
        p.addLast(DECODER, new Socks5InitialRequestDecoder());
        p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
        p.addLast(new Socks5IntermediaryHandler());
        break;
    case TERMINAL:
        p.addLast(DECODER, new Socks5InitialRequestDecoder());
        p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
        p.addLast(new Socks5TerminalHandler());
        break;
    case UNRESPONSIVE:
        p.addLast(UnresponsiveHandler.INSTANCE);
        break;
    }
}
 
Example #2
Source File: SocksPortUnificationServerHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    final int readerIndex = in.readerIndex();
    if (in.writerIndex() == readerIndex) {
        return;
    }

    ChannelPipeline p = ctx.pipeline();
    final byte versionVal = in.getByte(readerIndex);
    SocksVersion version = SocksVersion.valueOf(versionVal);

    switch (version) {
    case SOCKS4a:
        logKnownVersion(ctx, version);
        p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE);
        p.addAfter(ctx.name(), null, new Socks4ServerDecoder());
        break;
    case SOCKS5:
        logKnownVersion(ctx, version);
        p.addAfter(ctx.name(), null, socks5encoder);
        p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder());
        break;
    default:
        logUnknownVersion(ctx, versionVal);
        in.skipBytes(in.readableBytes());
        ctx.close();
        return;
    }

    p.remove(this);
}
 
Example #3
Source File: Socks5ProxyMatcher.java    From cute-proxy with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void handlePipeline(ChannelPipeline pipeline) {
    pipeline.addLast("socks5-server-encoder", Socks5ServerEncoder.DEFAULT);
    pipeline.addLast("socks5-initial-decoder", new Socks5InitialRequestDecoder());
    pipeline.addLast(new Socks5ProxyHandler(messageListener, sslContextManager, proxyHandlerSupplier));
}
 
Example #4
Source File: ProxyServer.java    From socks5-netty with MIT License 4 votes vote down vote up
public void start() throws Exception {
	if(proxyFlowLog == null) {
		proxyFlowLog = new ProxyFlowLog4j();
	}
	if(passwordAuth == null) {
		passwordAuth = new PropertiesPasswordAuth();
	}
	EventLoopGroup boss = new NioEventLoopGroup(2);
	EventLoopGroup worker = new NioEventLoopGroup();
	try {
		ServerBootstrap bootstrap = new ServerBootstrap();
		bootstrap.group(boss, worker)
		.channel(NioServerSocketChannel.class)
		.option(ChannelOption.SO_BACKLOG, 1024)
		.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
		.childHandler(new ChannelInitializer<SocketChannel>() {
			@Override
			protected void initChannel(SocketChannel ch) throws Exception {
				//流量统计
				ch.pipeline().addLast(
						ProxyChannelTrafficShapingHandler.PROXY_TRAFFIC, 
						new ProxyChannelTrafficShapingHandler(3000, proxyFlowLog, channelListener)
						);
				//channel超时处理
				ch.pipeline().addLast(new IdleStateHandler(3, 30, 0));
				ch.pipeline().addLast(new ProxyIdleHandler());
				//netty日志
				if(logging) {
					ch.pipeline().addLast(new LoggingHandler());
				}
				//Socks5MessagByteBuf
				ch.pipeline().addLast(Socks5ServerEncoder.DEFAULT);
				//sock5 init
				ch.pipeline().addLast(new Socks5InitialRequestDecoder());
				//sock5 init
				ch.pipeline().addLast(new Socks5InitialRequestHandler(ProxyServer.this));
				if(isAuth()) {
					//socks auth
					ch.pipeline().addLast(new Socks5PasswordAuthRequestDecoder());
					//socks auth
					ch.pipeline().addLast(new Socks5PasswordAuthRequestHandler(getPasswordAuth()));
				}
				//socks connection
				ch.pipeline().addLast(new Socks5CommandRequestDecoder());
				//Socks connection
				ch.pipeline().addLast(new Socks5CommandRequestHandler(ProxyServer.this.getBossGroup()));
			}
		});
		
		ChannelFuture future = bootstrap.bind(port).sync();
		logger.debug("bind port : " + port);
		future.channel().closeFuture().sync();
	} finally {
		boss.shutdownGracefully();
		worker.shutdownGracefully();
	}
}