io.netty.handler.proxy.Socks5ProxyHandler Java Examples
The following examples show how to use
io.netty.handler.proxy.Socks5ProxyHandler.
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: ProxyHandlerSupplier.java From cute-proxy with BSD 2-Clause "Simplified" License | 6 votes |
public ProxyHandler newProxyHandler() { switch (proxySetting.type()) { case ProxySetting.TYPE_HTTP: if (proxySetting.user().isEmpty()) { return new HttpProxyHandler(address); } else { return new HttpProxyHandler(address, proxySetting.user(), proxySetting.password()); } case ProxySetting.TYPE_SOCKS5: if (proxySetting.user().isEmpty()) { return new Socks5ProxyHandler(address); } else { return new Socks5ProxyHandler(address, proxySetting.user(), proxySetting.password()); } case ProxySetting.TYPE_SOCKS4: if (proxySetting.user().isEmpty()) { return new Socks4ProxyHandler(address); } else { return new Socks4ProxyHandler(address, proxySetting.user()); } default: throw new RuntimeException("unknown proxy type: " + proxySetting.type()); } }
Example #2
Source File: ProxyIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testCreateConnectionViaSocksProxy() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer(); TestProxy testProxy = new TestProxy(ProxyType.SOCKS5)) { testProxy.start(); AtomicInteger supplierUsageCount = new AtomicInteger(); Supplier<ProxyHandler> proxyHandlerSupplier = () -> { supplierUsageCount.incrementAndGet(); return new Socks5ProxyHandler(new InetSocketAddress("localhost", testProxy.getPort())); }; Connection connection = establishConnecton(testPeer, proxyHandlerSupplier, false, null); testPeer.expectClose(); connection.close(); assertEquals(1, testProxy.getSuccessCount()); assertEquals("Unexpected handler supplier usage count", 1, supplierUsageCount.get()); } }
Example #3
Source File: ProxyProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
/** * Return a new eventual {@link ProxyHandler} * * @return a new eventual {@link ProxyHandler} */ public final ProxyHandler newProxyHandler() { InetSocketAddress proxyAddr = this.address.get(); String username = this.username; String password = Objects.nonNull(username) && Objects.nonNull(this.password) ? this.password.apply(username) : null; final boolean b = Objects.nonNull(username) && Objects.nonNull(password); final ProxyHandler proxyHandler; switch (this.type) { case HTTP: proxyHandler = b ? new HttpProxyHandler(proxyAddr, username, password, this.httpHeaders.get()) : new HttpProxyHandler(proxyAddr, this.httpHeaders.get()); break; case SOCKS4: proxyHandler = Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) : new Socks4ProxyHandler(proxyAddr); break; case SOCKS5: proxyHandler = b ? new Socks5ProxyHandler(proxyAddr, username, password) : new Socks5ProxyHandler(proxyAddr); break; default: throw new IllegalArgumentException("Proxy type unsupported : " + this.type); } proxyHandler.setConnectTimeoutMillis(connectTimeoutMillis); return proxyHandler; }
Example #4
Source File: ProxyIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testCreateSecureConnectionViaSocksProxy() throws Exception { TransportOptions sslOptions = new TransportOptions(); sslOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE); sslOptions.setKeyStorePassword(PASSWORD); sslOptions.setVerifyHost(false); SSLContext context = TransportSupport.createJdkSslContext(sslOptions); try (TestAmqpPeer testPeer = new TestAmqpPeer(context, false); TestProxy testProxy = new TestProxy(ProxyType.SOCKS5)) { testProxy.start(); String connOptions = "?transport.trustStoreLocation=" + CLIENT_JKS_TRUSTSTORE + "&" + "transport.trustStorePassword=" + PASSWORD + "&" + "transport.useOpenSSL=" + false; AtomicInteger supplierUsageCount = new AtomicInteger(); Supplier<ProxyHandler> proxyHandlerSupplier = () -> { supplierUsageCount.incrementAndGet(); return new Socks5ProxyHandler(new InetSocketAddress("localhost", testProxy.getPort())); }; Connection connection = establishConnecton(testPeer, proxyHandlerSupplier, true, connOptions); Socket socket = testPeer.getClientSocket(); assertTrue(socket instanceof SSLSocket); testPeer.expectClose(); connection.close(); assertEquals(1, testProxy.getSuccessCount()); assertEquals("Unexpected handler supplier usage count", 1, supplierUsageCount.get()); } }
Example #5
Source File: NettyClientTransport.java From joyrpc with Apache License 2.0 | 4 votes |
/** * 配置 * * @param bootstrap bootstrap * @param ioGroup 线程池 * @param channels 通道 * @param sslContext ssl上下文 */ protected Bootstrap configure(final Bootstrap bootstrap, final EventLoopGroup ioGroup, final Channel[] channels, final SslContext sslContext) { //Unknown channel option 'SO_BACKLOG' for channel bootstrap.group(ioGroup).channel(Constants.isUseEpoll(url) ? EpollSocketChannel.class : NioSocketChannel.class). option(ChannelOption.CONNECT_TIMEOUT_MILLIS, url.getPositiveInt(Constants.CONNECT_TIMEOUT_OPTION)). //option(ChannelOption.SO_TIMEOUT, url.getPositiveInt(Constants.SO_TIMEOUT_OPTION)). option(ChannelOption.TCP_NODELAY, url.getBoolean(TCP_NODELAY)). option(ChannelOption.SO_KEEPALIVE, url.getBoolean(Constants.SO_KEEPALIVE_OPTION)). option(ChannelOption.ALLOCATOR, BufAllocator.create(url)). option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark( url.getPositiveInt(Constants.WRITE_BUFFER_LOW_WATERMARK_OPTION), url.getPositiveInt(Constants.WRITE_BUFFER_HIGH_WATERMARK_OPTION))). option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT). handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) { //及时发送 与 缓存发送 channels[0] = new NettyClientChannel(ch, ioGroup); //设置 channels[0]. setAttribute(Channel.PAYLOAD, url.getPositiveInt(Constants.PAYLOAD)). setAttribute(Channel.BIZ_THREAD_POOL, bizThreadPool, (k, v) -> v != null); //添加连接事件监听 ch.pipeline().addLast("connection", new ConnectionChannelHandler(channels[0], publisher)); //添加编解码和处理链 HandlerBinder binder = Plugin.HANDLER_BINDER.get(codec.binder()); binder.bind(ch.pipeline(), codec, handlerChain, channels[0]); //若配置idle心跳策略,配置心跳handler if (heartbeatStrategy != null && heartbeatStrategy.getHeartbeatMode() == HeartbeatMode.IDLE) { ch.pipeline(). addLast("idleState", new IdleStateHandler(0, heartbeatStrategy.getInterval(), 0, TimeUnit.MILLISECONDS)). addLast("idleHeartbeat", new IdleHeartbeatHandler()); } if (sslContext != null) { ch.pipeline().addFirst("ssl", sslContext.newHandler(ch.alloc())); } //若开启了ss5代理,添加ss5 if (url.getBoolean(SS5_ENABLE)) { String host = url.getString(SS5_HOST); if (host != null && !host.isEmpty()) { InetSocketAddress ss5Address = new InetSocketAddress(host, url.getInteger(SS5_PORT)); ch.pipeline().addFirst("ss5", new Socks5ProxyHandler(ss5Address, url.getString(SS5_USER), url.getString(SS5_PASSWORD))); } } } }); return bootstrap; }