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

The following examples show how to use io.netty.handler.codec.socksx.v5.Socks5ServerEncoder. 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
/**
 * Creates a new instance with the specified {@link Socks5ServerEncoder}.
 * This constructor is useful when a user wants to use an alternative {@link Socks5AddressEncoder}.
 */
public SocksPortUnificationServerHandler(Socks5ServerEncoder socks5encoder) {
    if (socks5encoder == null) {
        throw new NullPointerException("socks5encoder");
    }

    this.socks5encoder = socks5encoder;
}
 
Example #3
Source File: SocksProxyHandler.java    From nitmproxy with MIT License 5 votes vote down vote up
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    LOGGER.info("{} : handlerAdded", connectionInfo.toString(true));

    Socks5ServerEncoder socks5ServerEncoder = new Socks5ServerEncoder(Socks5AddressEncoder.DEFAULT);
    SocksPortUnificationServerHandler socksPortUnificationServerHandler = new SocksPortUnificationServerHandler(socks5ServerEncoder);
    ctx.pipeline().addBefore(ctx.name(), null, socksPortUnificationServerHandler);
}
 
Example #4
Source File: SocksPortUnificationServerHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance with the default configuration.
 */
public SocksPortUnificationServerHandler() {
    this(Socks5ServerEncoder.DEFAULT);
}
 
Example #5
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 #6
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();
	}
}