mirror of https://github.com/grpc/grpc-java.git
netty: push sslContext initialization into transportCreationParamsFilterFactory
This commit is contained in:
parent
d3d30e1c3a
commit
e01cec5c2c
|
|
@ -432,7 +432,6 @@ public final class NettyChannelBuilder
|
|||
private final Class<? extends Channel> channelType;
|
||||
private final Map<ChannelOption<?>, ?> channelOptions;
|
||||
private final NegotiationType negotiationType;
|
||||
private final SslContext sslContext;
|
||||
private final EventLoopGroup group;
|
||||
private final boolean usingSharedGroup;
|
||||
private final int flowControlWindow;
|
||||
|
|
@ -452,23 +451,10 @@ public final class NettyChannelBuilder
|
|||
this.channelType = channelType;
|
||||
this.negotiationType = negotiationType;
|
||||
this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions);
|
||||
if (negotiationType == NegotiationType.TLS && sslContext == null) {
|
||||
try {
|
||||
sslContext = GrpcSslContexts.forClient().build();
|
||||
} catch (SSLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
this.sslContext = sslContext;
|
||||
|
||||
if (transportCreationParamsFilterFactory == null) {
|
||||
transportCreationParamsFilterFactory = new TransportCreationParamsFilterFactory() {
|
||||
@Override
|
||||
public TransportCreationParamsFilter create(
|
||||
SocketAddress targetServerAddress, String authority, String userAgent) {
|
||||
return new DynamicNettyTransportParams(targetServerAddress, authority, userAgent);
|
||||
}
|
||||
};
|
||||
transportCreationParamsFilterFactory =
|
||||
new DefaultNettyTransportCreationParamsFilterFactory(sslContext);
|
||||
}
|
||||
this.transportCreationParamsFilterFactory = transportCreationParamsFilterFactory;
|
||||
|
||||
|
|
@ -523,6 +509,27 @@ public final class NettyChannelBuilder
|
|||
}
|
||||
}
|
||||
|
||||
private final class DefaultNettyTransportCreationParamsFilterFactory
|
||||
implements TransportCreationParamsFilterFactory {
|
||||
private final SslContext sslContext;
|
||||
|
||||
private DefaultNettyTransportCreationParamsFilterFactory(SslContext sslContext) {
|
||||
if (negotiationType == NegotiationType.TLS && sslContext == null) {
|
||||
try {
|
||||
sslContext = GrpcSslContexts.forClient().build();
|
||||
} catch (SSLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
this.sslContext = sslContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportCreationParamsFilter create(
|
||||
SocketAddress targetServerAddress, String authority, String userAgent) {
|
||||
return new DynamicNettyTransportParams(targetServerAddress, authority, userAgent);
|
||||
}
|
||||
|
||||
@CheckReturnValue
|
||||
private final class DynamicNettyTransportParams implements TransportCreationParamsFilter {
|
||||
|
||||
|
|
@ -558,4 +565,5 @@ public final class NettyChannelBuilder
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue