213 Commits
Author SHA1 Message Date
George Barnett c5d10f4165 Add synchronous option to trunk push (#207)
See https://github.com/apple/swift-nio/pull/1551
1.12.2
2020-06-10 15:18:29 +01:00
George Barnett 5be29ae313 Update build_podspec.sh to not use exact dependency versions (#206)
Motivation:

The build_podspec.sh script generates a podspec which requires exact
versions of its dependencies. This very quickly turns into unresolvable
dependency graphs.

Modifications:

- NIO version passed to script must be in the format `MAJOR.MINOR`
- Podspec dependencies are now '>= MAJOR.MINOR', '< MAJOR+1'

Result:

Looser version requirements for podspecs
2020-06-10 13:50:40 +01:00
Cory Benfield c8f952dbc3 Respect target window size on inbound channels. (#205)
Motivation:

As part of #202 we added support for configuring the target window size
of stream channels. That was plumbed through into outbound channels, but
we missed the inbound ones, meaning that this only really worked for
clients, not servers. That hardly seems fair!

Modifications:

Pass target window size to inbound channels too.

Result:

We can control target window size of inbound channels.
1.12.1
2020-06-01 09:29:36 +01:00
Cory Benfield 5b31110289 Explicitly test we tolerate GREASE. (#204)
Motivation:

As Chrome has started GREASEing HTTP/2 settings and frames, we should
ensure that we have tests that explicitly validate that we tolerate
GREASEing these parameters.

A future version of swift-nio-http2 should start emitting GREASE as
well, but for now we'll satisfy ourselves with this.

Two relevant citations:

https://tools.ietf.org/html/draft-bishop-httpbis-grease-00

https://bugs.chromium.org/p/chromium/issues/detail?id=1083706

Modifications:

- Added a frame parser test
- Added a end-to-end settings test.

Result:

Validated that GREASE is tolerated.
2020-05-18 12:35:47 +01:00
Cory Benfield b66a08e4bc Add debugging info to HTTP2StreamChannel too. (#198)
Motivation:

Sometimes folks will want to print things about the HTTP2StreamChannel,
and we should give them the things we can safely get. We also may want a
shorter log for NIOHTTP2Handler as the standard description, with the
wall of text available in the debug description.

Modifications:

- Conform HTTP2StreamChannel to CustomStringConvertible
- Conform NIOHTTP2Handler to CustomDebugStringConvertible.

Result:

Even better debug info.
1.12.0
2020-05-11 13:28:56 +01:00
Johannes WeissandCory Benfield cdf3c48b15 link swift-nio-extras in docs (#195)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-05-11 12:53:34 +01:00
Cory Benfield 5f665cd9e2 Make HTTP2StreamChannel.isActive thread safe (#199)
Motivation:

All public parts of the Channel protocol, such as isActive, are required
to be thread safe. Unfortunately, we missed a spot with the isActive
bool on HTTP2StreamChannel.

Modifications:

Back the HTTP2StreamChannel.isActive bool with an atomic, and set it on
state change.

Result:

Thread-safety for public readers of channel activity
2020-05-11 12:44:32 +01:00
John KassebaumandCory Benfield 0ca9705831 Make multiplexer's targetWindowSize configurable and use configurability when creating stream channels. (#202)
Motivation:
Infow target window size constrains throughput. The default hardcoded 65535 is low for some use cases and so needs to be configrable. A TODO in the code stated 'Make configurable'.

Modifications:
- In HTTP2StreamMultiplexer, responding to a TODO where stream multiplexer creates a stream channel, created a multiplexr stored property to be used which is set in the default initilaizer.
- In HTTP2PipelineHelpers, added versions of configureHTTP2Pipeline(..) and configureCommonHTTP2ServerPipeline that require an activeTargetWindow arg.

Result:
Clients, such as GRPCClient, can configure pipelines with targetWindowSizes to their liking.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-05-11 12:34:43 +01:00
Cory Benfield 32db4dd7c2 Swap Huffman unnecessary var to let. (#203) 2020-05-11 11:49:17 +01:00
tomer doron 1cd4b833b3 improve 5.3 docker setup (#201)
motivation: pin to 5.3 nighties 

changes: use swiftlang/swift:nightly-5.3-master-bionic instead of swiftlang/swift:nightly-master-bionic
2020-05-05 07:04:57 +01:00
Max Desiatov 209f96ffec Link to CONTRIBUTING.md in README.md (#200)
Motivation:

Linking to `CONTRIBUTING.md` directly would save readers some time if they'd like to navigate to this file while reading `README.md`.

Modifications:

No functional change, only `README.md` is updated.

Result:

The rendered `README.md` will have a direct link to `CONTRIBUTING.md`.
2020-05-04 20:26:15 +01:00
Cory Benfield 271b5570e8 Improve debugging output for HTTP2Handler. (#197)
Motivation:

Sometimes it's useful to be able to print out objects and see their
internal state. Somehow, HTTP2Handler can't do this.

Modifications:

Add a conformance to HTTP2Handler.

Result:

Awesome debugging output.
2020-04-28 14:11:17 +01:00
Cory Benfield b26b154c4a Fixup the docker setup. (#196) 2020-04-20 19:02:19 +01:00
Jon Shier 82eb3fa097 Make replacement method public, clean up ACLs. (#194) 1.11.0 2020-03-21 08:13:55 +00:00
Shekhar Rajak 6970de5512 Get rid of do { ... } catch { ... } for expected errors (#192) 1.10.0 2020-03-17 17:57:00 +00:00
Mario SangiorgioandCory Benfield 798c19b86e Added helper to configure HTTP1 or H2 accordingly to the negotiated protocol (#193)
Motivation:

Applications might want to support H2 (when available) and HTTP1 (as a fallback).
The application logic should not change between the two versions of the protocol
and the code to configure support for both the protocols is boilerplate and can
be provided as an helper function.

Modifications:

This PR adds an helper function to configure HTTP1 or H2 pipelines according to
the protocol negotiated by the TLS handler.

Result:

Applications that need to support clients using both HTTP1 and H2 can
configure their channels by calling `configureCommonHTTPServerPipeline`,
which should reduce the boilerplate they have to write.

Co-Authored-By: Cory Benfield <lukasa@apple.com>
2020-03-17 14:34:32 +00:00
George Barnett fbfe24ccee Exert backpressure via stream flow control windows (#191)
Motivation:

When a window update event is received in the stream channel we notify
the inbound window manager. Doing so may emit a WINDOW_UPDATE frame
to indicate the remote may send us more DATA. However, this happens even
if there are inbound frames waiting to be delivered to the channel. This
may lead to the remote sending us more DATA which we have to buffer
until it is read.

Modifications:

- Update the inbound window manager to track the number of bytes
  buffered in the stream channel
- Account for buffered bytes when receiving a new window size event
- Possibly emit WINDOW_UPDATE after unbuffering inbound frames into the
  stream channel's pipeline

Result:

The timing of WINDOW_UPDATE frames is better aligned with when frames
are actually read in a stream.
2020-03-12 07:45:00 +00:00
Jake PrickettandJake Prickett 0841f641fc Update Build Podspec & Dependencies Script with weissi's Updates (#189)
Co-authored-by: Jake Prickett <jpricke1@ford.com>
2020-03-03 10:33:04 +00:00
tomer doron 780e3a290b update docs generation script to work better with selinux (#187)
motivation: docs scripts is broken on selinux due to restriction on ssh-agent

changes:
* change the jazzy workspace to a directory accessible by the CI node so we can push from the agent instead of from the docker container
* dont remove older docs when pushing new ones
* add version information and source links
2020-02-28 12:26:01 -08:00
Jake PrickettandJake Prickett 0c7d697b5f Update build_podspec and added SwiftNIOHPACK Dependency (#185)
Co-authored-by: Jake Prickett <jpricke1@ford.com>
2020-02-18 20:16:26 +00:00
Jake PrickettandJake Prickett a8550db895 Added Build Podspec Script (#184)
Co-authored-by: Jake Prickett <jpricke1@ford.com>
2020-02-14 14:49:05 +00:00
Johannes Weiss 65ebab9db7 stream channel initialiser: allow closed & failed (#183)
Motivation:

Previously, if we failed in the stream channel initialiser and the
stream channel was closed before finishing the stream channel
initialiser, we would crash on an assertion because `closedWhileOpen`
correctly asserted that it has nothing to do and shouldn't be called.

Modification:

Apart from `.idle` also stop calling `closedWhileOpen` in `.closed` and
`.localActive` because the network actually doesn't think this channel
is open.

Result:

- Fewer crashes
- fixes rdar://59342916
1.9.1
2020-02-11 13:03:41 +00:00
tomer doron 73be3a1d8b improve docker security (#180)
motivation: more secured ci setup

changes:
* enable :z selinux flag on bind mounts so we can enable selinux on ci
* drop potentially exploitable capabilities from docker-compose
2020-02-01 07:41:23 +00:00
Johannes Weiss c1bfb7ce3f fix new NIO and new Swift compiler warnings (#179) 1.9.0 2019-12-10 12:45:48 +00:00
Eric York 859f6b46aa Issue #151 Update BadStreamStateTransition to have stream state (#175)
Update BadStreamStateTransition to have an enum NIOHTTP2StreamState that shows which state the stream was in before the error.
1.8.0
2019-12-09 09:56:41 +00:00
George Barnett a8f89aa368 Add a subscript to HPACKHeaders to return the first value with a matc… (#178)
* Add a subscript to HPACKHeaders to return the first value with a matching name

Motivation:

In some cases you only expect (or care about) a single value for a
header. However, getting this value without allocating an array or
traversing the whole array requres using first(where:) provided by
Sequence. This is not very ergonomic as it requires users to do the
case-insensitive comparison and then exctact the value from the
HPACKHeader. Additionally, users cannot use NIO HTTP/2s case insensitive
ASCII comparison.

Modifications:

- Provide a first(name:) method on HPACKHeaders which returns the value
  from the first header whose name is a case insentive match of the
  subscript parameter.

Result:

It's easier to get the first
2019-12-04 12:07:31 +00:00
George Barnett ac157bc897 Update Code of Conduct project maintainer email address (#176)
Motivation:

The code-of-conduct email address is out-of-date.

Modifications:

Update code-of-conduct email address to swift-server-conduct@group.apple.com

Result:

- Code of conduct email address is up-to-date.
2019-12-02 12:05:32 +00:00
Cory Benfield bde711f760 Account for window size of stream closing frames (#174)
Motivation:

Frames that close a stream may consume some of the connection window. We
were not correctly accounting for that in the code, which meant that
frames that carried END_STREAM would not notify the stream multiplexer
that they had consumed connection window space. In the worst cases this
could lead to resource starvation due to consumption of this window
without causing us to emit new WINDOW_UPDATE frames.

Modifications:

StreamClosedEvents should be followed by flow control change events.

Result:

We will correctly update the connection window when a stream is closed.
2019-11-28 08:41:27 +00:00
Johannes Weiss 867259332c fix new warnings in very new Swift compilers (#172)
Motivation:

Newer Swift compilers warn about implicitly tupling the payload of an
enum case whilst pattern matching.

Modification:

Stop using implicit tupling.

Result:

No warnings on newer Swift compilers.
1.7.2
2019-11-19 17:29:13 +01:00
Johannes Weiss f70f8aab4e tolerate multiple RST_STREAMs for same stream (#171)
Motivation:

The HTTP/2 RFC does not explicitly forbid sending more than one
RST_STREAM for the same stream. Given that we have seen this behaviour
in the wild we are going to ignore any additional RST_STREAMs.

A further indicative that this is the right call is that the RFC
explicitly mentions that sending RST_STREAMs in the idle state is not
acceptable.

Modifications:

Ignore RST_STREAM frames for streams in the closed state.

Result:

More compatibility.
2019-11-19 16:08:21 +00:00
Cory Benfield 7cc32a9a41 Add HPACK & Huffman benchmarks. (#167)
Motivation:

Having benchmarks for the HPACK encoder and decoder gives us better
insight into their performance. While we have some simple benchmarks in
the XCTests, using the NIO performance tester framework will give us
more insight into what's happening.

While we're here, we can move the Huffman benchmarks out of the unit
tests and into the benchmark suite.

Modifications:

Added encoder, decoder, and huffman benchmarks.

Result:

Better performance numbers.
1.7.1
2019-11-13 08:43:10 +00:00
Cory Benfield 747e511b11 Force slow path header comparison to not inline. (#170)
Motivation:

We have a slow path in compareCaseInsensitiveASCIIBytes. On the server
this path will never be hit as to hit it requires having a
non-contiguous String, so we really really want the compiler to use all
its inlining smarts on the fast path instead. Currently it does, but as
Sequence.elementsEqual is inlinable we need to be sure that doesn't
change.

Modifications:

Force the slow path not to be inlined.

Result:

Guarantees about good inlining.
2019-11-12 16:30:22 +00:00
Cory Benfield 16c346b4cb Fix partial table lookups. (#168)
Motivation:

In many cases it's necessary to be able to do HPACK table lookups to
find only a matching header field name, when it isn't going to be
possible to use a fully indexed header. For example, when using
nonIndexable header fields you cannot use an indexed field value, so
there is no point looking at all the header field values anyway.

While we technically supported this, there were two wrinkles. The first
was that if you attempted to search for a header field without any care
for its name, we'd actually only search the static table, missing
anything added into the dynamic table, which is pretty stupid.

The second issue was that nonIndexable header fields did extra
unnecessary work. This is because we asked the header table to search
for an exact match, but then disregarded whether or not one was found.
That meant a bunch of wasted computation.

Modifications:

- Fixed the table lookup to correctly search both dynamic and static
    tables for partial matches.
- Correctly indicated that nonIndexable headers shouldn't care about
    matching the header value.

Result:

Better handling of non-indexable headers.
2019-11-12 12:20:50 +00:00
Johannes Weiss 994c319e03 namespace ChannelOptions & fix deprecations (#166) 1.7.0 2019-10-28 16:11:12 +00:00
tomer doron 97e8bbbcf8 api breakage detection (#163)
motivation: test for api breakage on PR

changes:
* add script to detect api breakage
* amend docker setup to include jq
2019-10-07 15:00:10 -07:00
tomer doron 84189320bc swift 5.1 docker setup (#158)
* swift 5.1 docker setup

motivation: support swift 5.1

changes:
* add docker compose file for swift 5.1, will add CI job once merged
* update swiftformat version to 0.40.12
* use more standard dockerfile setup

* 16.04
2019-09-24 21:58:38 +01:00
Trevör 32d063e90a Fix small documentation error (#157) 2019-09-19 11:56:57 +02:00
Johannes Weiss 790cf6fd2b remove hpack-test-case submodule (#156)
Motivation:

Submodules can cause trouble with mirrored git setups because they can't
be easily mirrored through SwiftPM's mirror support.

Modification:

Remove the hpack-test-case submodule and add as files.

Result:

Easier to mirror.
1.6.1
2019-09-12 19:55:19 +01:00
George Barnett 58bf1c964d Allow adding a sequence of headeers to HPACKHeaders (#155)
Motivation:

HPACKHeaders are similar to HTTPHeaders but are missing a few useful
features:
- adding a sequence of headers to avoid reallocations, and
- being expressible as a dictionary literal.

Modifications:

- Add two `add(contentsOf:)` methods, one for key/value pairs, one for
  key/value/indexing triplets.
- Add conformance to `ExpressibleByDictionaryLiteral`

Result:

HPACKHeaders is closer in feature parity to HTTPHeaders.
1.6.0
2019-09-10 12:44:09 +01:00
Johannes Weiss 9162b00fd5 fix dependencies: require NIO 2.3.0 (#154) 2019-09-10 12:08:04 +01:00
Johannes Weiss 114c4e0022 accept more valid-in-HTTP/1 but invalid-in-H2 messages (#153)
Motivation:

HTTP/2 is mostly just HTTP(/1) semantics with streams on a new wire
protocol. However, there are certain things that are legal in HTTP/1 but
which are illegal in HTTP/2.

Modification:

Accept more of those messages and transform them into their HTTP/2
equivalent.

Result:

- Easier to write HTTP/2 clients & servers in NIO.
- fixes #152
2019-09-09 16:15:46 +01:00
tomer doron e88138a44f update conduct email group (#150)
motivation: use consistent email across swift server projects

changes: set conduct email address to swift-server-conduct@group.apple.com
2019-08-20 20:59:55 +01:00
Johannes Weiss 7efcb61e29 recommend secure version (#149)
Motivation:

We should always recommend secure versions.

Modifcation:

Recommend `from: "1.5.0"`.

Result:

People will hopefully run more secure software.
2019-08-13 18:39:03 +01:00
Johannes Weiss 93f9b98b83 fix allocation counter limits (#148)
Motivation:

We regressed 4 allocations in the security update
https://github.com/apple/swift-nio-http2/security/advisories/GHSA-jchv-x857-q8fq
. Four allocations are a great tradeoff for a number of security
vulnerabilities fixed but we need to raise the limits accordingly.

Modifications:

Raise the limits to the new limit so tests can pass again.

Result:

PRs can pass again and master should build again.
2019-08-13 18:24:46 +01:00
Cory Benfield 86ce1dcd0d Merge pull request from GHSA-jchv-x857-q8fq
* Forbid excessive sending of empty DATA frames

Motivation:

One vector for DoS can be sending a large number of essentially "empty"
frames, such as empty DATA frames without END_STREAM set. We should
forbid peers from doing so excessively, but we want to tolerate
implementations that occasionally emit such a frame for buggy reasons.

Modifications:

- Added verification that too many empty DATA frames are not sent.

Result:

Better resistance to DoS attacks.

* Improved buffering in CompoundOutboundBuffer

Motivation:

In HTTP/2 it is possible for remote peers to submit work in a way that
cause the NIOHTTP2Handler to generate a substantial number of control
frames. If the peer is not consuming these frames, we can eventually run
out of memory and die, which is not exactly ideal.

It's hard for us to know how the buffering is going if we always submit
all frames directly to the Channel, so we need to pay attention to
whether the Channel is actually writable. If it isn't, rather than issue
further writes we need to delay those writes so we can keep track of how
big that buffer is getting. If the buffer gets too large we need a
circuit breaker to drop the connection, as we're clearly not able to get
work done.

This patch adds a new buffer for outbound control frames. This new
buffer is the last step in the buffering sequence, and the first to be
drained when a Channel becomes writable.

Additionally, enhancements need to be made to ensure that other buffers
behave correctly in the face of this new model. The
ConcurrentStreamsBuffer needs to be more aggressive about storing
HEADERS frames that cannot be emitted to the wire because it does not
tolerate emitting a HEADERS frame that cannot be immediately written to
the wire. Additionally, the buffers must not be polled when a Channel is
unwritable.

This is a large patch, but it does substantially change the buffering
logic, and protects NIO against a wide range of denial of service
attacks, while providing a clear and coherent defense surface.

Note that one thing this patch does not do is constrain the size of the
buffers in the ConcurrentStreamsBuffer. This is on purpose: the size of
this buffer is controlled entirely by user action. Users that do not
wish to buffer excessively in this buffer can avoid doing so simply by
respecting the peer's value of SETTINGS_MAX_CONCURRENT_STREAMS. As the
entire purpose of this buffer is to tolerate users that do not wish to
abide by this setting, it would be unreasonable to provide an upper
bound on the value used in this setting.

Modifications:

- Moved the various buffers into a directory.
- Built and implemented ControlFrameBuffer.
- Integrated ControlFrameBuffer into CompoundOutboundBuffer.
- Added awareness around channel writability to HTTP2Handler
- Enhanced ConcurrentStreamsBuffer to be writability-aware.

Result:

We'll have somewhere to put control frames.

* Cleanup API for merged security fixes.

Motivation:

After merging the security fixes we ended up with a slightly awkward
API: the argument names differed slightly for no good reason, and it
became impossible to override only one of the two security settings.

Modifications:

- Renamed `max` to `maximum`.
- Gave default values for the security settings.

Result:

Better user experience.

* Prevent DoS with large header lists.

Motivation:

There are two ways malicious peers could attempt to DoS a SwiftNIO
HTTP/2 implementation with header lists. The first would be to attempt
to send an enormous header list, ideally with an amplification factor.
This approach was possible because SwiftNIO never actually enforced the
value of the max header list size it advertised.

In principle the peer can still get a good amplification attack effect
by sending a long header list that contains zero-length headers. We may
as well close this door as well: zero length header field names are
unacceptable, and so we should forbid them.

Modifications:

- Added max header list enforcement.
- Forbade zero-length header field names.

Result:

Peers cannot DoS a SwiftNIO HTTP/2 implementation using large header
lists.
1.5.0
2019-08-13 18:00:41 +01:00
Cory Benfield 492a77b186 Support child channel writability management. (#142)
Motivation:

It's important to ensure that child channel users can observe the
writability state of a child channel in order to avoid ballooning data
in memory. Up until now we haven't supported writability notifications,
but we really should.

Modifications:

- Added a flow controller to manage writability.
- Managed data flow through promises.
- Lots of tests.

Result:

Child channels will provide a much better signal as to whether they are
writable.
1.4.0
2019-07-19 16:49:22 +01:00
Johannes Weiss 7de397fda8 ignore frames that don't have a HTTP/1 equivalent (#146)
Motivation:

Previously, the H2to1 codec would crash if for example a push promise
came by.

Modifications:

Instead of crashing, ignore the frames without equivalent.

Result:

Fewer crashes.
2019-07-18 17:04:27 +01:00
Cory Benfield 17434a9658 Allow servers to send PUSH_PROMISE before HEADERS. (#145)
Motivation:

RFC 7540 is not particularly clear on whether the server is required to
send PUSH_PROMISE frames before or after the HEADERS frame, or whether
both are acceptable. We took a somewhat hard-line approach by asserting
that PUSH_PROMISE could only be sent after the server sent HEADERS, but
we've now caught at least one notable implementation in the wild doing
something different (nghttp2).

Given that there's no clear normative language pointing in either
direction, we should consider being a bit more lenient and allowing
both.

Modifications:

- Updated the stream state machine to allow pushes on a locally-idle
stream.

Result:

Servers can send PUSH_PROMISE before they have sent HEADERS.
2019-07-18 15:33:57 +01:00
tomer doron 3d0b38268e add performance analysis docker-compose setup and script (#141)
motivation: prepare to run performance tests in ci

changes:

add performance-test docker-compose task
add script that can parse the performance test suite results and compare between two result-sets
add generic shell docker-compose task
2019-07-16 11:04:26 +01:00
Cory Benfield 06880b0abd Minimise channelReadComplete traffic. (#136)
Motivation:

Currently swift-nio-http2 is extremely naive with its use of
channelReadComplete calls in HTTP2StreamChannel, firing one
channelReadComplete call per frame read. In high frame load cases this
leads to a lot of excessive channelReadComplete traffic, which can cause
unnecessary time spent in flush calls.

We should try to minimise the amount of time we spend on this
bookkeeping and save the CPU cost.

Modifications:

- Store a linked-list of HTTP2StreamChannels that need to have
channelReadComplete fired on them.
- Fire channelReadComplete based on this linked list.

Result:

Moderate improvement in performance in high-throughput workloads.
1.3.0
2019-06-18 11:54:43 +01:00