Beispiel #1
0
 public void LogUnknownFrame(Direction direction, IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId,
                             Http2Flags flags, IByteBuffer data)
 {
     if (IsEnabled())
     {
         _logger.Log(_level, "{} {} UNKNOWN: frameType={} streamId={} flags={} length={} bytes={}",
                     ctx.Channel, direction, (byte)frameType & 0xFF, streamId, flags.Value, data.ReadableBytes, ToString(data));
     }
 }
Beispiel #2
0
        public virtual Task WriteFrameAsync(IChannelHandlerContext ctx, Http2FrameTypes frameType,
                                            int streamId, Http2Flags flags, IByteBuffer payload, IPromise promise)
        {
            SimplePromiseAggregator promiseAggregator = new SimplePromiseAggregator(promise);

            try
            {
                if (streamId < 0)
                {
                    ThrowHelper.ThrowArgumentException_PositiveOrZero(ExceptionArgument.StreamID);
                }
                IByteBuffer buf = ctx.Allocator.Buffer(Http2CodecUtil.FrameHeaderLength);
                // Assume nothing below will throw until buf is written. That way we don't have to take care of ownership
                // in the catch block.
                Http2CodecUtil.WriteFrameHeaderInternal(buf, payload.ReadableBytes, frameType, flags, streamId);
                _ = ctx.WriteAsync(buf, promiseAggregator.NewPromise());
            }
            catch (Exception t)
            {
                try
                {
                    _ = payload.Release();
                }
                finally
                {
                    promiseAggregator.SetException(t);
                    _ = promiseAggregator.DoneAllocatingPromises();
                }

                return(promiseAggregator.Task);
            }

            try
            {
                _ = ctx.WriteAsync(payload, promiseAggregator.NewPromise());
            }
            catch (Exception t)
            {
                promiseAggregator.SetException(t);
            }

            _ = promiseAggregator.DoneAllocatingPromises();
            return(promiseAggregator.Task);
        }
 public virtual Task WriteFrameAsync(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload, IPromise promise)
 {
     return(_innerWriter.WriteFrameAsync(ctx, frameType, streamId, flags, payload, promise));
 }
Beispiel #4
0
 public Task WriteFrameAsync(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload, IPromise promise)
 {
     _logger.LogUnknownFrame(Direction.Outbound, ctx, frameType, streamId, flags, payload);
     return(_writer.WriteFrameAsync(ctx, frameType, streamId, flags, payload, promise));
 }
Beispiel #5
0
 public virtual void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     _listener.OnUnknownFrame(ctx, frameType, streamId, flags, payload);
 }
 public void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
 }
 public void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     _logger.LogUnknownFrame(Direction.Inbound, ctx, frameType, streamId, flags, payload);
     _listener.OnUnknownFrame(ctx, frameType, streamId, flags, payload);
 }
Beispiel #8
0
 public void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     this.listener.OnUnknownFrame(ctx, frameType, streamId, flags, payload);
     this.messageLatch.SafeSignal();
 }
 public void WriteInboundFrame(Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     _writer.WriteFrameAsync(_ctx, frameType, streamId, flags, payload, _ctx.NewPromise()).GetAwaiter().GetResult();
 }
Beispiel #10
0
 internal static void WriteFrameHeaderInternal(IByteBuffer output, int payloadLength, Http2FrameTypes type,
                                               Http2Flags flags, int streamId)
 {
     _ = output.WriteMedium(payloadLength);
     _ = output.WriteByte((int)type);
     _ = output.WriteByte(flags.Value);
     _ = output.WriteInt(streamId);
 }
Beispiel #11
0
        void ProcessHeaderState(IByteBuffer input)
        {
            if (input.ReadableBytes < Http2CodecUtil.FrameHeaderLength)
            {
                // Wait until the entire frame header has been read.
                return;
            }

            // Read the header and prepare the unmarshaller to read the frame.
            _payloadLength = input.ReadUnsignedMedium();
            if (_payloadLength > _maxFrameSize)
            {
                ThrowHelper.ThrowConnectionError_FrameLengthExceedsMaximum(_payloadLength, _maxFrameSize);
            }

            _frameType = (Http2FrameTypes)input.ReadByte();
            _flags     = new Http2Flags(input.ReadByte());
            _streamId  = Http2CodecUtil.ReadUnsignedInt(input);

            // We have consumed the data, next time we read we will be expecting to read the frame payload.
            _readingHeaders = false;

            switch (_frameType)
            {
            case Http2FrameTypes.Data:
                VerifyDataFrame();
                break;

            case Http2FrameTypes.Headers:
                VerifyHeadersFrame();
                break;

            case Http2FrameTypes.Priority:
                VerifyPriorityFrame();
                break;

            case Http2FrameTypes.RstStream:
                VerifyRstStreamFrame();
                break;

            case Http2FrameTypes.Settings:
                VerifySettingsFrame();
                break;

            case Http2FrameTypes.PushPromise:
                VerifyPushPromiseFrame();
                break;

            case Http2FrameTypes.Ping:
                VerifyPingFrame();
                break;

            case Http2FrameTypes.GoAway:
                VerifyGoAwayFrame();
                break;

            case Http2FrameTypes.WindowUpdate:
                VerifyWindowUpdateFrame();
                break;

            case Http2FrameTypes.Continuation:
                VerifyContinuationFrame();
                break;

            default:
                // Unknown frame type, could be an extension.
                VerifyUnknownFrame();
                break;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Writes an HTTP/2 frame header to the output buffer.
 /// </summary>
 /// <param name="output"></param>
 /// <param name="payloadLength"></param>
 /// <param name="type"></param>
 /// <param name="flags"></param>
 /// <param name="streamId"></param>
 public static void WriteFrameHeader(IByteBuffer output, int payloadLength, Http2FrameTypes type,
                                     Http2Flags flags, int streamId)
 {
     _ = output.EnsureWritable(FrameHeaderLength + payloadLength);
     WriteFrameHeaderInternal(output, payloadLength, type, flags, streamId);
 }
Beispiel #13
0
 public DefaultHttp2UnknownFrame(Http2FrameTypes frameType, Http2Flags flags, IByteBuffer data)
     : base(data)
 {
     _frameType = frameType;
     _flags     = flags;
 }
Beispiel #14
0
 public DefaultHttp2UnknownFrame(Http2FrameTypes frameType, Http2Flags flags)
     : this(frameType, flags, Unpooled.Empty)
 {
 }
Beispiel #15
0
 public static void IgnoringFrameForStreamRst(this IInternalLogger logger, IChannelHandlerContext ctx, Http2FrameTypes frameName, bool isResetSent, int lastStreamKnownByPeer)
 {
     logger.Info("{} ignoring {} frame for stream {}", ctx.Channel, frameName,
                 isResetSent ? "RST_STREAM sent." :
                 ("Stream created after GOAWAY sent. Last known stream by peer " +
                  lastStreamKnownByPeer));
 }
Beispiel #16
0
 public static void IgnoringFrameForStream(this IInternalLogger logger, IChannelHandlerContext ctx, Http2FrameTypes frameName, int streamId)
 {
     logger.Info("{} ignoring {} frame for stream {}. Stream sent after GOAWAY sent",
                 ctx.Channel, frameName, streamId);
 }