• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19465

20 Sep 2024 10:53PM UTC coverage: 84.549% (+0.005%) from 84.544%
#19465

push

github

web-flow
s2a: Address comments on PR#11113 (#11534)

* Mark S2A public APIs as experimental.

* Rename S2AChannelCredentials createBuilder API to newBuilder.

* Remove usage of AdvancedTls.

* Use InsecureChannelCredentials.create instead of Optional.

* Invoke Thread.currentThread().interrupt() in a InterruptedException block.

33621 of 39765 relevant lines covered (84.55%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.33
/../netty/src/main/java/io/grpc/netty/InternalProtocolNegotiators.java
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.grpc.ChannelLogger;
20
import io.grpc.internal.ObjectPool;
21
import io.grpc.netty.ProtocolNegotiators.ClientTlsHandler;
22
import io.grpc.netty.ProtocolNegotiators.GrpcNegotiationHandler;
23
import io.grpc.netty.ProtocolNegotiators.WaitUntilActiveHandler;
24
import io.netty.channel.ChannelHandler;
25
import io.netty.handler.ssl.SslContext;
26
import io.netty.util.AsciiString;
27
import java.util.concurrent.Executor;
28

29
/**
30
 * Internal accessor for {@link ProtocolNegotiators}.
31
 */
32
public final class InternalProtocolNegotiators {
33

34
  private InternalProtocolNegotiators() {}
35

36
  /**
37
   * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
38
   * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel.Channel}
39
   * may happen immediately, even before the TLS Handshake is complete.
40
   * @param executorPool a dedicated {@link Executor} pool for time-consuming TLS tasks
41
   */
42
  public static InternalProtocolNegotiator.ProtocolNegotiator tls(SslContext sslContext,
43
          ObjectPool<? extends Executor> executorPool) {
44
    final io.grpc.netty.ProtocolNegotiator negotiator = ProtocolNegotiators.tls(sslContext,
1✔
45
        executorPool);
46
    final class TlsNegotiator implements InternalProtocolNegotiator.ProtocolNegotiator {
1✔
47

48
      @Override
49
      public AsciiString scheme() {
50
        return negotiator.scheme();
×
51
      }
52

53
      @Override
54
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
55
        return negotiator.newHandler(grpcHandler);
1✔
56
      }
57

58
      @Override
59
      public void close() {
60
        negotiator.close();
×
61
      }
×
62
    }
63
    
64
    return new TlsNegotiator();
1✔
65
  }
66
  
67
  /**
68
   * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
69
   * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel.Channel}
70
   * may happen immediately, even before the TLS Handshake is complete.
71
   */
72
  public static InternalProtocolNegotiator.ProtocolNegotiator tls(SslContext sslContext) {
73
    return tls(sslContext, null);
1✔
74
  }
75

76
  /**
77
   * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will be
78
   * negotiated, the server TLS {@code handler} is added and writes to the {@link
79
   * io.netty.channel.Channel} may happen immediately, even before the TLS Handshake is complete.
80
   */
81
  public static InternalProtocolNegotiator.ProtocolNegotiator serverTls(SslContext sslContext) {
82
    final io.grpc.netty.ProtocolNegotiator negotiator = ProtocolNegotiators.serverTls(sslContext);
1✔
83
    final class ServerTlsNegotiator implements InternalProtocolNegotiator.ProtocolNegotiator {
1✔
84

85
      @Override
86
      public AsciiString scheme() {
87
        return negotiator.scheme();
×
88
      }
89

90
      @Override
91
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
92
        return negotiator.newHandler(grpcHandler);
1✔
93
      }
94

95
      @Override
96
      public void close() {
97
        negotiator.close();
×
98
      }
×
99
    }
100

101
    return new ServerTlsNegotiator();
1✔
102
  }
103

104
  /** Returns a {@link ProtocolNegotiator} for plaintext client channel. */
105
  public static InternalProtocolNegotiator.ProtocolNegotiator plaintext() {
106
    final io.grpc.netty.ProtocolNegotiator negotiator = ProtocolNegotiators.plaintext();
1✔
107
    final class PlaintextNegotiator implements InternalProtocolNegotiator.ProtocolNegotiator {
1✔
108

109
      @Override
110
      public AsciiString scheme() {
111
        return negotiator.scheme();
1✔
112
      }
113

114
      @Override
115
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
116
        return negotiator.newHandler(grpcHandler);
1✔
117
      }
118

119
      @Override
120
      public void close() {
121
        negotiator.close();
1✔
122
      }
1✔
123
    }
124

125
    return new PlaintextNegotiator();
1✔
126
  }
127

128
  /** Returns a {@link ProtocolNegotiator} for plaintext server channel. */
129
  public static InternalProtocolNegotiator.ProtocolNegotiator serverPlaintext() {
130
    final io.grpc.netty.ProtocolNegotiator negotiator = ProtocolNegotiators.serverPlaintext();
1✔
131
    final class ServerPlaintextNegotiator implements InternalProtocolNegotiator.ProtocolNegotiator {
1✔
132

133
      @Override
134
      public AsciiString scheme() {
135
        return negotiator.scheme();
×
136
      }
137

138
      @Override
139
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
140
        return negotiator.newHandler(grpcHandler);
×
141
      }
142

143
      @Override
144
      public void close() {
145
        negotiator.close();
×
146
      }
×
147
    }
148

149
    return new ServerPlaintextNegotiator();
1✔
150
  }
151

152
  /**
153
   * Internal version of {@link WaitUntilActiveHandler}.
154
   */
155
  public static ChannelHandler waitUntilActiveHandler(ChannelHandler next,
156
      ChannelLogger negotiationLogger) {
157
    return new WaitUntilActiveHandler(next, negotiationLogger);
×
158
  }
159

160
  /**
161
   * Internal version of {@link GrpcNegotiationHandler}.
162
   */
163
  public static ChannelHandler grpcNegotiationHandler(GrpcHttp2ConnectionHandler next) {
164
    return new GrpcNegotiationHandler(next);
×
165
  }
166

167
  public static ChannelHandler clientTlsHandler(
168
      ChannelHandler next, SslContext sslContext, String authority,
169
      ChannelLogger negotiationLogger) {
170
    return new ClientTlsHandler(next, sslContext, authority, null, negotiationLogger);
×
171
  }
172

173
  public static class ProtocolNegotiationHandler
174
      extends ProtocolNegotiators.ProtocolNegotiationHandler {
175

176
    protected ProtocolNegotiationHandler(ChannelHandler next, String negotiatorName,
177
        ChannelLogger negotiationLogger) {
178
      super(next, negotiatorName, negotiationLogger);
×
179
    }
×
180

181
    protected ProtocolNegotiationHandler(ChannelHandler next, ChannelLogger negotiationLogger) {
182
      super(next, negotiationLogger);
1✔
183
    }
1✔
184
  }
185
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc