org.littleshoot.proxy.TransportProtocol Java Examples
The following examples show how to use
org.littleshoot.proxy.TransportProtocol.
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: ServerGroup.java From g4proxy with Apache License 2.0 | 5 votes |
/** * Retrieves the {@link ProxyThreadPools} for the specified transport protocol. Lazily initializes the thread pools * for the transport protocol if they have not yet been initialized. If the protocol has already been initialized, * this method returns immediately, without synchronization. If initialization is necessary, the initialization * process creates the acceptor and worker threads necessary to service requests to/from the proxy. * <p> * This method is thread-safe; no external locking is necessary. * * @param protocol transport protocol to retrieve thread pools for * @return thread pools for the specified transport protocol */ private ProxyThreadPools getThreadPoolsForProtocol(TransportProtocol protocol) { // if the thread pools have not been initialized for this protocol, initialize them if (protocolThreadPools.get(protocol) == null) { synchronized (THREAD_POOL_INIT_LOCK) { if (protocolThreadPools.get(protocol) == null) { log.debug("Initializing thread pools for {} with {} acceptor threads, {} incoming worker threads, and {} outgoing worker threads", protocol, incomingAcceptorThreads, incomingWorkerThreads, outgoingWorkerThreads); SelectorProvider selectorProvider = TRANSPORT_PROTOCOL_SELECTOR_PROVIDERS.get(protocol); if (selectorProvider == null) { throw new UnknownTransportProtocolException(protocol); } ProxyThreadPools threadPools = new ProxyThreadPools(selectorProvider, incomingAcceptorThreads, incomingWorkerThreads, outgoingWorkerThreads, name, serverGroupId); protocolThreadPools.put(protocol, threadPools); } } } return protocolThreadPools.get(protocol); }
Example #2
Source File: ProxyToServerConnection.java From g4proxy with Apache License 2.0 | 5 votes |
/** * Set up our connection parameters based on server address and chained * proxies. * * @throws UnknownHostException when unable to resolve the hostname to an IP address */ private void setupConnectionParameters() throws UnknownHostException { if (chainedProxy != null && chainedProxy != ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION) { this.transportProtocol = chainedProxy.getTransportProtocol(); this.remoteAddress = chainedProxy.getChainedProxyAddress(); this.localAddress = chainedProxy.getLocalAddress(); } else { this.transportProtocol = TransportProtocol.TCP; // Report DNS resolution to HttpFilters this.remoteAddress = this.currentFilters.proxyToServerResolutionStarted(serverHostAndPort); // save the hostname and port of the unresolved address in hostAndPort, in case name resolution fails String hostAndPort = null; try { if (this.remoteAddress == null) { hostAndPort = serverHostAndPort; this.remoteAddress = addressFor(serverHostAndPort, proxyServer); } else if (this.remoteAddress.isUnresolved()) { // filter returned an unresolved address, so resolve it using the proxy server's resolver hostAndPort = HostAndPort.fromParts(this.remoteAddress.getHostName(), this.remoteAddress.getPort()).toString(); this.remoteAddress = proxyServer.getServerResolver().resolve(this.remoteAddress.getHostName(), this.remoteAddress.getPort()); } } catch (UnknownHostException e) { // unable to resolve the hostname to an IP address. notify the filters of the failure before allowing the // exception to bubble up. this.currentFilters.proxyToServerResolutionFailed(hostAndPort); throw e; } this.currentFilters.proxyToServerResolutionSucceeded(serverHostAndPort, this.remoteAddress); this.localAddress = proxyServer.getLocalAddress(); } }
Example #3
Source File: DefaultHttpProxyServer.java From g4proxy with Apache License 2.0 | 5 votes |
/** * Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop. * * @param transportProtocol * @param readThrottleBytesPerSecond * @param writeThrottleBytesPerSecond * @return */ private GlobalTrafficShapingHandler createGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) { EventLoopGroup proxyToServerEventLoop = this.getProxyToServerWorkerFor(transportProtocol); return new GlobalTrafficShapingHandler(proxyToServerEventLoop, writeThrottleBytesPerSecond, readThrottleBytesPerSecond, TRAFFIC_SHAPING_CHECK_INTERVAL_MS, Long.MAX_VALUE); }
Example #4
Source File: ProxyToServerConnection.java From yfs with Apache License 2.0 | 5 votes |
/** * Set up our connection parameters based on server address and chained * proxies. * * @throws UnknownHostException when unable to resolve the hostname to an IP address */ private void setupConnectionParameters() throws UnknownHostException { if (chainedProxy != null && chainedProxy != ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION) { this.transportProtocol = chainedProxy.getTransportProtocol(); this.remoteAddress = chainedProxy.getChainedProxyAddress(); this.localAddress = chainedProxy.getLocalAddress(); } else { this.transportProtocol = TransportProtocol.TCP; // Report DNS resolution to HttpFilters this.remoteAddress = this.currentFilters.proxyToServerResolutionStarted(serverHostAndPort); // save the hostname and port of the unresolved address in hostAndPort, in case name resolution fails String hostAndPort = null; try { if (this.remoteAddress == null) { hostAndPort = serverHostAndPort; this.remoteAddress = addressFor(serverHostAndPort, proxyServer); } else if (this.remoteAddress.isUnresolved()) { // filter returned an unresolved address, so resolve it using the proxy server's resolver hostAndPort = HostAndPort.fromParts(this.remoteAddress.getHostName(), this.remoteAddress.getPort()).toString(); this.remoteAddress = proxyServer.getServerResolver().resolve(this.remoteAddress.getHostName(), this.remoteAddress.getPort()); } } catch (UnknownHostException e) { // unable to resolve the hostname to an IP address. notify the filters of the failure before allowing the // exception to bubble up. this.currentFilters.proxyToServerResolutionFailed(hostAndPort); throw e; } this.currentFilters.proxyToServerResolutionSucceeded(serverHostAndPort, this.remoteAddress); this.localAddress = proxyServer.getLocalAddress(); } }
Example #5
Source File: ProxyToServerConnection.java From PowerTunnel with MIT License | 4 votes |
public TransportProtocol getTransportProtocol() { return transportProtocol; }
Example #6
Source File: ProxyToServerConnection.java From PowerTunnel with MIT License | 4 votes |
/** * Set up our connection parameters based on server address and chained * proxies. * * @throws UnknownHostException when unable to resolve the hostname to an IP address */ private void setupConnectionParameters() throws UnknownHostException { if (chainedProxy != null && chainedProxy != ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION) { this.transportProtocol = chainedProxy.getTransportProtocol(); this.chainedProxyType = chainedProxy.getChainedProxyType(); this.localAddress = chainedProxy.getLocalAddress(); this.remoteAddress = chainedProxy.getChainedProxyAddress(); this.remoteAddressResolver = DefaultAddressResolverGroup.INSTANCE; this.username = chainedProxy.getUsername(); this.password = chainedProxy.getPassword(); } else { this.transportProtocol = TransportProtocol.TCP; this.chainedProxyType = ChainedProxyType.HTTP; this.username = null; this.password = null; // Report DNS resolution to HttpFilters this.remoteAddress = this.currentFilters.proxyToServerResolutionStarted(serverHostAndPort); // save the hostname and port of the unresolved address in hostAndPort, in case name resolution fails String hostAndPort = null; try { if (this.remoteAddress == null) { hostAndPort = serverHostAndPort; this.remoteAddress = addressFor(serverHostAndPort, proxyServer); } else if (this.remoteAddress.isUnresolved()) { // filter returned an unresolved address, so resolve it using the proxy server's resolver hostAndPort = HostAndPort.fromParts(this.remoteAddress.getHostName(), this.remoteAddress.getPort()).toString(); this.remoteAddress = proxyServer.getServerResolver().resolve(this.remoteAddress.getHostName(), this.remoteAddress.getPort()); } } catch (UnknownHostException e) { // unable to resolve the hostname to an IP address. notify the filters of the failure before allowing the // exception to bubble up. this.currentFilters.proxyToServerResolutionFailed(hostAndPort); throw e; } this.currentFilters.proxyToServerResolutionSucceeded(serverHostAndPort, this.remoteAddress); this.localAddress = proxyServer.getLocalAddress(); } }
Example #7
Source File: ProxyToServerConnection.java From g4proxy with Apache License 2.0 | 4 votes |
/*************************************************************************** * State Management **************************************************************************/ public TransportProtocol getTransportProtocol() { return transportProtocol; }
Example #8
Source File: DefaultHttpProxyServer.java From g4proxy with Apache License 2.0 | 4 votes |
/** * Creates a new proxy server. * * @param serverGroup our ServerGroup for shared thread pools and such * @param transportProtocol The protocol to use for data transport * @param requestedAddress The address on which this server will listen * @param sslEngineSource (optional) if specified, this Proxy will encrypt inbound * connections from clients using an {@link SSLEngine} obtained * from this {@link SslEngineSource}. * @param authenticateSslClients Indicate whether or not to authenticate clients when using SSL * @param proxyAuthenticator (optional) If specified, requests to the proxy will be * authenticated using HTTP BASIC authentication per the provided * {@link ProxyAuthenticator} * @param chainProxyManager The proxy to send requests to if chaining proxies. Typically * <code>null</code>. * @param mitmManager The {@link MitmManager} to use for man in the middle'ing * CONNECT requests * @param filtersSource Source for {@link HttpFilters} * @param transparent If true, this proxy will run as a transparent proxy. This will * not modify the response, and will only modify the request to * amend the URI if the target is the origin server (to comply * with RFC 7230 section 5.3.1). * @param idleConnectionTimeout The timeout (in seconds) for auto-closing idle connections. * @param activityTrackers for tracking activity on this proxy * @param connectTimeout number of milliseconds to wait to connect to the upstream * server * @param serverResolver the {@link HostResolver} to use for resolving server addresses * @param readThrottleBytesPerSecond read throttle bandwidth * @param writeThrottleBytesPerSecond write throttle bandwidth * @param maxInitialLineLength * @param maxHeaderSize * @param maxChunkSize * @param allowRequestsToOriginServer when true, allow the proxy to handle requests that contain an origin-form URI, as defined in RFC 7230 5.3.1 */ private DefaultHttpProxyServer(ServerGroup serverGroup, TransportProtocol transportProtocol, InetSocketAddress requestedAddress, SslEngineSource sslEngineSource, boolean authenticateSslClients, ProxyAuthenticator proxyAuthenticator, ChainedProxyManager chainProxyManager, MitmManager mitmManager, HttpFiltersSource filtersSource, boolean transparent, int idleConnectionTimeout, Collection<ActivityTracker> activityTrackers, int connectTimeout, HostResolver serverResolver, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond, InetSocketAddress localAddress, String proxyAlias, int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean allowRequestsToOriginServer) { this.serverGroup = serverGroup; this.transportProtocol = transportProtocol; this.requestedAddress = requestedAddress; this.sslEngineSource = sslEngineSource; this.authenticateSslClients = authenticateSslClients; this.proxyAuthenticator = proxyAuthenticator; this.chainProxyManager = chainProxyManager; this.mitmManager = mitmManager; this.filtersSource = filtersSource; this.transparent = transparent; this.idleConnectionTimeout = idleConnectionTimeout; if (activityTrackers != null) { this.activityTrackers.addAll(activityTrackers); } this.connectTimeout = connectTimeout; this.serverResolver = serverResolver; if (writeThrottleBytesPerSecond > 0 || readThrottleBytesPerSecond > 0) { this.globalTrafficShapingHandler = createGlobalTrafficShapingHandler(transportProtocol, readThrottleBytesPerSecond, writeThrottleBytesPerSecond); } else { this.globalTrafficShapingHandler = null; } this.localAddress = localAddress; if (proxyAlias == null) { // attempt to resolve the name of the local machine. if it cannot be resolved, use the fallback name. String hostname = ProxyUtils.getHostName(); if (hostname == null) { hostname = FALLBACK_PROXY_ALIAS; } this.proxyAlias = hostname; } else { this.proxyAlias = proxyAlias; } this.maxInitialLineLength = maxInitialLineLength; this.maxHeaderSize = maxHeaderSize; this.maxChunkSize = maxChunkSize; this.allowRequestsToOriginServer = allowRequestsToOriginServer; }
Example #9
Source File: DefaultHttpProxyServer.java From g4proxy with Apache License 2.0 | 4 votes |
protected EventLoopGroup getProxyToServerWorkerFor(TransportProtocol transportProtocol) { return serverGroup.getProxyToServerWorkerPoolForTransport(transportProtocol); }
Example #10
Source File: DefaultHttpProxyServer.java From g4proxy with Apache License 2.0 | 4 votes |
private DefaultHttpProxyServerBootstrap( ServerGroup serverGroup, TransportProtocol transportProtocol, InetSocketAddress requestedAddress, SslEngineSource sslEngineSource, boolean authenticateSslClients, ProxyAuthenticator proxyAuthenticator, ChainedProxyManager chainProxyManager, MitmManager mitmManager, HttpFiltersSource filtersSource, boolean transparent, int idleConnectionTimeout, Collection<ActivityTracker> activityTrackers, int connectTimeout, HostResolver serverResolver, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond, InetSocketAddress localAddress, String proxyAlias, int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean allowRequestToOriginServer) { this.serverGroup = serverGroup; this.transportProtocol = transportProtocol; this.requestedAddress = requestedAddress; this.port = requestedAddress.getPort(); this.sslEngineSource = sslEngineSource; this.authenticateSslClients = authenticateSslClients; this.proxyAuthenticator = proxyAuthenticator; this.chainProxyManager = chainProxyManager; this.mitmManager = mitmManager; this.filtersSource = filtersSource; this.transparent = transparent; this.idleConnectionTimeout = idleConnectionTimeout; if (activityTrackers != null) { this.activityTrackers.addAll(activityTrackers); } this.connectTimeout = connectTimeout; this.serverResolver = serverResolver; this.readThrottleBytesPerSecond = readThrottleBytesPerSecond; this.writeThrottleBytesPerSecond = writeThrottleBytesPerSecond; this.localAddress = localAddress; this.proxyAlias = proxyAlias; this.maxInitialLineLength = maxInitialLineLength; this.maxHeaderSize = maxHeaderSize; this.maxChunkSize = maxChunkSize; this.allowRequestToOriginServer = allowRequestToOriginServer; }
Example #11
Source File: DefaultHttpProxyServer.java From g4proxy with Apache License 2.0 | 4 votes |
@Override public HttpProxyServerBootstrap withTransportProtocol( TransportProtocol transportProtocol) { this.transportProtocol = transportProtocol; return this; }
Example #12
Source File: ProxyToServerConnection.java From yfs with Apache License 2.0 | 4 votes |
/*************************************************************************** * State Management **************************************************************************/ public TransportProtocol getTransportProtocol() { return transportProtocol; }
Example #13
Source File: ServerGroup.java From g4proxy with Apache License 2.0 | 2 votes |
/** * Retrieves the client-to-proxy acceptor thread pool for the specified protocol. Initializes the pool if it has not * yet been initialized. * <p> * This method is thread-safe; no external locking is necessary. * * @param protocol transport protocol to retrieve the thread pool for * @return the client-to-proxy acceptor thread pool */ public EventLoopGroup getClientToProxyAcceptorPoolForTransport(TransportProtocol protocol) { return getThreadPoolsForProtocol(protocol).getClientToProxyAcceptorPool(); }
Example #14
Source File: ServerGroup.java From g4proxy with Apache License 2.0 | 2 votes |
/** * Retrieves the client-to-proxy acceptor worker pool for the specified protocol. Initializes the pool if it has not * yet been initialized. * <p> * This method is thread-safe; no external locking is necessary. * * @param protocol transport protocol to retrieve the thread pool for * @return the client-to-proxy worker thread pool */ public EventLoopGroup getClientToProxyWorkerPoolForTransport(TransportProtocol protocol) { return getThreadPoolsForProtocol(protocol).getClientToProxyWorkerPool(); }
Example #15
Source File: ServerGroup.java From g4proxy with Apache License 2.0 | 2 votes |
/** * Retrieves the proxy-to-server worker thread pool for the specified protocol. Initializes the pool if it has not * yet been initialized. * <p> * This method is thread-safe; no external locking is necessary. * * @param protocol transport protocol to retrieve the thread pool for * @return the proxy-to-server worker thread pool */ public EventLoopGroup getProxyToServerWorkerPoolForTransport(TransportProtocol protocol) { return getThreadPoolsForProtocol(protocol).getProxyToServerWorkerPool(); }