Search in sources :

Example 1 with HttpConnectProxiedSocketAddress

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());
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) URI(java.net.URI) Test(org.junit.Test)

Example 2 with HttpConnectProxiedSocketAddress

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);
}
Also used : Attributes(io.grpc.Attributes) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) SocketAddress(java.net.SocketAddress)

Example 3 with HttpConnectProxiedSocketAddress

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());
}
Also used : AddressResolver(io.grpc.internal.DnsNameResolver.AddressResolver) InetSocketAddress(java.net.InetSocketAddress) ProxyDetector(io.grpc.ProxyDetector) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) Test(org.junit.Test)

Example 4 with HttpConnectProxiedSocketAddress

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);
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) URI(java.net.URI) Test(org.junit.Test)

Aggregations

HttpConnectProxiedSocketAddress (io.grpc.HttpConnectProxiedSocketAddress)4 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 Proxy (java.net.Proxy)2 SocketAddress (java.net.SocketAddress)2 URI (java.net.URI)2 Attributes (io.grpc.Attributes)1 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)1 ProxiedSocketAddress (io.grpc.ProxiedSocketAddress)1 ProxyDetector (io.grpc.ProxyDetector)1 AddressResolver (io.grpc.internal.DnsNameResolver.AddressResolver)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1