|
32 | 32 | import com.google.common.util.concurrent.ListenableFuture;
|
33 | 33 | import com.google.common.util.concurrent.ListeningExecutorService;
|
34 | 34 | import com.google.common.util.concurrent.MoreExecutors;
|
| 35 | +import io.grpc.ChannelCredentials; |
| 36 | +import io.grpc.Grpc; |
| 37 | +import io.grpc.InsecureChannelCredentials; |
35 | 38 | import io.grpc.ManagedChannel;
|
36 | 39 | import io.grpc.ManagedChannelBuilder;
|
37 | 40 | import io.grpc.Server;
|
38 | 41 | import io.grpc.ServerBuilder;
|
39 | 42 | import io.grpc.Status;
|
40 | 43 | import io.grpc.StatusException;
|
41 |
| -import io.grpc.netty.GrpcSslContexts; |
42 |
| -import io.grpc.netty.NegotiationType; |
43 |
| -import io.grpc.netty.NettyChannelBuilder; |
| 44 | +import io.grpc.TlsChannelCredentials; |
44 | 45 | import io.grpc.stub.StreamObserver;
|
45 | 46 | import io.grpc.testing.TlsTesting;
|
46 |
| -import io.netty.handler.ssl.SslContext; |
47 | 47 | import java.io.IOException;
|
48 |
| -import java.net.InetAddress; |
49 | 48 | import java.net.InetSocketAddress;
|
50 | 49 | import java.net.URI;
|
51 | 50 | import java.net.URISyntaxException;
|
52 |
| -import java.net.UnknownHostException; |
53 | 51 | import java.util.ArrayList;
|
54 | 52 | import java.util.Collections;
|
55 | 53 | import java.util.Iterator;
|
@@ -296,19 +294,9 @@ private List<InetSocketAddress> parseServerAddresses(String addressesStr) {
|
296 | 294 | List<InetSocketAddress> addresses = new ArrayList<>();
|
297 | 295 |
|
298 | 296 | for (List<String> namePort : parseCommaSeparatedTuples(addressesStr)) {
|
299 |
| - InetAddress address; |
300 | 297 | String name = namePort.get(0);
|
301 | 298 | int port = Integer.valueOf(namePort.get(1));
|
302 |
| - try { |
303 |
| - address = InetAddress.getByName(name); |
304 |
| - if (serverHostOverride != null) { |
305 |
| - // Force the hostname to match the cert the server uses. |
306 |
| - address = InetAddress.getByAddress(serverHostOverride, address.getAddress()); |
307 |
| - } |
308 |
| - } catch (UnknownHostException ex) { |
309 |
| - throw new RuntimeException(ex); |
310 |
| - } |
311 |
| - addresses.add(new InetSocketAddress(address, port)); |
| 299 | + addresses.add(new InetSocketAddress(name, port)); |
312 | 300 | }
|
313 | 301 |
|
314 | 302 | return addresses;
|
@@ -341,19 +329,28 @@ private static List<List<String>> parseCommaSeparatedTuples(String str) {
|
341 | 329 | }
|
342 | 330 |
|
343 | 331 | private ManagedChannel createChannel(InetSocketAddress address) {
|
344 |
| - SslContext sslContext = null; |
345 |
| - if (useTestCa) { |
346 |
| - try { |
347 |
| - sslContext = GrpcSslContexts.forClient().trustManager( |
348 |
| - TlsTesting.loadCert("ca.pem")).build(); |
349 |
| - } catch (Exception ex) { |
350 |
| - throw new RuntimeException(ex); |
| 332 | + ChannelCredentials channelCredentials; |
| 333 | + if (useTls) { |
| 334 | + if (useTestCa) { |
| 335 | + try { |
| 336 | + channelCredentials = TlsChannelCredentials.newBuilder() |
| 337 | + .trustManager(TlsTesting.loadCert("ca.pem")) |
| 338 | + .build(); |
| 339 | + } catch (Exception ex) { |
| 340 | + throw new RuntimeException(ex); |
| 341 | + } |
| 342 | + } else { |
| 343 | + channelCredentials = TlsChannelCredentials.create(); |
351 | 344 | }
|
| 345 | + } else { |
| 346 | + channelCredentials = InsecureChannelCredentials.create(); |
| 347 | + } |
| 348 | + ManagedChannelBuilder<?> builder = Grpc.newChannelBuilderForAddress( |
| 349 | + address.getHostString(), address.getPort(), channelCredentials); |
| 350 | + if (serverHostOverride != null) { |
| 351 | + builder.overrideAuthority(serverHostOverride); |
352 | 352 | }
|
353 |
| - return NettyChannelBuilder.forAddress(address) |
354 |
| - .negotiationType(useTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT) |
355 |
| - .sslContext(sslContext) |
356 |
| - .build(); |
| 353 | + return builder.build(); |
357 | 354 | }
|
358 | 355 |
|
359 | 356 | private static String serverAddressesToString(List<InetSocketAddress> addresses) {
|
|
0 commit comments