Skip to content

Commit

Permalink
Revert SslEngineWrapperFactory api breakage introduced by 4448b8f.
Browse files Browse the repository at this point in the history
Motivation:

Commit 4448b8f introduced some API breakage which we need to revert before we release.

Modifications:

- Introduce an AllocatorAwareSslEngineWrapperFactory which expose an extra method that takes a ByteBufAllocator as well.
- Revert API changes to SslEngineWrapperFactory.

Result:

API breakage reverted.
  • Loading branch information
normanmaurer committed Aug 16, 2017
1 parent 3469004 commit 5d9a5d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public JdkAlpnApplicationProtocolNegotiator(ProtocolSelectorFactory selectorFact
super(ALPN_WRAPPER, selectorFactory, listenerFactory, protocols);
}

private static final class FailureWrapper implements SslEngineWrapperFactory {
private static final class FailureWrapper extends AllocatorAwareSslEngineWrapperFactory {
@Override
public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) {
Expand All @@ -118,7 +118,7 @@ public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
}
}

private static final class AlpnWrapper implements SslEngineWrapperFactory {
private static final class AlpnWrapper extends AllocatorAwareSslEngineWrapperFactory {
@Override
public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg
* Abstract factory pattern for wrapping an {@link SSLEngine} object. This is useful for NPN/APLN JDK support.
*/
interface SslEngineWrapperFactory {
/**
* Abstract factory pattern for wrapping an {@link SSLEngine} object. This is useful for NPN/APLN support.
*
* @param engine The engine to wrap.
* @param applicationNegotiator The application level protocol negotiator
* @param isServer <ul>
* <li>{@code true} if the engine is for server side of connections</li>
* <li>{@code false} if the engine is for client side of connections</li>
* </ul>
* @return The resulting wrapped engine. This may just be {@code engine}.
*/
SSLEngine wrapSslEngine(
SSLEngine engine, JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer);
}

abstract class AllocatorAwareSslEngineWrapperFactory implements SslEngineWrapperFactory {

@Override
public final SSLEngine wrapSslEngine(SSLEngine engine,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) {
return wrapSslEngine(engine, ByteBufAllocator.DEFAULT, applicationNegotiator, isServer);
}

/**
* Abstract factory pattern for wrapping an {@link SSLEngine} object. This is useful for NPN/APLN support.
*
Expand All @@ -40,8 +63,8 @@ interface SslEngineWrapperFactory {
* </ul>
* @return The resulting wrapped engine. This may just be {@code engine}.
*/
SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer);
abstract SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class JdkDefaultApplicationProtocolNegotiator implements JdkApplicationPro
new JdkDefaultApplicationProtocolNegotiator();
private static final SslEngineWrapperFactory DEFAULT_SSL_ENGINE_WRAPPER_FACTORY = new SslEngineWrapperFactory() {
@Override
public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
public SSLEngine wrapSslEngine(SSLEngine engine,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) {
return engine;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class JdkNpnApplicationProtocolNegotiator extends JdkBaseApplicatio
}

@Override
public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc,
public SSLEngine wrapSslEngine(SSLEngine engine,
JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) {
return new JettyNpnSslEngine(engine, applicationNegotiator, isServer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ private SSLEngine configureAndWrapEngine(SSLEngine engine, ByteBufAllocator allo
throw new Error("Unknown auth " + clientAuth);
}
}
return apn.wrapperFactory().wrapSslEngine(engine, alloc, apn, isServer());
JdkApplicationProtocolNegotiator.SslEngineWrapperFactory factory = apn.wrapperFactory();
if (factory instanceof JdkApplicationProtocolNegotiator.AllocatorAwareSslEngineWrapperFactory) {
return ((JdkApplicationProtocolNegotiator.AllocatorAwareSslEngineWrapperFactory) factory)
.wrapSslEngine(engine, alloc, apn, isServer());
}
return factory.wrapSslEngine(engine, apn, isServer());
}

@Override
Expand Down

0 comments on commit 5d9a5d3

Please sign in to comment.