Files
swift-nio-http2/Sources/NIOHTTP2/HTTP2ConcurrentStreamsHandler.swift
T
Cory Benfield 3c90345c36 Pure-Swift HTTP/2 implementation (#40)
* Updated to use SwiftNIO 1.10+ to gain access to HTTPHeaders internals.

* Add pure-Swift HTTP/2 protocol implementation.

Motivation:

Currently we use nghttp2 for our basic protocol implementation. This is
plenty workable, but provides us a number of limitations. It adds
complexity to our build system, provides us with external dependencies we
have little control over, limits our users' ability to express low-level
protocol semantics if they so wish, causes us to heap-allocate like crazy over
the lifetime of a connection, and brings a world of pain around reentrancy.

This set of limitations has motivated a desire to move away from using
nghttp2. This is a part of that dream.

Modifications:

- Add pure Swift protocol implementations.
- Test them.

Results:

Another step towards protocol independence.

* Initial basic parser code.

* Adding unit tests.

* Add NIOHTTP2FlowControlHandler

Motivation:

One of the things that nghttp2 used to do for us was to handle buffering
DATA frames until flow control allowed them to go out. For users that
want that behaviour, we need to replace the nghttp2 code with a new
ChannelHandler that can do this work.

Modifications:

- Added NIOHTTP2FlowControlHandler.

Result:

Users will have the same feature set as they did with nghttp2.

* Generate Linux test information.

* Documentation comment.

* Updated new tests from master to use new payload types.

* Updated following review.

Notable changes:

- Implemented unit tests for the ALTSVC (0xa) and ORIGIN (0xc) frame types.
- Additional DATA frames are synthesized to wrap individual payload chunks as they arrive. If the payload of a DATA frame with 4MB data arrives in 4 separate 1MB chunks, the decoder will emit 4 DATA frames, with only the last containing the END_STREAM flag (if that was set on the incoming frame).
- HEADERS / PUSH_PROMISE frames and any following CONTINUATION frames are now handled properly: header fragments from all frames are gathered up into a single buffer. Once a frame with END_HEADERS is encountered, the resultant accumulated buffer is sent for decoding along with the flags and stream ID of the original HEADERS / PUSH_PROMISE frame.
- HPACK encoders/decoders now live in the frame encoder/decoder types, rather than being attached to a stream.

* Updated Linux tests.

* Headers placed in relevant files.

* Add pure-Swift HTTP/2 protocol implementation.

Motivation:

Currently we use nghttp2 for our basic protocol implementation. This is
plenty workable, but provides us a number of limitations. It adds
complexity to our build system, provides us with external dependencies we
have little control over, limits our users' ability to express low-level
protocol semantics if they so wish, causes us to heap-allocate like crazy over
the lifetime of a connection, and brings a world of pain around reentrancy.

This set of limitations has motivated a desire to move away from using
nghttp2. This is a part of that dream.

Modifications:

- Add pure Swift protocol implementations.
- Test them.

Results:

Another step towards protocol independence.

* Revamped frame decoder state machine and API. Now uses separate input and output methods to manage multiple frames in a single buffer.

* Updated Linux tests.

* Bumped swift-nio version to 1.12.0 and updated `HTTPHeaders` -> `HPACKHeaders` conversion initializer to directly copy the buffer and map the header name/value indices.

* Set up HTTP2Parser in handlerAdded if the channel had been previously activated. (#36)

By setting up the handler in the handlerAdded hook, HTTP2Parser supports
being added dynamically in a channelRead event, after the channel has sent
the channelActive event.

(cherry picked from commit 88bd6d369a)

* Minor tweaks to get the tests passing

* Initial integration here

* Minor clearing up of the handler

* Get the tests compiling

* Fix header issues.

We now pass the frame parser to the various setting operations to let it
update the state. We also fixed some issues with specific settings.

* Remove ngthttp2-based impl, clean up stream ID

* Tests with new HTTP2StreamID

* Simple test cleanup

* Get remaining non-core tests passing

* Allow GOAWAY even when fully quiesced

* We don't buffer outbound frames any more

* Emit StreamClosed events on GoAway frame

* Notify stream creation and closure

* This test started failing

* Goodbye, C code! 🎉

* Send PING ACK automatically

* Updated based on PR feedback.

* Correctly handle 1XX responses

* Add SETTINGS_MAX_FRAME_SIZE support to flow controller

* Correctly account for flow control

* Define ConcurrentStreamsHandler

* Prepare for signalling connection state changes

* Better state change message propagation

* Refactor to use result with effect everywhere

* Don't lose flow control info on stream error

* Add basic flow control management to stream multiplexer

* Better pipeline in sample server

* Clean up some reentrancy concerns

* Move to Swift 5 and NIO 2

* Move to new Swift 5 for CI

* Allow wider range of choices of years

* Catch up to NIO 2 again
2019-02-21 11:52:49 +00:00

543 lines
24 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import NIO
/// A `ChannelHandler` that buffers new stream creation attempts to avoid violating
/// the HTTP/2 setting `SETTINGS_MAX_CONCURRENT_STREAMS`.
///
/// HTTP/2 provides tools for bounding the maximum amount of concurrent streams that a
/// given peer can create. This is used to limit the amount of state that a peer will need
/// to allocate for a given connection.
///
/// In an high-efficiency pipeline it will generally be better to limit the maximum number of
/// concurrent streams by avoiding creating new outbound streams. However, simpler applications
/// may prefer to delay stream creation instead, buffering frames until they can be delivered.
/// This `ChannelHandler` manages this transparently to the user by keeping track of the number
/// of active outbound streams and delaying any stream creation until safe.
///
/// Note that this `ChannelHandler` can and will re-order flushed frames. Having this `ChannelHandler`
/// in the pipeline means that frames written logically before others may nonetheless have their write
/// promises satisfied later. If this is a concern for your application, consider using the
/// `HTTP2StreamMultiplexer` to avoid a single `Channel` having its writes reordered.
public class NIOHTTP2ConcurrentStreamsHandler: ChannelDuplexHandler {
public typealias InboundIn = HTTP2Frame
public typealias InboundOut = HTTP2Frame
public typealias OutboundIn = HTTP2Frame
public typealias OutboundOut = HTTP2Frame
/// The buffer that will store frames as needed. Provides most of the logic of this
/// ChannelHandler.
private var frameBuffer: StreamFrameBuffer
/// The mode of the Channel we're operating in
private var mode: NIOHTTP2Handler.ParserMode {
get {
return self.frameBuffer.mode
}
}
public init(mode: NIOHTTP2Handler.ParserMode, initialMaxOutboundStreams: Int) {
self.frameBuffer = StreamFrameBuffer(mode: mode, initialMaxOutboundStreams: initialMaxOutboundStreams)
}
public func userInboundEventTriggered(ctx: ChannelHandlerContext, event: Any) {
switch event {
case let event as StreamClosedEvent:
// This event may make some frames writable. If it does, then we may be in write()
// (in which case we expect a pending flush), or we may be in flush() (in which case we're
// already looping) or we may be in a read cycle (in which case we'll get channelReadComplete
// soon). In any case, we will soon be writing frames, so we do not need to do so here.
// Instead, just keep track of the change internally.
self.frameBuffer.streamClosed(event.streamID)
case let event as NIOHTTP2StreamCreatedEvent:
self.frameBuffer.streamCreated(event.streamID)
default:
break
}
ctx.fireUserInboundEventTriggered(event)
}
public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
let frame = self.unwrapInboundIn(data)
guard case .settings(let newSettings) = frame.payload, !frame.flags.contains(.ack) else {
// Either this is not a settings frame, or it's a settings ACK. Either way we don't care.
// TODO(cory): We should handle GOAWAY!
ctx.fireChannelRead(data)
return
}
guard let newMaxConcurrentStreams = newSettings.lazy.reversed().first(where: { $0.parameter == .maxConcurrentStreams }).map( { $0.value } ) else {
// This settings frame didn't change the value of SETTINGS_MAX_CONCURRENT_STREAMS
ctx.fireChannelRead(data)
return
}
// This is allowed to shrink maxConcurrentStreams.
self.frameBuffer.maxOutboundStreams = newMaxConcurrentStreams
ctx.fireChannelRead(data)
}
public func channelReadComplete(ctx: ChannelHandlerContext) {
if self.writeIfPossible(ctx: ctx) {
ctx.flush()
}
ctx.fireChannelReadComplete()
}
public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
let frame = self.unwrapOutboundIn(data)
let operation: StreamFrameBuffer.OutboundFrameAction
do {
operation = try self.frameBuffer.processOutboundFrame(frame, promise: promise)
} catch {
promise?.fail(error)
return
}
switch operation {
case .nothing:
break
case .forward:
ctx.write(data, promise: promise)
case .forwardAndDrop(let writesToDrop, let error):
// We forward *first*, drop *second*.
ctx.write(data, promise: promise)
for (_, promise) in writesToDrop {
promise?.fail(error)
}
case .succeedAndDrop(let writesToDrop, let error):
// We drop *first*, succeed *second*
for (_, promise) in writesToDrop {
promise?.fail(error)
}
promise?.succeed(())
}
}
public func flush(ctx: ChannelHandlerContext) {
self.frameBuffer.flushReceived()
self.writeIfPossible(ctx: ctx)
ctx.flush()
}
@discardableResult
private func writeIfPossible(ctx: ChannelHandlerContext) -> Bool {
// We need to spin our writing loop. How does this work?
//
// We may be buffering a number of frames for streams that are now ready to be unbuffered.
// These streams will have become ready to be unbuffered due to some combination of flush
// calls and stream closures. Here we loop forward over all buffers capable of being somewhat
// unbuffered and punt those frames out. The act of punting those frames out may in fact cause
// more streams to become able to be flushed, which is just fine: nothing bad should happen.
var didWrite = false
while let (frame, promise) = self.frameBuffer.nextFlushedWritableFrame() {
ctx.write(self.wrapOutboundOut(frame), promise: promise)
didWrite = true
}
return didWrite
}
}
/// An object that manages buffering stream frames to avoid violating SETTINGS_MAX_CONCURRENT_STREAMS.
struct StreamFrameBuffer {
fileprivate struct FrameBuffer {
var frames: MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>
var streamID: HTTP2StreamID
var currentlyUnblocking: Bool
init(streamID: HTTP2StreamID) {
self.streamID = streamID
self.frames = MarkedCircularBuffer(initialCapacity: 16)
self.currentlyUnblocking = false
}
}
/// The mode of the HTTP/2 channel in which we're operating: client or server.
let mode: NIOHTTP2Handler.ParserMode
/// The current number of active outbound streams.
private(set) var currentOutboundStreams: Int = 0
/// The maximum number of active outbound streams, as set by the remote peer.
var maxOutboundStreams: Int
/// The last outbound stream we initiated.
private var lastOutboundStream: HTTP2StreamID = .rootStream
/// The frames we've buffered are stored here.
///
/// This circular buffer has an interesting property: by definition, it should always be sorted. This is because
/// correct construction of new streams requires that stream IDs monotonically increase. As we always pop streams off the
/// front and push them on the back of this buffer, it should remain in a sorted order forever. We have code that maintains
/// this invariant.
///
/// We regularly search this buffer, and rely on the ability to safely and quickly binary search this buffer.
private var bufferedFrames = SortedCircularBuffer(initialRingCapacity: 16)
init(mode: NIOHTTP2Handler.ParserMode, initialMaxOutboundStreams: Int) {
self.mode = mode
self.maxOutboundStreams = initialMaxOutboundStreams
}
/// Called when a stream has been closed.
///
/// Notes that the current number of outbound streams may have gone down, which is useful information
/// when flushing writes.
mutating func streamClosed(_ streamID: HTTP2StreamID) {
// We only care about outbound streams.
if streamID.mayBeInitiatedBy(self.mode) {
self.currentOutboundStreams -= 1
}
}
mutating func streamCreated(_ streamID: HTTP2StreamID) {
// We only care about outbound streams.
guard streamID.mayBeInitiatedBy(self.mode) else {
return
}
self.currentOutboundStreams += 1
precondition(self.currentOutboundStreams <= self.maxOutboundStreams)
precondition(self.lastOutboundStream <= streamID)
self.lastOutboundStream = streamID
}
mutating func flushReceived() {
self.bufferedFrames.markFlushPoint()
}
/// The result of receiving a frame that is about to be sent.
enum OutboundFrameAction {
/// The caller should forward the frame on.
case forward
/// This object has buffered the frame, no action should be taken.
case nothing
/// A number of frames have to be dropped on the floor due to a RST_STREAM frame being emitted, and the RST_STREAM
/// frame itself must be forwarded.
/// This cannot be done automatically without potentially causing exclusive access violations.
case forwardAndDrop(MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed)
/// A number of frames have to be dropped on the floor due to a RST_STREAM frame being emitted, and the RST_STREAM
/// frame itself should be succeeded and not forwarded.
/// This cannot be done automatically without potentially causing exclusive access violations.
case succeedAndDrop(MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed)
}
mutating func processOutboundFrame(_ frame: HTTP2Frame, promise: EventLoopPromise<Void>?) throws -> OutboundFrameAction {
// If this frame is not for a locally initiated stream, then that's fine, just pass it on.
guard frame.streamID != .rootStream && frame.streamID.mayBeInitiatedBy(self.mode) else {
return .forward
}
// Working out what to do here is awkward. The first concern is whether we're currently buffering frames for streams.
// If we are, it's possible we're buffering frames for this stream already. That may happen even when the stream is technically
// "live" if we have been re-entrantly called and haven't yet finished draining the buffer for this stream. As a result, if we're
// buffering frames we need to check if we're buffering for this stream. If we are, we just append to that buffer. If we're not,
// we don't yet know whether we should be buffering.
//
// Before we search our buffers for this stream we do a quick sanity check: if its stream ID is lower than the first element in the
// array, it won't be there.
if let firstElement = self.bufferedFrames.first,
frame.streamID >= firstElement.streamID,
let bufferIndex = self.bufferedFrames.binarySearch(key: { $0.streamID }, needle: frame.streamID) {
return self.bufferFrame(frame, promise: promise, bufferIndex: bufferIndex)
}
// Ok, we're not currently buffering frames for this stream.
// Now we need to check if this is for a stream that has already been opened. If it is, and we aren't buffering it, pass
// the frame through.
if frame.streamID <= self.lastOutboundStream {
return .forward
}
// Now we want to see whether we're allowed to initiate a new stream. If we aren't, then we will buffer this stream.
if self.currentOutboundStreams >= self.maxOutboundStreams {
// Ok, we can't create a new stream. In this case we need to buffer this. We can only have gotten this far if either this stream ID is lower
// than the first stream ID, or if it's higher but doesn't match something in the buffer. As a result, it is an error for this frame to have
// a stream ID lower than or equal to the highest stream ID in the buffer: if it did, we should have found it when we searched above. If that
// constraint is breached, fail the write.
if let lastElement = self.bufferedFrames.last, frame.streamID <= lastElement.streamID {
throw NIOHTTP2Errors.StreamIDTooSmall()
}
// Ok, the stream ID is fine: buffer this frame.
self.bufferFrameForNewStream(frame, promise: promise)
return .nothing
}
// Good news, we're allowed to send this frame! Let's do it.
return .forward
}
/// Returns the next flushed frame on a stream that is either currently active or which can be
/// made active.
mutating func nextFlushedWritableFrame() -> (HTTP2Frame, EventLoopPromise<Void>?)? {
// The stream buffers are bisected into two segments. The first, towards the start of the buffer,
// are currently unblocking: that is, we have a buffer, but the stream has been initiated already.
// The second set are those that have not currently been unblocked. Due to the requirements of
// ascending stream ID, if any of these have been flushed then the first one *must* have been.
// Thus, if we have room for another outbound stream, check the next stream and see if it has a
// flushed frame. If it does, flip its unblocking bit to true and grab the next frame out of it.
// Otherwise, we're done.
var index = self.bufferedFrames.startIndex
while index < self.bufferedFrames.endIndex {
guard self.bufferedFrames[index].currentlyUnblocking else {
// We've run out of currently unblocking frames. To the next step!
break
}
if self.bufferedFrames[index].frames.hasMark {
return self.bufferedFrames.nextWriteFor(index)
}
self.bufferedFrames.formIndex(after: &index)
}
// Ok, last shot. Does the next stream exist? If not, we're done.
guard index < self.bufferedFrames.endIndex else {
return nil
}
// Do we have room to start a new stream?
guard self.currentOutboundStreams < self.maxOutboundStreams else {
return nil
}
// We have room and the stream exists. Does it have flushed frames?
guard self.bufferedFrames[index].frames.hasMark else {
return nil
}
// It has flushed frames! Flip it to "unbuffering" and emit the first frame.
self.bufferedFrames.beginUnblocking(index)
return self.bufferedFrames.nextWriteFor(index)
}
private mutating func bufferFrame(_ frame: HTTP2Frame, promise: EventLoopPromise<Void>?, bufferIndex index: SortedCircularBuffer.Index) -> OutboundFrameAction {
// Ok, we need to buffer this frame, and we know we have the index for it. What we do here depends on this frame type. For
// almost all frames, we just append them to the buffer. For RST_STREAM, however, we're in a different spot. RST_STREAM is a
// request to drop all resources for a given stream. We know we have some, but we shouldn't wait to unblock them, we should
// just kill them now and immediately free the resources.
if case .rstStream(let reason) = frame.payload {
// We're going to remove the buffer and fail all the writes.
let writeBuffer = self.bufferedFrames.remove(at: index)
// If we're currently unbuffering this stream, we need to pass the RST_STREAM frame on for correctness. If we aren't, just
// kill it.
if writeBuffer.currentlyUnblocking {
return .forwardAndDrop(writeBuffer.frames, NIOHTTP2Errors.StreamClosed(streamID: frame.streamID, errorCode: reason))
} else {
return .succeedAndDrop(writeBuffer.frames, NIOHTTP2Errors.StreamClosed(streamID: frame.streamID, errorCode: reason))
}
}
// Ok, this is a frame we want to buffer. Append it.
self.bufferedFrames.bufferWrite(index: index, frame: frame, promise: promise)
return .nothing
}
private mutating func bufferFrameForNewStream(_ frame: HTTP2Frame, promise: EventLoopPromise<Void>?) {
// We need to buffer this frame. We should have previously checked that it's safe to buffer, so
// we charge on.
assert(self.bufferedFrames.count == 0 || (frame.streamID > self.bufferedFrames.last!.streamID))
var frameBuffer = FrameBuffer(streamID: frame.streamID)
frameBuffer.frames.append((frame, promise))
self.bufferedFrames.append(frameBuffer, key: { $0.streamID })
}
}
/// A simple wrapper around CircularBuffer that ensures that it remains sorted.
///
/// This removes CircularBuffer's MutableCollection conformance because it's not necessary
/// for our use-case here, and it greatly complicates the implementation. If we need it back
/// at any point we can arrange to return it.
///
/// I could have implemented this as a more general `SortedRandomAccessCollection` structure and
/// then provided specific hooks for appropriate implementations of `MutableCollection`, but altogether
/// that seemed unnecessary. Instead, we provide basically just the surface area we need, but with the
/// implementation of binarySearch written against the RandomAccessCollection protocol to make it more
/// portable in the future.
private struct SortedCircularBuffer {
private var _base: CircularBuffer<StreamFrameBuffer.FrameBuffer>
init(initialRingCapacity: Int) {
self._base = CircularBuffer(initialCapacity: initialRingCapacity)
}
/// Appends an element to this CircularBuffer. Traps if the element is not larger than the current end of this buffer.
mutating func append<SortKey: Comparable>(_ element: Element, key: (Element) -> SortKey) {
if let last = self._base.last {
precondition(key(element) >= key(last), "Attempted to append unsorted element")
}
self._base.append(element)
}
mutating func bufferWrite(index: Index, frame: HTTP2Frame, promise: EventLoopPromise<Void>?) {
// To make this work without CoW, we need to temporarily swap out either the entire element or the circular buffer within it to ensure that it
// is held loosely. We choose to swap the circular buffer within it as it avoids even temporarily violating the invariant that the
// backing array is sorted.
assert(frame.streamID == self._base[index].streamID)
var tempBuffer = MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>(initialCapacity: 0)
swap(&tempBuffer, &self._base[index].frames)
tempBuffer.append((frame, promise))
swap(&tempBuffer, &self._base[index].frames)
}
mutating func beginUnblocking(_ index: Index) {
assert(!self._base[index].currentlyUnblocking)
self._base[index].currentlyUnblocking = true
}
mutating func nextWriteFor(_ index: Index) -> (HTTP2Frame, EventLoopPromise<Void>?) {
// It is an error to call this when there is nothing in the backing buffer!
// To make this work without CoW, we need to temporarily swap out either the entire element or the circular buffer within it to ensure that it
// is held loosely. We choose to swap the circular buffer within it as it avoids even temporarily violating the invariant that the
// backing array is sorted.
var tempBuffer = MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>(initialCapacity: 0)
swap(&tempBuffer, &self._base[index].frames)
let write = tempBuffer.removeFirst()
swap(&tempBuffer, &self._base[index].frames)
if self._base[index].frames.count == 0 {
// We're done here, drop the buffer.
self._base.remove(at: index)
}
return write
}
mutating func remove(at index: Index) -> Element {
// This one is easy: simple removal does what we need here.
return self._base.remove(at: index)
}
mutating func markFlushPoint() {
var index = self._base.startIndex
while index < self._base.endIndex {
// This cannot CoW as it doesn't modify the circular buffer underneath the MCB.
self._base[index].frames.mark()
self._base.formIndex(after: &index)
}
}
}
extension SortedCircularBuffer: RandomAccessCollection {
typealias Element = CircularBuffer<StreamFrameBuffer.FrameBuffer>.Element
typealias Index = CircularBuffer<StreamFrameBuffer.FrameBuffer>.Index
typealias SubSequence = CircularBuffer<StreamFrameBuffer.FrameBuffer>.SubSequence
typealias Indices = CircularBuffer<StreamFrameBuffer.FrameBuffer>.Indices
var startIndex: Index {
return self._base.startIndex
}
var endIndex: Index {
return self._base.endIndex
}
var indices: Indices {
return self._base.indices
}
func distance(from start: Index, to end: Index) -> Int {
return self._base.distance(from: start, to: end)
}
func formIndex(after i: inout Index) {
self._base.formIndex(after: &i)
}
func formIndex(before i: inout Index) {
self._base.formIndex(before: &i)
}
func index(_ i: Index, offsetBy distance: Int) -> Index {
return self._base.index(i, offsetBy: distance)
}
func index(_ i: Index, offsetBy distance: Int, limitedBy limit: Index) -> Index? {
return self._base.index(i, offsetBy: distance, limitedBy: limit)
}
func index(after i: Index) -> Index {
return self._base.index(after: i)
}
func index(before i: Index) -> Index {
return self._base.index(before: i)
}
subscript(_ i: Index) -> Element {
return self._base[i]
}
subscript(_ range: Range<Index>) -> SubSequence {
return self._base[range]
}
}
extension SortedCircularBuffer {
func binarySearch<SearchKey: Comparable>(key: (Element) -> SearchKey, needle: SearchKey) -> Index? {
var bottomIndex = self.startIndex
var topIndex = self.endIndex
var sliceSize = self.distance(from: bottomIndex, to: topIndex)
while sliceSize > 0 {
let middleIndex = self.index(bottomIndex, offsetBy: sliceSize / 2)
switch key(self[middleIndex]) {
case let potentialKey where potentialKey > needle:
// Too big. We want to search everything smaller than here.
topIndex = middleIndex
case let potentialKey where potentialKey < needle:
// Too small. We want to search everything larger than here.
bottomIndex = self.index(after: middleIndex)
case let potentialKey:
// Got an answer!
assert(potentialKey == needle)
return middleIndex
}
sliceSize = self.distance(from: bottomIndex, to: topIndex)
}
return nil
}
}
private extension HTTP2StreamID {
func mayBeInitiatedBy(_ mode: NIOHTTP2Handler.ParserMode) -> Bool {
switch mode {
case .client:
return self.networkStreamID % 2 == 1
case .server:
return self.networkStreamID % 2 == 0
}
}
}