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

grpc / grpc-java / #19504

10 Oct 2024 11:31PM UTC coverage: 84.654% (-0.01%) from 84.668%
#19504

push

github

web-flow
s2a: Add S2AStub cleanup handler. (#11600)

* Add S2AStub cleanup handler.

* Give TLS and Cleanup handlers name + update comment.

* Don't add TLS handler twice.

* Don't remove explicitly, since done by fireProtocolNegotiationEvent.

* plumb S2AStub close to handshake end + add integration test.

* close stub when TLS negotiation fails.

33781 of 39905 relevant lines covered (84.65%)

0.85 hits per line

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

56.76
/../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.Optional;
28
import java.util.concurrent.Executor;
29

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

35
  private InternalProtocolNegotiators() {}
36

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

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

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

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

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

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

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

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

103
    return new ServerTlsNegotiator();
1✔
104
  }
105

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

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

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

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

127
    return new PlaintextNegotiator();
1✔
128
  }
129

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

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

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

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

151
    return new ServerPlaintextNegotiator();
1✔
152
  }
153

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

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

169
  public static ChannelHandler clientTlsHandler(
170
      ChannelHandler next, SslContext sslContext, String authority,
171
      ChannelLogger negotiationLogger) {
172
    return new ClientTlsHandler(next, sslContext, authority, null, negotiationLogger,
×
173
        Optional.empty());
×
174
  }
175

176
  public static class ProtocolNegotiationHandler
177
      extends ProtocolNegotiators.ProtocolNegotiationHandler {
178

179
    protected ProtocolNegotiationHandler(ChannelHandler next, String negotiatorName,
180
        ChannelLogger negotiationLogger) {
181
      super(next, negotiatorName, negotiationLogger);
×
182
    }
×
183

184
    protected ProtocolNegotiationHandler(ChannelHandler next, ChannelLogger negotiationLogger) {
185
      super(next, negotiationLogger);
1✔
186
    }
1✔
187
  }
188
}
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

© 2026 Coveralls, Inc