Commit Graph

110 Commits

Author SHA1 Message Date
Sean McArthur
4398e169e8 Update to Tokio 0.2 (#428) 2019-11-27 14:53:57 -08:00
Sean McArthur
4c1d797712 Add ability to adjust INITIAL_WINDOW_SIZE setting on an existing connection (#421) 2019-10-07 15:29:23 -07:00
Sean McArthur
2d90efee17 Prune futures-* dependencies 2019-08-30 14:53:49 -07:00
Gurwinder Singh
f46840f3fa chore: cargo fmt, clippy 2019-08-16 22:27:39 -07:00
Gurwinder Singh
ad7ffa795f Updated as per review comments 2019-08-16 18:47:47 -07:00
Gurwinder Singh
c8fefd49f1 Update lib to std-future 2019-08-16 18:47:47 -07:00
Jakub Beránek
db6b841e67 Update crate to Rust 2018 (#383) 2019-07-23 10:18:43 -07:00
Sean McArthur
a3e59eb7e2 Prevent server Connection from returning same error after calling abrupt shutdown (#352) 2019-04-03 11:41:56 -07:00
Sean McArthur
492f4e7f11 Make 'pending reset' streams not count towards active streams 2019-03-12 17:17:02 -07:00
Sean McArthur
e3a73f726e Add user PING support (#346)
- Add `share::PingPong`, which can send `Ping`s, and poll for the `Pong`
  from the peer.
2019-02-18 15:59:11 -08:00
Steven Fackler
66a5d113d4 Shutdown the stream along with connection (#304)
This will in particular send close notify alerts for TLS streams.
2018-08-09 10:36:30 -07:00
Carl Lerche
cf62b783e0 Misc bug fixes related to stream state (#273)
This patch includes two new significant debug assertions:

* Assert stream counts are zero when the connection finalizes.
* Assert all stream state has been released when the connection is 
  dropped.

These two assertions were added in an effort to test the fix provided
by #261. In doing so, many related bugs have been discovered and fixed.
The details related to these bugs can be found in #273.
2018-05-09 15:03:21 -07:00
Geoffry Song
11f914150e Add some missing bounds checks. (#260) 2018-04-23 14:38:42 -07:00
Sean McArthur
dca336f8b2 send proper max stream ID in graceful goaway (#254) 2018-04-06 15:51:34 -07:00
Sean McArthur
1c5d4ded50 Add Graceful Shutdown support
If graceful shutdown is initiated, a GOAWAY of the max stream ID - 1 is
sent, followed by a PING frame, to measure RTT. When the PING is ACKed,
the connection sends a new GOAWAY with the proper last processed stream
ID. From there, once all active streams have completely, the connection
will finally close.
2018-03-29 13:51:30 -07:00
Darren Tsung
4595b54cfa Add initial_max_send_streams() as builder option (#242) 2018-03-16 11:58:06 -07:00
Darren Tsung
0c59957d88 When Streams are dropped, close Connection (#221) (#222)
When all Streams are dropped / finished, the Connection was held
open until the peer hangs up. Instead, the Connection should hang up
once it knows that nothing more will be sent.

To fix this, we notify the Connection when a stream is no longer
referenced. On the Connection poll(), we check that there are no
active, held, reset streams or any references to the Streams
and transition to sending a GOAWAY if that is case.

The specific behavior depends on if running as a client or server.
2018-02-15 13:14:18 -08:00
Sean McArthur
1ea9a8fc7e ignore received frames on a stream locally reset for some time (#174)
- Adds config duration for how long to ignore frames on a reset stream
- Adds config for how many reset streams can be held at a time
2017-12-18 11:09:38 -08:00
Sean McArthur
2be2523162 notify stream refs when the connection receives EOF (#176) 2017-11-28 13:42:22 -08:00
Carl Lerche
c4fc2928fe API cleanup (#155)
* Change send_reset to take &mut self.

While calling this function is the last thing that should be done with
the instance, the intent of the h2 library is not to be used directly by
users, but to be used as an implementation detail by other libraries.

Requiring `self` on `send_reset` is pretty annoying when calling the
function from inside a `Future` implementation. Also, all the other fns
on the type take `&mut self`.

* Remove the P: Peer generic from internals

* Split out `Respond` from `server::Stream`

This new type is used to send HTTP responses to the client as well as
reserve streams for push promises.

* Remove unused `Send` helper.

This could be brought back later when the API becomes stable.

* Unite `client` and `server` types

* Remove `B` generic from internal proto structs

This is a first step in removing the `B` generic from public API types
that do not strictly require it.

Currently, all public API types must be generic over `B` even if they do
not actually interact with the send data frame type. The first step in
removing this is to remove `B` as a generic on all internal types.

* Remove `Buffer<B>` from inner stream state

This is the next step in removing the `B` generic from all public API
types. The send buffer is the only type that requires `B`. It has now
been extracted from the rest of the stream state.

The strategy used in this PR requires an additional `Arc` and `Mutex`,
but this is not a fundamental requirement. The additional overhead can
be avoided with a little bit of unsafe code. However, this optimization
should not be made until it is proven that it is required.

* Remove `B` generic from `Body` + `ReleaseCapacity`

This commit actually removes the generic from these two public API
types. Also note, that removing the generic requires that `B: 'static`.
This is because there is no more generic on `Body` and `ReleaseCapacity`
and the compiler must be able to ensure that `B` outlives all `Body` and
`ReleaseCapacity` handles.

In practice, in an async world, passing a non 'static `B` is never going
to happen.

* Remove generic from `ResponseFuture`

This change also makes generic free types `Send`. The original strategy
of using a trait object meant that those handles could not be `Send`.
The solution was to avoid using the send buffer when canceling a stream.
This is done by transitioning the stream state to `Canceled`, a new
`Cause` variant.

* Simplify Send::send_reset

Now that implicit cancelation goes through a separate path, the
send_reset function can be simplified.

* Export types common to client & server at root

* Rename Stream -> SendStream, Body -> RecvStream

* Implement send_reset on server::Respond
2017-10-19 20:02:08 -07:00
Sean McArthur
5c1bde7d62 add set_target_window_size methods to Server and Client (#149)
Closes #101
2017-10-13 11:19:56 -07:00
Eliza Weisman
2fcf8c3740 Add methods to {client, server}::Builder to set max concurrent streams (#150)
This PR adds `max_concurrent_streams()` methods to the client and server `Builder`s to set the `max_concurrent_streams` setting. I've added unit tests to ensure the correct SETTINGS frame is sent.

Closes #106
2017-10-10 17:36:45 -05:00
Holt Chesley
2aee78c7d7 Issue 128: Convert frame::Reason to struct (#142)
Alter frame::Reason to a struct with a single u32 member.
Introduce Constants to the impl for existing Reasons. Change all usage
in the library and its tests to adopt this change,
using the new constants.
2017-10-08 13:13:07 -07:00
Sean McArthur
720fb20bbf remove unused pieces from PingPong (#134)
Adds some extra tests as well, to be sure.
2017-10-05 19:16:14 -07:00
Sean McArthur
ecd2764f4b when receiving a GOAWAY, allow earlier streams to still process (#133)
Once all active streams have finished, send a GOAWAY back and close the
connection.
2017-10-05 15:32:13 -07:00
Sean McArthur
f8efb053b9 split Client into (Client, Connection) (#107)
The Connection type is a `Future` that drives all of the IO of the
client connection.

The Client type is separate, and is used to send requests into the
connection.
2017-09-28 16:55:12 -07:00
Oliver Gould
dad113e17b Disallow nightly failures (#115)
Always install rustfmt since nightly may change underneath it, causing
linking to break.

Apply rustfmt
2017-09-24 19:25:50 -07:00
Sean McArthur
db8c109817 Client::poll_ready() returns an Error if next stream ID would overflow (#103)
Closes #102
2017-09-19 14:16:32 -07:00
Sean McArthur
0c8bd75224 check for StreamId overflow (#68) 2017-09-19 13:10:48 -07:00
Sean McArthur
a8a4cd2be1 add Client config to disable server push
- Adds `Client::builder().enable_push(false)` to disable push
- Client sends a GO_AWAY if receiving a push when it's disabled
2017-09-18 10:49:35 -07:00
Sean McArthur
3ec0e85e56 add test when stream window overflows before conn window 2017-09-13 14:32:27 -07:00
Sean McArthur
ed472f109c add client::Builder to configure Clients 2017-09-13 14:32:27 -07:00
Sean McArthur
f7d14861e5 rustfmt: add trailing commas in match arms, set fn call to block stle (#85) 2017-09-12 19:29:06 -07:00
Oliver Gould
897bf84163 Use rustfmt to enforce consistent formatting
This change adds a .rustfmt.toml that includes ALL supported settings,
12 of which we have overridden to attempt to cater to our own
proclivities.

rustfmt is checked in the rust-nightly CI job.
2017-09-12 22:29:35 +00:00
Carl Lerche
5c0efcf8c4 Ref count stream state and release when final (#73)
Previously, stream state was never released so that long-lived connections
leaked memory.

Now, stream states are reference-counted and freed from the stream slab
when complete.  Locally reset streams are retained so that received frames
may be ignored.
2017-09-10 16:01:19 -07:00
Carl Lerche
38bbf30b2f Fix bug in prioritization (#63)
The stream buffered data counter was never decremented.
2017-09-07 14:12:21 -07:00
Carl Lerche
c122e97127 Refactor errors (#46)
This patch does a bunch of refactoring, mostly around error types, but it also
paves the way to allow `Codec` to be used standalone.

* `Codec` (and `FramedRead` / `FramedWrite`) is broken out into a codec module.
* An h2-codec crate is created that re-exports the frame and codec modules.
* New error types are introduced in the internals:
  * `RecvError` represents errors caused by trying to receive a frame.
  * `SendError` represents errors caused by trying to send a frame.
  * `UserError` is an enum of potential errors caused by invalid usage
    by the user of the lib.
  * `ProtoError` is either a `Reason` or an `io::Error`. However it doesn't
    specify connection or stream level.
  * `h2::Error` is an opaque error type and is the only error type exposed
    by the public API (used to be `ConnectionError`).

There are misc code changes to enable this as well. The biggest is a new "sink"
API for `Codec`. It provides buffer which queues up a frame followed by flush
which writes everything that is queued. This departs from the `Sink` trait in
order to provide more accurate error values. For example, buffer can never fail
(but it will panic if `poll_ready` is not called first).
2017-09-02 11:12:50 -07:00
Carl Lerche
9bb34d907a Thread P generic through all 2017-08-30 18:16:21 -04:00
Carl Lerche
14f35f1be6 Handle malformed HEADERS 2017-08-30 18:16:21 -04:00
Carl Lerche
b0e6867877 Fix warnings 2017-08-24 15:52:01 -07:00
Carl Lerche
807d2b7317 Wire in recv flow control (#26) 2017-08-23 11:22:24 -07:00
Oliver Gould
e015d7bfba Implement Client::poll_ready (#21)
Client::poll_ready ensures that the connection is ale to to initiate a new request stream to the remote server.  When the server is at capacity, a task is stored to be notified when capacity is available.
2017-08-15 13:46:55 -07:00
Carl Lerche
8a15663ed2 Progress towards allowing large writes 2017-08-11 16:57:51 -07:00
Carl Lerche
32d4c2d5a9 Many more changes 2017-08-11 12:00:22 -07:00
Carl Lerche
23b2ef49cc Stub out priority 2017-08-10 23:17:21 -07:00
Carl Lerche
a61562f6b8 Add GoAway support 2017-08-10 14:19:46 -07:00
Carl Lerche
a1b03b7724 Trying to get something working 2017-08-10 13:15:40 -07:00
Carl Lerche
dfec401fdf WIP: send flow control 2017-08-09 14:16:32 -07:00
Carl Lerche
87c4d36b0c Delete comments 2017-08-09 11:47:15 -07:00
Carl Lerche
0bf0e79132 Tweaks 2017-08-09 11:43:55 -07:00