|
11 | 11 |
|
12 | 12 | package io.vertx.core.net.impl; |
13 | 13 |
|
| 14 | +import io.netty.buffer.ByteBufAllocator; |
| 15 | +import io.netty.buffer.PooledByteBufAllocator; |
14 | 16 | import io.netty.handler.ssl.OpenSsl; |
15 | 17 | import io.netty.handler.ssl.SslProvider; |
16 | 18 | import io.vertx.core.Future; |
17 | 19 | import io.vertx.core.Promise; |
18 | 20 | import io.vertx.core.VertxException; |
19 | 21 | import io.vertx.core.buffer.Buffer; |
| 22 | +import io.vertx.core.buffer.impl.PartialPooledByteBufAllocator; |
20 | 23 | import io.vertx.core.http.ClientAuth; |
21 | 24 | import io.vertx.core.impl.ContextInternal; |
22 | 25 | import io.vertx.core.net.ClientOptionsBase; |
@@ -57,6 +60,27 @@ public class SSLHelper { |
57 | 60 | CLIENT_AUTH_MAPPING.put(ClientAuth.NONE, io.netty.handler.ssl.ClientAuth.NONE); |
58 | 61 | } |
59 | 62 |
|
| 63 | + ByteBufAllocator clientByteBufAllocator(SslContextProvider ctxProvider) { |
| 64 | + if (usesJDKSSLWithPooledHeapBuffers(ctxProvider)) { |
| 65 | + return PooledByteBufAllocator.DEFAULT; |
| 66 | + } |
| 67 | + return PartialPooledByteBufAllocator.INSTANCE; |
| 68 | + } |
| 69 | + |
| 70 | + ByteBufAllocator serverByteBufAllocator(SslContextProvider ctxProvider) { |
| 71 | + if (!ssl || usesJDKSSLWithPooledHeapBuffers(ctxProvider)) { |
| 72 | + return PooledByteBufAllocator.DEFAULT; |
| 73 | + } |
| 74 | + return PartialPooledByteBufAllocator.INSTANCE; |
| 75 | + } |
| 76 | + |
| 77 | + private boolean usesJDKSSLWithPooledHeapBuffers(SslContextProvider ctxProvider) { |
| 78 | + return ssl && sslEngineOptions instanceof JdkSSLEngineOptions && |
| 79 | + ctxProvider.jdkSSLProvider() && |
| 80 | + ((JdkSSLEngineOptions) sslEngineOptions).isPooledHeapBuffers(); |
| 81 | + } |
| 82 | + |
| 83 | + |
60 | 84 | /** |
61 | 85 | * Resolve the ssl engine options to use for properly running the configured options. |
62 | 86 | */ |
@@ -149,18 +173,22 @@ private static class CachedProvider { |
149 | 173 |
|
150 | 174 | private class EngineConfig { |
151 | 175 |
|
| 176 | + private final boolean jdkSSLProvider; |
152 | 177 | private final SSLOptions sslOptions; |
153 | 178 | private final Supplier<SslContextFactory> supplier; |
154 | 179 | private final boolean useWorkerPool; |
155 | 180 |
|
156 | | - public EngineConfig(SSLOptions sslOptions, Supplier<SslContextFactory> supplier, boolean useWorkerPool) { |
| 181 | + public EngineConfig(boolean jdkSSLProvider, SSLOptions sslOptions, Supplier<SslContextFactory> supplier, |
| 182 | + boolean useWorkerPool) { |
| 183 | + this.jdkSSLProvider = jdkSSLProvider; |
157 | 184 | this.sslOptions = sslOptions; |
158 | 185 | this.supplier = supplier; |
159 | 186 | this.useWorkerPool = useWorkerPool; |
160 | 187 | } |
161 | 188 |
|
162 | 189 | SslContextProvider sslContextProvider() { |
163 | 190 | return new SslContextProvider( |
| 191 | + jdkSSLProvider, |
164 | 192 | clientAuth, |
165 | 193 | endpointIdentificationAlgorithm, |
166 | 194 | applicationProtocols, |
@@ -291,18 +319,20 @@ private Future<EngineConfig> build(SSLOptions sslOptions, ContextInternal ctx) { |
291 | 319 | }).compose(v2 -> ctx.<EngineConfig>executeBlockingInternal(p -> { |
292 | 320 | Supplier<SslContextFactory> supplier; |
293 | 321 | boolean useWorkerPool; |
| 322 | + final boolean jdkSSLProvider; |
294 | 323 | try { |
295 | 324 | SSLEngineOptions resolvedEngineOptions = resolveEngineOptions(sslEngineOptions, useAlpn); |
296 | 325 | supplier = resolvedEngineOptions::sslContextFactory; |
297 | 326 | useWorkerPool = resolvedEngineOptions.getUseWorkerThread(); |
| 327 | + jdkSSLProvider = resolvedEngineOptions instanceof JdkSSLEngineOptions; |
298 | 328 | } catch (Exception e) { |
299 | 329 | p.fail(e); |
300 | 330 | return; |
301 | 331 | } |
302 | | - p.complete(new EngineConfig(sslOptions, supplier, useWorkerPool)); |
| 332 | + p.complete(new EngineConfig(jdkSSLProvider, sslOptions, supplier, useWorkerPool)); |
303 | 333 | })).onComplete(promise); |
304 | 334 | } else { |
305 | | - sslContextFactorySupplier = Future.succeededFuture(new EngineConfig(sslOptions, () -> new DefaultSslContextFactory(SslProvider.JDK, false), SSLEngineOptions.DEFAULT_USE_WORKER_POOL)); |
| 335 | + sslContextFactorySupplier = Future.succeededFuture(new EngineConfig(true, sslOptions, () -> new DefaultSslContextFactory(SslProvider.JDK, false), SSLEngineOptions.DEFAULT_USE_WORKER_POOL)); |
306 | 336 | } |
307 | 337 | return sslContextFactorySupplier; |
308 | 338 | } |
|
0 commit comments