use of io.grpc.HttpConnectProxiedSocketAddress in project grpc-java by grpc.
the class ProxyDetectorImplTest method unresolvedProxyAddressBecomesResolved.
@Test
public void unresolvedProxyAddressBecomesResolved() throws Exception {
InetSocketAddress unresolvedProxy = InetSocketAddress.createUnresolved("10.0.0.100", 1234);
assertTrue(unresolvedProxy.isUnresolved());
Proxy proxy1 = new java.net.Proxy(java.net.Proxy.Type.HTTP, unresolvedProxy);
when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy1));
HttpConnectProxiedSocketAddress proxy = (HttpConnectProxiedSocketAddress) proxyDetector.proxyFor(destination);
assertFalse(((InetSocketAddress) proxy.getProxyAddress()).isUnresolved());
}
use of io.grpc.HttpConnectProxiedSocketAddress in project grpc-java by grpc.
the class InternalSubchannel method startNewTransport.
private void startNewTransport() {
syncContext.throwIfNotInThisSynchronizationContext();
Preconditions.checkState(reconnectTask == null, "Should have no reconnectTask scheduled");
if (addressIndex.isAtBeginning()) {
connectingTimer.reset().start();
}
SocketAddress address = addressIndex.getCurrentAddress();
HttpConnectProxiedSocketAddress proxiedAddr = null;
if (address instanceof HttpConnectProxiedSocketAddress) {
proxiedAddr = (HttpConnectProxiedSocketAddress) address;
address = proxiedAddr.getTargetAddress();
}
Attributes currentEagAttributes = addressIndex.getCurrentEagAttributes();
String eagChannelAuthority = currentEagAttributes.get(EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE);
ClientTransportFactory.ClientTransportOptions options = new ClientTransportFactory.ClientTransportOptions().setAuthority(eagChannelAuthority != null ? eagChannelAuthority : authority).setEagAttributes(currentEagAttributes).setUserAgent(userAgent).setHttpConnectProxiedSocketAddress(proxiedAddr);
TransportLogger transportLogger = new TransportLogger();
// In case the transport logs in the constructor, use the subchannel logId
transportLogger.logId = getLogId();
ConnectionClientTransport transport = new CallTracingTransport(transportFactory.newClientTransport(address, options, transportLogger), callsTracer);
transportLogger.logId = transport.getLogId();
channelz.addClientSocket(transport);
pendingTransport = transport;
transports.add(transport);
Runnable runnable = transport.start(new TransportListener(transport, address));
if (runnable != null) {
syncContext.executeLater(runnable);
}
channelLogger.log(ChannelLogLevel.INFO, "Started transport {0}", transportLogger.logId);
}
use of io.grpc.HttpConnectProxiedSocketAddress in project grpc-java by grpc.
the class DnsNameResolverTest method doNotResolveWhenProxyDetected.
@Test
public void doNotResolveWhenProxyDetected() throws Exception {
final String name = "foo.googleapis.com";
final int port = 81;
final InetSocketAddress proxyAddress = new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 1000);
ProxyDetector alwaysDetectProxy = new ProxyDetector() {
@Override
public HttpConnectProxiedSocketAddress proxyFor(SocketAddress targetAddress) {
return HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress((InetSocketAddress) targetAddress).setProxyAddress(proxyAddress).setUsername("username").setPassword("password").build();
}
};
DnsNameResolver resolver = newResolver(name, port, alwaysDetectProxy, Stopwatch.createUnstarted());
AddressResolver mockAddressResolver = mock(AddressResolver.class);
when(mockAddressResolver.resolveAddress(anyString())).thenThrow(new AssertionError());
resolver.setAddressResolver(mockAddressResolver);
resolver.start(mockListener);
assertEquals(1, fakeExecutor.runDueTasks());
verify(mockListener).onResult(resultCaptor.capture());
List<EquivalentAddressGroup> result = resultCaptor.getValue().getAddresses();
assertThat(result).hasSize(1);
EquivalentAddressGroup eag = result.get(0);
assertThat(eag.getAddresses()).hasSize(1);
HttpConnectProxiedSocketAddress socketAddress = (HttpConnectProxiedSocketAddress) eag.getAddresses().get(0);
assertSame(proxyAddress, socketAddress.getProxyAddress());
assertEquals("username", socketAddress.getUsername());
assertEquals("password", socketAddress.getPassword());
assertTrue(socketAddress.getTargetAddress().isUnresolved());
}
use of io.grpc.HttpConnectProxiedSocketAddress in project grpc-java by grpc.
the class ProxyDetectorImplTest method detectProxyForResolvedDestination.
@Test
public void detectProxyForResolvedDestination() throws Exception {
InetSocketAddress resolved = new InetSocketAddress(InetAddress.getByName("10.1.2.3"), 10);
assertFalse(resolved.isUnresolved());
Proxy proxy = new Proxy(Proxy.Type.HTTP, unresolvedProxy);
when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
ProxiedSocketAddress detected = proxyDetector.proxyFor(resolved);
assertNotNull(detected);
HttpConnectProxiedSocketAddress expected = HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(resolved).setProxyAddress(new InetSocketAddress(InetAddress.getByName(unresolvedProxy.getHostName()), proxyPort)).build();
assertEquals(expected, detected);
}
Aggregations