Skip to content

Commit bb39413

Browse files
netty: limit access to ProtocolNegotiators
1 parent 041cf2a commit bb39413

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import io.grpc.internal.GrpcAttributes;
3232
import io.grpc.internal.ObjectPool;
3333
import io.grpc.netty.GrpcHttp2ConnectionHandler;
34+
import io.grpc.netty.InternalProtocolNegotiators.AbstractBufferingHandler;
3435
import io.grpc.netty.ProtocolNegotiator;
35-
import io.grpc.netty.ProtocolNegotiators.AbstractBufferingHandler;
3636
import io.netty.channel.ChannelHandler;
3737
import io.netty.channel.ChannelHandlerContext;
3838
import io.netty.util.AsciiString;

alts/src/main/java/io/grpc/alts/internal/GoogleDefaultProtocolNegotiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import io.grpc.alts.internal.AltsProtocolNegotiator.LazyChannel;
2121
import io.grpc.internal.GrpcAttributes;
2222
import io.grpc.netty.GrpcHttp2ConnectionHandler;
23+
import io.grpc.netty.InternalProtocolNegotiators;
2324
import io.grpc.netty.ProtocolNegotiator;
24-
import io.grpc.netty.ProtocolNegotiators;
2525
import io.netty.handler.ssl.SslContext;
2626

2727
/** A client-side GPRC {@link ProtocolNegotiator} for Google Default Channel. */
@@ -35,7 +35,7 @@ public GoogleDefaultProtocolNegotiator(
3535
TsiHandshakerFactory altsFactory, LazyChannel lazyHandshakerChannel, SslContext sslContext) {
3636
altsProtocolNegotiator =
3737
AltsProtocolNegotiator.createClientNegotiator(altsFactory, lazyHandshakerChannel);
38-
tlsProtocolNegotiator = ProtocolNegotiators.tls(sslContext);
38+
tlsProtocolNegotiator = InternalProtocolNegotiators.tls(sslContext);
3939
}
4040

4141
@VisibleForTesting
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2019 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.netty;
18+
19+
import io.netty.channel.ChannelHandler;
20+
import io.netty.channel.ChannelHandlerContext;
21+
import io.netty.handler.ssl.SslContext;
22+
23+
/**
24+
* Internal accessor for {@link ProtocolNegotiators}.
25+
*/
26+
public final class InternalProtocolNegotiators {
27+
28+
private InternalProtocolNegotiators() {}
29+
30+
/**
31+
* Buffers all writes until either {@link #writeBufferedAndRemove(ChannelHandlerContext)} or
32+
* {@link #fail(ChannelHandlerContext, Throwable)} is called. This handler allows us to
33+
* write to a {@link io.netty.channel.Channel} before we are allowed to write to it officially
34+
* i.e. before it's active or the TLS Handshake is complete.
35+
*/
36+
public abstract static class AbstractBufferingHandler
37+
extends ProtocolNegotiators.AbstractBufferingHandler {
38+
39+
protected AbstractBufferingHandler(ChannelHandler... handlers) {
40+
super(handlers);
41+
}
42+
}
43+
44+
/**
45+
* Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
46+
* be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel.Channel}
47+
* may happen immediately, even before the TLS Handshake is complete.
48+
*/
49+
public static ProtocolNegotiator tls(SslContext sslContext) {
50+
return ProtocolNegotiators.tls(sslContext);
51+
}
52+
}

netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.common.base.Preconditions;
2525
import io.grpc.Attributes;
2626
import io.grpc.Grpc;
27-
import io.grpc.Internal;
2827
import io.grpc.InternalChannelz;
2928
import io.grpc.SecurityLevel;
3029
import io.grpc.Status;
@@ -74,8 +73,7 @@
7473
/**
7574
* Common {@link ProtocolNegotiator}s used by gRPC.
7675
*/
77-
@Internal
78-
public final class ProtocolNegotiators {
76+
final class ProtocolNegotiators {
7977
private static final Logger log = Logger.getLogger(ProtocolNegotiators.class.getName());
8078

8179
private ProtocolNegotiators() {

0 commit comments

Comments
 (0)