New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: x/net/quic: add QUIC implementation #58547
Comments
I generally like the use of Confusingly, it probably does not make sense for Edit: Random thought: Might it make sense to introduce new interfaces for the |
Author of quic-go here If there's interest from the Go team's side, I'd be happy to talk about what would be needed to get (parts of?) quic-go merged into the standard library. |
It probably does make sense for I don't think it's useful for anything in a QUIC implementation to implement If someone does need to use a |
Related: #32204 (net/http: support HTTP/3) |
Is it better to add laddr, same as:
For convenience, there is no need to listen first and then dial :), like here |
Thank you for sharing this!
Does an endpoint that acts as a client need to set a certificate? If so, I'd guess that it's even OK to call
These methods don't allow using normal io packages in a Context-aware way; anything that takes an What are the tradeoffs of this versus a method like This revision of the API doesn't give visibility into flow control. How much is required to build a reliable QPACK implementation? From https://www.rfc-editor.org/rfc/rfc9204.html#section-2.1.3
Only because you mentioned future possibility of Early Data: Would Dialing with Early Data need a separate |
@neild I just want to make sure @marten-seemann's comment above was seen. Given the years of effort that have already been spent implementing and optimizing QUIC in Go, it would probably make sense to take advantage of that rather than start over from scratch, even if the exported APIs are a little different. Please consider using quic-go as the basis for this effort. |
@mholt quic-go never tried to integrate with stdlib net packages in a natural way. while I'm sure some of the internal structures might be reusable. the overall library itself wasn't terribly appealing to me personally due to the incompatibilities with the wider ecosystem. edit: as a result I strongly recommend against using quic-go as a base because of that decision. quic-go focused on getting quic http support available. golang's stdlib implementation should be focused on compatibility with the wide ecosystem at the transport level. the fundmental driving forces for the API design are very different. |
@paralin I think the adapter code all of them had to implement to handle quic-go speaks for itself. golang stdlib needs to figure out how to interopt at the transport level. similar to the packet conn vs stream conns it already has. if I have a stream oriented protocol I shouldn't care if I receive a quic, tcp, or unix transport. this is the problem we need to resolve which quic-go explicitly decided to ignore |
This is an active proposal and no decisions have been made as of yet. Please hold off on speculation about the implementation, and take conversations about quic-go elsewhere. |
@mdlayher agreed, but my points about the interopt in stdlib for quic stand. they're important even if we ignore quic-go. |
It is good for proposals to focus on API, but implementation is explicitly on topic at least for large proposals, given that it's one of the sections listed in the design doc template. As for quic-go, I completely agree that it would be good to take advantage of the expertise that @marten-seemann has built up over his years of development of quic-go. We would certainly welcome his help. At the same time, reusing quic-go directly is probably not the right path forward, for a few reasons:
For all these reasons, the path forward is almost certainly not to adopt quic-go directly. @marten-seemann, as I said before, we certainly appreciate your work implementing QUIC to date as well as the expertise you have amassed, and if you would be interested to share that with us in the development and review of a fresh implementation, you'd certainly be welcome. On the other hand, if you would rather focus on quic-go and not a different implementation, we'd understand that too. |
main things I'm interested in w/ a quic implementation are exposing ALPN and seamless interopt w/ other standard transports. aka shouldn't have to make extra calls to server http over a quic transport. just setup the quic listener and pass it to http.Serve. when the quic implementation gets to a workable state I'm 100% down to start using it in some of my applications and provide feedback on the API. |
@rsc, thank you for your detailed post. It seems like a decision has already been made, but nevertheless, here are my 2c. Happy to share some of my insights from almost 8 years of developing / maintaining a QUIC stack and from having been a member of the IETF QUIC working group since the very beginning. Building a performant QUIC stack is an absolutely massive endeavor. Getting the handshake to work is nothing more than a tiny first step. When we started the project, it only took us one or two weeks to download a small file from a quic-go server using Chrome via what was back then called H2/QUIC, and most of that time was spent on implementing the bespoke QUIC Crypto. This results in a spec-compliant QUIC stack, but in no way an optimized / performant one. You'd probably want to implement
Maybe not absolutely necessary, but highly desirable:
Aside from all of these features above, we've spent significant engineering efforts on performance optimizations (e.g. reducing the number of allocs) and DoS defense (you're keeping track of a lot of things, e.g. sent and received frames, sent and received packets, etc., and all of these data structures are potentially attackable). As I see it, there's little point in just providing a spec-compliant QUIC implementation, if it can't (at the very least) compete with TCP's performance. And performance work on quic-go is far from done at this point. Let me briefly comment on the points you made.
Not sure in what sense quic-go is too low-level. However, quic-go is still on a v0.x version, and we're happy to consider well-motivated API changes. That statement stands independent of the discussion on this issue, and we're happy about proposals how to make the quic-go API work better (please open an issue in quic-go, happy to discuss there!).
We've removed support for QUIC crypto a long time ago. The only compatibility code that we're still maintaining is for draft-29, which we're planning to remove some time in summer this year. The additional code for draft-29 is pretty limited to begin with (mostly just using different labels in the various HKDF expansions), and with one tiny exception doesn't leak beyond the handshake package. One thing I'm really happy about is finally cleaning up the API between quic-go and crypto/tls. I can't wait to start using the new API (I already have a branch). The API that my crypto/tls fork has accumulated over the years is indeed suboptimal (to say the least). Cleaning it up was always complicated by the fact that I had to maintain two separate forks (for the most recent 2 Go versions) at the same time. Other than that, I don't think there's any code around that only exists for historical reasons. While minimizing the LOC was never a design target (code clarity and testability was), I don't think there's a lot you can remove without removing features or sacrificing performance.
Indeed. In hindsight, that was a bad decision we made when we started the project. Migrating would probably take somewhere around 2 weeks of work to rewrite the tests. Pretty sure that this would still be orders of magnitude less work than rewriting an implementation from scratch.
All code has been reviewed by a Googler, @lucas-clemente (not on the Go team though). I don't mean to be nit-picky here, but it's just 24,000 LOC if you exclude tests (and 63,000 if you don't) (counted using I'd also like to point out that quic-go is widely used in production, for example by Caddy (using the HTTP/3 implementation it comes with) and accounts for ~80-90% of all connections in the IPFS network (using just the quic package, without HTTP/3). See here for a (very much incomplete) list of other projects that use it. It's also tested against a long list of other QUIC implementations using the QUIC Interop Runner which we built a few years ago to facilitate automated interop testing in the QUIC working group.
Happy to help, in one way or the other. You know where to find me :) |
No; fixed the documentation for
There are three types of API for cancellable read/write operations in common use that I know of:
I believe we need to support the first one for compatibility with I don't have a strong opinion about which of the latter two options is best ( Another possibility if #57928 is accepted (not strictly necessary, but necessary to implement this efficiently) might be:
This is an excellent question. I left flow control out of the initial proposal because I'm not completely satisfied with any of the ideas I've had so far. My current inclination is to have a per-stream configuration option that makes writes to the stream effectively atomic--a write will block until flow control is available to send the entire write, sending either the entire chunk of data or none of it.
I'd be interested to hear other ideas.
To close a connection with an error and wait for the peer to acknowledge:
I think you might be right that combining Abort and Close into a single
I think we can do Early Data almost entirely within the proposed API.
But I haven't tried to implement this, and might be missing something. |
Change https://go.dev/cl/475435 mentions this issue: |
Change https://go.dev/cl/468402 mentions this issue: |
Change https://go.dev/cl/475437 mentions this issue: |
Change https://go.dev/cl/475436 mentions this issue: |
Change https://go.dev/cl/475438 mentions this issue: |
To be clear: This will not work. QUIC is not TCP. A In addition, while it would be possible to run HTTP/1 over QUIC streams, nobody (so far as I know) does this. HTTP/3 uses QUIC as an underlying transport, but HTTP/3 is not just HTTP/1 with TCP swapped out for QUIC. |
Yes, The adaptor is simple to write in either direction (2 to 3 or 3 to 2). The It seems that API 1 can also be built into API 3, where the value that For what it's worth, I'd also expect multiple calls to I agree though that it's not clear which of these APIs is best. Most of all I'd like one that aligns with performance: where it's easy to implement and use in an efficient way and hard to end up with a bunch of great code that can't be made to go fast.
That sounds pretty simple to use, nice! If it allows writes that are larger than a single packet, and some pacing is active, and the user cancels the write via
IIUC there are three protocol-level limits that determine whether a particular STREAM frame is allowed on the wire: stream-level flow control, connection-level flow control, and connection-level congestion control (which seems closely related to any pacing in place). It looks like QPACK specifies a need for interacting with the first two. I expect it's unusual to need to interact with the third, but I have an application that takes advantage of visibility into that: it prioritizes which data to send, and sometimes whether to send any data at all, based on how soon it expects the QUIC stack will be able to send it to the peer. (Maybe some of that is better left to an integration with the packet scheduler.) I wonder if there's room for an API along the lines of https://pkg.go.dev/golang.org/x/time/rate#Limiter.ReserveN that gives an app a higher level of visibility into and control of those windows, through an API that returns a struct with methods that allow inspecting and manipulating (and canceling) the reservation. It's definitely an "other idea"; I don't know whether it's better than your
|
While this might be off topic as the unreliable datagram extension is not part of quic rfc, I would like to express interest in the extension, for implementing http 3 datagrams and udp-connect methods. |
The type of a QUIC packet can be identified by inspecting its first byte, and the destination connection ID can be determined without decrypting and parsing the entire packet. For golang/go#58547 Change-Id: Ie298c0f6c0017343168a0974543e37ab7a569b0f Reviewed-on: https://go-review.googlesource.com/c/net/+/475437 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Encrypt and decrypt QUIC packets according to RFC 9001. For golang/go#58547 Change-Id: Ib7f824cf08f8520400bd38d3b3ab89e8a968114e Reviewed-on: https://go-review.googlesource.com/c/net/+/475438 Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
A rangeset is an ordered list of non-overlapping int64 ranges. This type will be used for tracking which packet numbers need to be acknowledged and which parts of a stream have been sent/received. For golang/go#58547 Change-Id: Ia4ab3a47e82d0e7aea738a0f857b2129d4ea1f63 Reviewed-on: https://go-review.googlesource.com/c/net/+/478295 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Functions to encode and decode QUIC variable-length integers (RFC 9000, Section 16), as well as a few other common operations. For golang/go#58547 Change-Id: I2a738e8798b8013a7b13d7c1e1385bf846c6c2cd Reviewed-on: https://go-review.googlesource.com/c/net/+/478258 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Constants for the transport error codes in RFC 9000 Section 20, types representing transport errors sent to or received from the peer, and a type representing application protocol errors. For golang/go#58547 Change-Id: Ib4325e1272f6e0984f233ef494827a1799d7dc26 Reviewed-on: https://go-review.googlesource.com/c/net/+/495235 Reviewed-by: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
When we send a packet, we need to remember its contents until it has been acked or detected as lost. For golang/go#58547 Change-Id: I8c18f7ca1730a3ce460cd562d060dd6c7cfa9ffb Reviewed-on: https://go-review.googlesource.com/c/net/+/495236 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Frame encoding is handled by the packetWriter type. The packetWriter also takes responsibility for recording the contents of constructed packets in a sentPacket structure. Frame decoding is handled by consume*Frame functions, which generally return the frame contents. ACK frames, which have complex contents, are provided to the caller via callback function. In addition to the above functions, used in the serving path, this CL includes per-frame types that implement a common debugFrame interface. These types are used for tests and debug logging, but not in the serving path where we want to avoid allocations from storing values in an interface. For golang/go#58547 Change-Id: I03ce11210aa9aa6ac749a5273b2ba9dd9c6989cf Reviewed-on: https://go-review.googlesource.com/c/net/+/495355 Reviewed-by: Jonathan Amsterdam <jba@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Any given datum communicated to the peer follows a state machine: - We do not need to send the this datum. - We need to send it, but have not done so. - We have sent it, but the peer has not acknowledged it. - We have sent it and the peer has acknowledged it. Data transitions between states in a consistent fashion; for example, loss of the most recent packet containing a HANDSHAKE_DONE frame means we should resend the frame in a new packet. Add a sentVal type which tracks this state machine. For golang/go#58547 Change-Id: I9de0ef5e482534b8733ef66363bac8f6c0fd3173 Reviewed-on: https://go-review.googlesource.com/c/net/+/498295 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Change https://go.dev/cl/499284 mentions this issue: |
Change https://go.dev/cl/499285 mentions this issue: |
Change https://go.dev/cl/499283 mentions this issue: |
Change https://go.dev/cl/499286 mentions this issue: |
Change https://go.dev/cl/499287 mentions this issue: |
I’d like to reach out once again, with a new proposal (see below). There have been several positive developments in quic-go in recent months:
Heres’s my proposal: Have the standard library add HTTP/3 support, without exposing any QUIC API. As @ianswett pointed out, probably 90% of the use cases of QUIC in the standard library actually only need HTTP/3. I believe this could easily be achieved by vendoring quic-go to an The 10% of users that need raw QUIC (without HTTP/3) could then import quic-go directly. Importing a 3rd party package that implements additional functionality is a very common pattern in the Go ecosystem. While quic-go does offer an http3 package, there’d be a big usability win if the standard library At frequent intervals (before a new Go release?) the Go team could decide if they want to include an updated quic-go version. This approach would have a number of advantages:
|
I'm not a fan of how HTTP/2 was bundled into the std lib. using Also the way |
This package will add on crypto/tls features added in Go 1.21, so use a build constraint to restrict ourselves to that version. Unlocks the ability to use other features from Go versions more recent than what's in x/net's go.mod file. For golang/go#58547 Change-Id: I14011c7506b047e389d9b3e995c0bafcd5e74d44 Reviewed-on: https://go-review.googlesource.com/c/net/+/499283 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
@kgersen you bring up two issues, bundling and how HTTP2 ALPN negociation isn't very pretty, however thoses issues also applies to using a QUIC / HTTP3 implementation that lives in |
Thanks for the update Marten that's excellent progress and impressive throughput performance. |
Per @marten-seemann’s proposal:
Raising my hand to help port the |
Presumably if this is go internal vendoring or bundle route I don't see why quic-go's test suite would need to be runned inside the std, the http2 test suite is exclusively ran in |
Make the rangeset type parameterized, so it can be used for either packet number or byte ranges without type conversions. For golang/go#58547 Change-Id: I764913a33ba58222dcfd36f94de01c2249d73551 Reviewed-on: https://go-review.googlesource.com/c/net/+/499284 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Change https://go.dev/cl/499640 mentions this issue: |
Change https://go.dev/cl/499641 mentions this issue: |
also need to remove third package? |
I assume you're referring to gojay? That's a 3rd party JSON encoder only used in the qlog package. It speeds up qlog encoding (by a lot), compared to the standard library, which is needed if you want to use qlog to debug QUIC connections at high throughputs. For my proposal, quic-go could be vendored / bundled without qlog (quic-go doesn't depend on the qlog package, qlog is just an implementation of quic-go's tracer interface). Excluding tests and qlog, this means that quic-go doesn't have any 3rd-party dependencies. |
@marten-seemann wrote:
This may be a reasonable transition plan to provide HTTP/3 sooner, but I think it's important to have a plan to land QUIC in the standard library as a peer transport option alongside TCP and UDP. If the code is trusted for HTTP/3, it should be available for other uses too. Using QUIC as a transport has a lot of advantages. In future, the idea of not shipping QUIC could be similar to not including TCP/UDP. With a solid implementation available many more applications are likely to be developed. |
@mpx You're totally right, and as a member of the IETF QUIC working group from the very first day, I couldn't agree more. Can't wait for more and more internet traffic to shift to QUIC :) My proposal is to decouple exposing of a HTTP/3 API (probably super easy, likely just a few bools in the net/http package) from exposing a QUIC API (which will be a huge API surface). Neither requires writing a complete RFC 9000-compliant stack from scratch (which is a big task in itself), and the work required to make it an actually usable and performant stack (as I described in #58547 (comment)), which is an even bigger task, if you want to do it right. |
Store in-flight packets in a ring buffer. For golang/go#58547 Change-Id: I825c4e600bb496c2f8f6c195085aaae3e847445e Reviewed-on: https://go-review.googlesource.com/c/net/+/499285 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com> Run-TryBot: Damien Neil <dneil@google.com>
I'm not the person who makes the decision here, but it's extremely unlikely that we would vendor a large, complex, third-party dependency into the standard library. The standard library consists of code maintained by the Go team. We have common processes for code review, issue tracking, release cycles, and so forth. Adding a dependency which doesn't use those processes would be a very large change with a great deal of impact. As one example, coordinating security fixes for a third-party dependency would be tremendously complicated, and would need an entirely new and different process from what we use today. There are some examples of code in the standard library that originate with third-party sources (e.g., Users can already import Regarding the situation with HTTP/2 support in As for providing a QUIC API vs. HTTP/3: It's absolutely the case that almost all uses for QUIC will be via HTTP/3. Perhaps the endpoint of this issue will be that we should have a QUIC implementation, but initially only expose it via HTTP/3 to avoid prematurely committing to a publicly-facing API. |
I propose adding an implementation of the QUIC transport protocol (RFC 9000) in
golang.org/x/net/quic
. QUIC is the protocol underlying HTTP/3, and QUIC support is a necessary prerequisite for HTTP/3 support.The proposed API is in https://go.dev/cl/468575. This API does not include support for Early Data, but does not preclude adding that support at a later time.
RFC 9000 does not define a QUIC API, but it does define a set of operations that can be performed on a QUIC connection or stream.
A QUIC connection is shared state between a client and server.
open a [client] connection:
listen for incoming connections:
A QUIC stream is an ordered, reliable byte stream. A connection may have many streams. (A QUIC stream is loosely analogous to a TCP connection.)
create streams:
accept streams created by the peer:
read from, write to, and close streams:
stream operations also have Context-aware variants:
data written to streams is buffered, and may be explicitly flushed:
See https://go.dev/cl/468575 for the detailed API.
The text was updated successfully, but these errors were encountered: