Search in sources :

Example 11 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyServerHandler method newHandler.

@VisibleForTesting
static NettyServerHandler newHandler(Http2FrameReader frameReader, Http2FrameWriter frameWriter, ServerTransportListener transportListener, int maxStreams, int flowControlWindow, int maxHeaderListSize, int maxMessageSize) {
    Preconditions.checkArgument(maxStreams > 0, "maxStreams must be positive");
    Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
    Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive");
    Http2Connection connection = new DefaultHttp2Connection(true);
    // Create the local flow controller configured to auto-refill the connection window.
    connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
    // TODO(ejona): swap back to DefaultHttp2Connection with Netty-4.1.9
    Http2ConnectionDecoder decoder = new FixedHttp2ConnectionDecoder(connection, encoder, frameReader);
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(flowControlWindow);
    settings.maxConcurrentStreams(maxStreams);
    settings.maxHeaderListSize(maxHeaderListSize);
    return new NettyServerHandler(transportListener, decoder, encoder, settings, maxMessageSize);
}
Also used : Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) DefaultHttp2LocalFlowController(io.netty.handler.codec.http2.DefaultHttp2LocalFlowController) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyClientHandler method newHandler.

@VisibleForTesting
static NettyClientHandler newHandler(Http2Connection connection, Http2FrameReader frameReader, Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, int flowControlWindow, int maxHeaderListSize, Ticker ticker) {
    Preconditions.checkNotNull(connection, "connection");
    Preconditions.checkNotNull(frameReader, "frameReader");
    Preconditions.checkNotNull(lifecycleManager, "lifecycleManager");
    Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
    Preconditions.checkNotNull(ticker, "ticker");
    Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyClientHandler.class);
    frameReader = new Http2InboundFrameLogger(frameReader, frameLogger);
    frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger);
    StreamBufferingEncoder encoder = new StreamBufferingEncoder(new DefaultHttp2ConnectionEncoder(connection, frameWriter));
    // Create the local flow controller configured to auto-refill the connection window.
    connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
    // TODO(ejona): swap back to DefaultHttp2Connection with Netty-4.1.9
    Http2ConnectionDecoder decoder = new FixedHttp2ConnectionDecoder(connection, encoder, frameReader);
    Http2Settings settings = new Http2Settings();
    settings.pushEnabled(false);
    settings.initialWindowSize(flowControlWindow);
    settings.maxConcurrentStreams(0);
    settings.maxHeaderListSize(maxHeaderListSize);
    return new NettyClientHandler(decoder, encoder, settings, lifecycleManager, keepAliveManager, ticker);
}
Also used : Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) Http2InboundFrameLogger(io.netty.handler.codec.http2.Http2InboundFrameLogger) StreamBufferingEncoder(io.netty.handler.codec.http2.StreamBufferingEncoder) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) DefaultHttp2LocalFlowController(io.netty.handler.codec.http2.DefaultHttp2LocalFlowController) Http2OutboundFrameLogger(io.netty.handler.codec.http2.Http2OutboundFrameLogger) Http2Settings(io.netty.handler.codec.http2.Http2Settings) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyHandlerTestBase method serializeSettings.

protected final ByteBuf serializeSettings(Http2Settings settings) {
    ChannelHandlerContext ctx = newMockContext();
    new DefaultHttp2FrameWriter().writeSettings(ctx, settings, newPromise());
    return captureWrite(ctx);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter)

Example 14 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyServerHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    // Simulate receipt of the connection preface
    handler().handleProtocolNegotiationCompleted(Attributes.EMPTY);
    channelRead(Http2CodecUtil.connectionPrefaceBuf());
    // Simulate receipt of initial remote settings.
    ByteBuf serializedSettings = serializeSettings(new Http2Settings());
    channelRead(serializedSettings);
}
Also used : GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ServerHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) ByteBuf(io.netty.buffer.ByteBuf) Before(org.junit.Before)

Example 15 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyClientHandlerTest method setUp.

/**
   * Set up for test.
   */
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    lifecycleManager = new ClientTransportLifecycleManager(listener);
    // it'll be null which will be testing if we behave correctly when it's not present.
    if (setKeepaliveManagerFor.contains(testNameRule.getMethodName())) {
        mockKeepAliveManager = mock(KeepAliveManager.class);
    }
    initChannel(new GrpcHttp2ClientHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    streamTransportState = new TransportStateImpl(handler(), DEFAULT_MAX_MESSAGE_SIZE);
    streamTransportState.setListener(streamListener);
    grpcHeaders = new DefaultHttp2Headers().scheme(HTTPS).authority(as("www.fake.com")).path(as("/fakemethod")).method(HTTP_METHOD).add(as("auth"), as("sometoken")).add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).add(TE_HEADER, TE_TRAILERS);
    // Simulate receipt of initial remote settings.
    ByteBuf serializedSettings = serializeSettings(new Http2Settings());
    channelRead(serializedSettings);
}
Also used : DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ClientHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) KeepAliveManager(io.grpc.internal.KeepAliveManager) ByteBuf(io.netty.buffer.ByteBuf) Before(org.junit.Before)

Aggregations

Http2Settings (io.netty.handler.codec.http2.Http2Settings)12 ByteBuf (io.netty.buffer.ByteBuf)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 Test (org.junit.Test)5 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)4 Buffer (io.vertx.core.buffer.Buffer)4 ChannelFuture (io.netty.channel.ChannelFuture)3 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)3 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)3 Http2Connection (io.netty.handler.codec.http2.Http2Connection)3 Http2ConnectionEncoder (io.netty.handler.codec.http2.Http2ConnectionEncoder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 Unpooled (io.netty.buffer.Unpooled)2 Channel (io.netty.channel.Channel)2 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)2 ChannelInitializer (io.netty.channel.ChannelInitializer)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2