diff options
author | zpencer <spencerfang@google.com> | 2018-03-23 15:44:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 15:44:40 -0700 |
commit | a5b55bb24c413cef87b135647ea44cf6527a692c (patch) | |
tree | 9814315d66509bc6c286c581bf2d9052095bac8a /netty | |
parent | ae42d666add7a92073850fbed0bd629e767c12e1 (diff) | |
download | grpc-grpc-java-a5b55bb24c413cef87b135647ea44cf6527a692c.tar.gz |
netty,okhttp,testing: always set TRANSPORT_ATTR_REMOTE_ADDR (#4217)
Always set the remote address, no reason why this should be a TLS-only
feature. This is needed for channelz, and is especially useful in unit
tests where we are using plaintext.
This PR adds the attr for plaintext.
Diffstat (limited to 'netty')
-rw-r--r-- | netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java index c45a6ac6b..398ef8838 100644 --- a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java +++ b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java @@ -329,7 +329,7 @@ public final class ProtocolNegotiators { HttpClientCodec httpClientCodec = new HttpClientCodec(); final HttpClientUpgradeHandler upgrader = new HttpClientUpgradeHandler(httpClientCodec, upgradeCodec, 1000); - return new BufferingHttp2UpgradeHandler(upgrader); + return new BufferingHttp2UpgradeHandler(upgrader, handler); } } @@ -662,8 +662,11 @@ public final class ProtocolNegotiators { private static class BufferUntilChannelActiveHandler extends AbstractBufferingHandler implements ProtocolNegotiator.Handler { - BufferUntilChannelActiveHandler(ChannelHandler... handlers) { - super(handlers); + private final GrpcHttp2ConnectionHandler handler; + + BufferUntilChannelActiveHandler(GrpcHttp2ConnectionHandler handler) { + super(handler); + this.handler = handler; } @Override @@ -679,6 +682,11 @@ public final class ProtocolNegotiators { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { writeBufferedAndRemove(ctx); + handler.handleProtocolNegotiationCompleted( + Attributes + .newBuilder() + .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress()) + .build()); super.channelActive(ctx); } } @@ -689,8 +697,11 @@ public final class ProtocolNegotiators { private static class BufferingHttp2UpgradeHandler extends AbstractBufferingHandler implements ProtocolNegotiator.Handler { - BufferingHttp2UpgradeHandler(ChannelHandler... handlers) { - super(handlers); + private final GrpcHttp2ConnectionHandler grpcHandler; + + BufferingHttp2UpgradeHandler(ChannelHandler handler, GrpcHttp2ConnectionHandler grpcHandler) { + super(handler); + this.grpcHandler = grpcHandler; } @Override @@ -712,6 +723,11 @@ public final class ProtocolNegotiators { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt == HttpClientUpgradeHandler.UpgradeEvent.UPGRADE_SUCCESSFUL) { writeBufferedAndRemove(ctx); + grpcHandler.handleProtocolNegotiationCompleted( + Attributes + .newBuilder() + .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress()) + .build()); } else if (evt == HttpClientUpgradeHandler.UpgradeEvent.UPGRADE_REJECTED) { fail(ctx, unavailableException("HTTP/2 upgrade rejected")); } |