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 Class<? extends Channel> channelType;
|
||||||
private final Map<ChannelOption<?>, ?> channelOptions;
|
private final Map<ChannelOption<?>, ?> channelOptions;
|
||||||
private final NegotiationType negotiationType;
|
private final NegotiationType negotiationType;
|
||||||
private final SslContext sslContext;
|
|
||||||
private final EventLoopGroup group;
|
private final EventLoopGroup group;
|
||||||
private final boolean usingSharedGroup;
|
private final boolean usingSharedGroup;
|
||||||
private final int flowControlWindow;
|
private final int flowControlWindow;
|
||||||
|
|
@ -452,23 +451,10 @@ public final class NettyChannelBuilder
|
||||||
this.channelType = channelType;
|
this.channelType = channelType;
|
||||||
this.negotiationType = negotiationType;
|
this.negotiationType = negotiationType;
|
||||||
this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions);
|
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) {
|
if (transportCreationParamsFilterFactory == null) {
|
||||||
transportCreationParamsFilterFactory = new TransportCreationParamsFilterFactory() {
|
transportCreationParamsFilterFactory =
|
||||||
@Override
|
new DefaultNettyTransportCreationParamsFilterFactory(sslContext);
|
||||||
public TransportCreationParamsFilter create(
|
|
||||||
SocketAddress targetServerAddress, String authority, String userAgent) {
|
|
||||||
return new DynamicNettyTransportParams(targetServerAddress, authority, userAgent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
this.transportCreationParamsFilterFactory = transportCreationParamsFilterFactory;
|
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
|
@CheckReturnValue
|
||||||
private final class DynamicNettyTransportParams implements TransportCreationParamsFilter {
|
private final class DynamicNettyTransportParams implements TransportCreationParamsFilter {
|
||||||
|
|
||||||
|
|
@ -559,3 +566,4 @@ public final class NettyChannelBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue