290 Commits

Author SHA1 Message Date
cuishuang
9be1ff2808 all: fix some comments
Change-Id: I4a06e68307ac3deb5b2e1bab9235ebe01dcd4ea6
Reviewed-on: https://go-review.googlesource.com/c/net/+/713380
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
2025-10-23 07:34:54 -07:00
Rhys Hiltner
6e243da531 quic: update Initial keys when handling Retry
A Retry packet specifies a new connection ID for the client to use as a
destination address, in what the server will consider to be the client's
"first" Initial packet. Re-derive the Initial space's packet protection
keys, since that address is an input to their derivation function.

"Changing the Destination Connection ID field also results in a change
to the keys used to protect the Initial packet."
https://www.rfc-editor.org/rfc/rfc9000#section-17.2.5.2-4

For golang/go#58547

Change-Id: Id8acf5788a05d367f952dce33ef4b06f7e8b66e2
Reviewed-on: https://go-review.googlesource.com/c/net/+/712341
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-17 13:07:34 -07:00
Rhys Hiltner
98daa2e33a quic: send ECN feedback to peers
Track the total number of ECT(0), ECT(1), and ECN-CE state of packets we
process in each packet number space. Send it back to the peer in each
ACK frame (unless it's all zeros).

"Even if an endpoint does not set an ECT field in packets it sends, the
endpoint MUST provide feedback about ECN markings it receives, if these
are accessible."
https://www.rfc-editor.org/rfc/rfc9000#section-13.4.1-2

For golang/go#58547

Change-Id: I3ce5be6c536198eaa711f527402503b0567fc7a5
Reviewed-on: https://go-review.googlesource.com/c/net/+/712280
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17 13:04:03 -07:00
Rhys Hiltner
3ba82d21c9 internal/quic/cmd/interop: test ChaCha20 on server
The QUIC interop test suite confirms support for ChaCha20. Go's TLS
implementation doesn't allow configuring ciphersuites for TLS 1.3, so we
cannot force the client hello to offer only ChaCha20 as the test
requires.

When acting as a server, we still cannot control which ciphersuites we
offer, but we can make the binary choice of whether we respond to the
client hello (which includes its offer of ciphersuites).

Use that to implement the server side of the ChaCha20 interop test. This
tells a more complete story of our level of ChaCha20 support: it works
when negotiated.

Fixes golang/go#75912

Change-Id: I1d8d08e4f4b8eb89bf11e9e4ae1aaa5c0709a530
Reviewed-on: https://go-review.googlesource.com/c/net/+/712120
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-15 13:27:37 -07:00
Nicholas S. Husin
b2ab3712bc internal/httpsfv: implement parsing support for date and display string
This change adds support for parsing date and display string, meaning
this package can now fully parse any HTTP SFV that is compliant with
RFC 9651.

This package is still intended only for internal use at this point.

For golang/go#75500

Change-Id: I07626b45f01e0c5cb4e92aa3fea04cc7e2d0c814
Reviewed-on: https://go-review.googlesource.com/c/net/+/708437
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-02 12:44:41 -07:00
Nicholas S. Husin
edb764c229 internal/httpsfv: add parsing functionality for types defined in RFC 8941
This change introduces parsing functions for all item types defined in
RFC 8941, namely: integers, decimals, strings, tokens, byte sequences,
and booleans.

At this point, internal/httpsfv should be usable for parsing any RFC
8941-compliant HTTP Structured Field Values.

In a future CL, we will add support for parsing display strings and
dates, so that this package fully supports RFC 9651.

For golang/go#75500

Change-Id: Ib8ad2caa5f6ea4285d00506faa4b8127c2cc9419
Reviewed-on: https://go-review.googlesource.com/c/net/+/708435
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-01 18:54:45 -07:00
Nicholas S. Husin
fbba2c22cb internal/httpsfv: add support for consuming Display String and Date type
This CL adds consumeDisplayString() and consumeDate() function, meaning
that we can now consume all types that are defined within RFC 9651. In
future CL, we will add the corresponding parsing function for all the
types, so callers of this package will not have to implement their own
parsing / formatting.

For golang/go#75500

Change-Id: I90aa132d3ab1385b310d821997da13a095cd71bc
Reviewed-on: https://go-review.googlesource.com/c/net/+/708015
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-10-01 14:45:17 -07:00
Nicholas S. Husin
f2e909b982 internal/httpsfv: implement parsing support for Dictionary and List type.
This change implements the Parse functions for the Dictionary and List
type. At this point, we should be able to use internal/httpsfv package
to extract information from any HTTP SFV that follows RFC 8941.

In future changes, we will add additional types introduced in RFC 9651
to achieve feature parity with it. Additionally, we will add Parse
functions for all the HTTP SFV types, such that users of the package do
not need to do their own type assertions and conversions.

Note that the Dictionary and List type do not have a consume function.
This is because both types never appear as a child of other types,
meaning it is guaranteed to always consume its entire string input.

For go/golang#75500

Change-Id: I376dca274d920a4bea276ebb4d49a9cd768c79fe
Reviewed-on: https://go-review.googlesource.com/c/net/+/707100
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-09-29 09:35:41 -07:00
Nicholas S. Husin
7d8cfcee6c internal/httpsfv: add support for Bare Inner List and Item type.
This change implements the consume and Parse functions for both the Item
and Bare Inner List type. This is part of a chain of changes that is needed
in order for us to fully support HTTP Structured Field Values parsing as
defined in RFC 9651.

In future changes, we will utilize the support for Bare Inner List and Item
that is added here to support more complex types, namely Dictionary and
List.

Note that Bare Inner List is something we define on our own. We define a
Bare Inner List as an Inner List without the top-most parameter meant
for the Inner List. For example, the Inner List `(a;b c;d);e` would
translate to the Bare Inner List `(a;b c;d)`. We have done this because
the parameter of an Inner List will be exposed to the user via
ParseDictionary() or ParseList() too. By implementing Bare Inner List,
we can avoid having two ways of accessing the Inner List parameter, and
incurring the cost of a more complex implementation for Inner List and
other types that utilize Inner List (e.g. if we have consumeInnerList,
ParseDictionary will have to use consumeInnerList and backtrack the
consumption to separate out the InnerList parameter).

For go/golang#75500

Change-Id: I9b418d10b5755195d1cc3ff5f7ea211423bc4b48
Reviewed-on: https://go-review.googlesource.com/c/net/+/707099
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-29 09:35:27 -07:00
Nicholas S. Husin
c492e3c189 internal/httpsfv: add functionality to walk Parameters in HTTP SFV.
This change implements the minimum set of functionality within RFC 8491
that is needed in order for us to be able to extract information out of
Parameters type.

Rather than parsing the given Structured Field Values as usual, we
instead allow users to give us functions that will be invoked as we walk
through the SFV. This allows users to still extract information out of
SFV, without incurring significant memory allocation, especially when
the input is large.

If the current API & approach is good, we will proceed further by
implementing walk functionality for the rest of the types within RFC
8491: Dictionary, List, Item, and Inner List. After that, we will also
add support for Date and Display String to fully support RFC 9651.

For golang/go#75500

Change-Id: I838a7267a54fcd64b019be0ac10fe86b1e3e2c8b
Reviewed-on: https://go-review.googlesource.com/c/net/+/706755
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-25 13:52:30 -07:00
cuishuang
875d966983 all: fix some comments
Including mismatched function names/struct names, repeated words, typos, etc.

Change-Id: Ia576274bce6e6fbfe4d2fca6dcd6d31bf00936fb
Reviewed-on: https://go-review.googlesource.com/c/net/+/683875
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
2025-09-15 17:28:39 -07:00
Damien Neil
ef33bc08f8 internal/http3: use bubbled context in synctest tests
Avoid using T.Context within a synctest bubble. If the Context's
Done channel is created outside the bubble, waiting on it within
the bubble is durably blocking. If it's created within the bubble,
the testing package encounters a panic when closing it after
CL 671960.

Instead, create our own Context within the bubble and cancel it
before the bubble is destroyed.

This will be entirely obviated by synctest.Test, which creates
a testing.T that returns a properly bubbled context.

Change-Id: Iff93c296ccbc1ece8172cb0a60e626ea1bd895ad
Reviewed-on: https://go-review.googlesource.com/c/net/+/675615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-05-22 15:58:59 -07:00
cuishuang
ea0c1d94f5 internal/timeseries: use built-in max/min to simplify the code
Change-Id: I3d408025af072559cac1f2b403a90518995d0a5a
Reviewed-on: https://go-review.googlesource.com/c/net/+/664855
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-15 18:01:41 -07:00
Chressie Himpel
ebed060e8f internal/http3: fix build of tests with GOEXPERIMENT=nosynctest
The tests in qpack_decode_test.go require synctest helpers from
http3_test.go, but that file has a goexperiment.synctest build
constraint.

To make builds work when GOEXPERIMENT=nosynctest is specified the
synctest helpers are refactored into http3_synctest_test.go (with the
same build constraint) and the non-synctest related functionality is
kept in http3_test.go.

Change-Id: Iae339dc1895f27e7ac5ba985e204f4868c229a4d
Reviewed-on: https://go-review.googlesource.com/c/net/+/660535
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-03-25 08:01:24 -07:00
Damien Neil
459513d1f8 internal/http3: move more common stream processing to genericConn
Move the server stream-accept loop into genericConn.
(Overlooked in a previous CL.)

Be more consistent about having genericConn handle errors.

For golang/go#70914

Change-Id: I872673482f16539e95a1a1381ada7d3e22affb82
Reviewed-on: https://go-review.googlesource.com/c/net/+/653395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-28 11:43:44 -08:00
Damien Neil
5f45c776a9 internal/http3: make read-data tests usable for server handlers
A reading a transport response body behaves much the same as a
server handler reading a request body. Move the transport test into
body_test.go and rearrange it a bit so we can reuse it as a server
test.

For golang/go#70914

Change-Id: I24e10dd078ffab867c9b678e1d0b99172763b069
Reviewed-on: https://go-review.googlesource.com/c/net/+/652457
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-27 10:24:19 -08:00
Damien Neil
43c2540165 http2, internal/httpcommon: reject userinfo in :authority
RFC 9113, section 8.3.1: The :authority (host) in an HTTP
request must not include a userinfo (e.g., user@host).

Change-Id: I459a3da40b825c9662467778f582050c7358f8bb
Reviewed-on: https://go-review.googlesource.com/c/net/+/652456
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-02-26 14:12:30 -08:00
Damien Neil
1d78a08500 http2, internal/httpcommon: factor out server header logic for h2/h3
Move common elements of constructing a http.Request for
a server handler into internal/httpcommon.

For golang/go#70914

Change-Id: I5dcd902e189a0bb8daf47c0a815045d274346923
Reviewed-on: https://go-review.googlesource.com/c/net/+/652455
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-25 11:03:29 -08:00
Damien Neil
163d83654d internal/http3: add Server
Add the general structure of an HTTP/3 server.
The server currently accepts QUIC connections and establishes a
control stream on them, but does not handle requests.

For golang/go#70914

Change-Id: I28193ddacef028233248601979b0b45ad844205a
Reviewed-on: https://go-review.googlesource.com/c/net/+/646617
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-18 14:25:14 -08:00
Damien Neil
884432780b internal/httpcommon: don't depend on net/http
When the http2 package is bundled into net/http, it imports httpcommon,
so httpcommon must not depend on net/http.

Change-Id: I2aa34e913a0df757fa83deb56f650394a924933e
Reviewed-on: https://go-review.googlesource.com/c/net/+/649415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-13 14:27:35 -08:00
Damien Neil
b914489dfb internal/http3: refactor in prep for sharing transport/server code
Pull out various elements of the HTTP/3 client that can be
reused in the server. Move tests which can apply to client or server
connections into conn_test.go.

For golang/go#70914

Change-Id: I72b5eab55ba27df980ab2079120613f175b05927
Reviewed-on: https://go-review.googlesource.com/c/net/+/646616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-02-04 17:21:19 -08:00
Damien Neil
938a9fb94e internal/http3: add request/response body transfer
For golang/go#70914

Change-Id: I372458214fe73f8156e0ec291168b043c10221e6
Reviewed-on: https://go-review.googlesource.com/c/net/+/644915
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-03 17:39:20 -08:00
Damien Neil
145b2d7b6d internal/http3: add RoundTrip
Send request headers, receive response headers.

For golang/go#70914

Change-Id: I78d4dcc69c253ed7ad1543dfc3c5d8f1c321ced9
Reviewed-on: https://go-review.googlesource.com/c/net/+/644118
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-27 16:46:54 -08:00
Damien Neil
5bda71aec0 internal/http3: define connection and stream error types
HTTP/3 distinguishes between connection errors which result in an
entire connection closing, and stream errors which only terminate
a single request stream.

Define internal types to represent these two types of error.

For golang/go#70914

Change-Id: I907f395adc82a683b5c2eda65f936b1ab4904ffb
Reviewed-on: https://go-review.googlesource.com/c/net/+/644117
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-24 14:20:07 -08:00
Damien Neil
3c1185a39b internal/http3: return error on mid-frame EOF
When a stream ends in the middle of a frame,
return a non-EOF error from Read or ReadByte.

When a stream ends at the end of a frame,
don't return io.EOF from the Read call that reads
the last byte of the frame.
(This complicates stream.Read slightly,
but means that code that reads frames consistently
never sees an io.EOF, but gets an error if it tries
to read past the end of a frame.)

For golang/go#70914

Change-Id: If1b852716fe5e3aa3503f6970e2e1fba2ebb5f48
Reviewed-on: https://go-review.googlesource.com/c/net/+/644116
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-01-24 14:05:38 -08:00
Damien Neil
a6c2c7f364 http2, internal/httpcommon: factor out common request header logic for h2/h3
HTTP/2 and HTTP/3 use the same set of pseudo-headers to represent
requests and responses. Move the http2 package's logic for validating
an http.Request and converting it to a set of pseudo-headers into
internal/httpcommon so it can be shared with HTTP/3.

For golang/go#70914

Change-Id: I80561752e821ccd0da2a811034c44f3f71064434
Reviewed-on: https://go-review.googlesource.com/c/net/+/643780
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Commit-Queue: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-24 11:09:29 -08:00
Damien Neil
c72e89d6a9 internal/http3: QPACK encoding and decoding
Basic support for encoding/decoding QPACK headers.

QPACK supports three forms of header compression:
Huffman-encoding of literal strings, a static table of
well-known header values, and a dynamic table of
header values negotiated between encoder and decoder
at runtime.

Right now, we support Huffman compression and the
static table, but not the dynamic table.
This is a supported mode for a QPACK encoder or
decoder, so we can leave dynamic table support
for after the rest of HTTP/3 is working.

For golang/go#70914

Change-Id: Ib694199b99c752a220d43f3a309169b16020b474
Reviewed-on: https://go-review.googlesource.com/c/net/+/642599
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2025-01-22 16:02:30 -08:00
Damien Neil
93c1957e42 internal/http3: add Transport and ClientConn
Add the first rudiments of an HTTP/3 client.

The client currently opens a QUIC connection and creates a control
stream on it, and nothing else.

Add surrounding test infrastructure for examining the client's
behavior. Tests use the experimental testing/synctest package
and will only run when the Go version is at least Go 1.24 and
GOEXPERIMENT=synctest is set.

For golang/go#70914

Change-Id: I19803187a8e62c461f60d7a1d44c2a408377e342
Reviewed-on: https://go-review.googlesource.com/c/net/+/642516
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-22 10:00:23 -08:00
Tobias Klauser
45432b5e4f internal/socket, webdav: use testing.T.TempDir
It's available since Go 1.15 and go.mod currently specifies Go 1.18.

Change-Id: Ia5ba22f5802f4af9fb6d3b6e7ee5a02ce3582e9a
Reviewed-on: https://go-review.googlesource.com/c/net/+/643595
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-01-21 14:35:12 -08:00
Damien Neil
7ad0ebf002 internal/http3: qpack wire primitives
Encode and decode QPACK prefixed integers and string literals.

For golang/go#70914

Change-Id: Id12d1853738fc6d0e03bbbef36b67c24298451e1
Reviewed-on: https://go-review.googlesource.com/c/net/+/642115
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-13 15:50:20 -08:00
Damien Neil
f6b2e53bb7 internal/http3: basic stream read/write operations
Read and write HTTP/3 frames from QUIC streams.

The varint encoding/decoding overlaps a bit with that in
the quic package, but this package operates on streams while
the QUIC package operates on []bytes.

For golang/go#70914

Change-Id: I31115f5b572a59b899e2c880ecc86ba3caed982e
Reviewed-on: https://go-review.googlesource.com/c/net/+/641838
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-13 15:50:17 -08:00
Damien Neil
78717f922a internal/http3: error codes
Define constants for RFC 9114 and RFC 9204 error codes.

For golang/go#70914

Change-Id: Icddaf0ef1468adc6ac8e7b8739d45c8e4400f0e4
Reviewed-on: https://go-review.googlesource.com/c/net/+/641837
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-01-13 15:38:51 -08:00
Damien Neil
84b528b4a5 internal/http3: new package
Create a package for an HTTP/3 implementation.
Internal for now, intended to eventually move to x/net/http3.

For golang/go#70914

Change-Id: I3a643fe7958cf75b231ca97f25e9f338554f723c
Reviewed-on: https://go-review.googlesource.com/c/net/+/641836
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-13 15:38:49 -08:00
Damien Neil
97dd44e201 http2, internal/gate: move Gate type to an internal package
For reuse in internal/http3.

Change-Id: I186d7219194a07c100aa8bd049e007232de2d3d9
Reviewed-on: https://go-review.googlesource.com/c/net/+/641497
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-01-09 11:13:01 -08:00
Damien Neil
35e1007cf8 quic, internal/quic/quicwire: split wire encode/decode functions to new package
HTTP/3 also uses QUIC varints. Move the more general-purpose wire
encoding/decoding functions into a new internal/quic/quicwire package
so they can be shared.

For golang/go#70914

Change-Id: Id888baf131e90a12247e15a6f7bc7dc37c6dc572
Reviewed-on: https://go-review.googlesource.com/c/net/+/641496
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-09 11:12:58 -08:00
Damien Neil
2e6010204e quic, internal/testcert: move test cert to internal package
Move the testing-only localhost certificate to an internal package
so it can be accessed by other packages' tests.

Change-Id: I52e8cc1220ce49f99e40a5be78d4cdc2f6998a0e
Reviewed-on: https://go-review.googlesource.com/c/net/+/640795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-01-07 08:52:02 -08:00
cuishuang
5716b9813d internal/socket: execute gofmt
Change-Id: Ifc793d535c31da3ba183ee44e1808e0072d7f099
Reviewed-on: https://go-review.googlesource.com/c/net/+/619595
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-10-11 22:36:55 +00:00
Damien Neil
c1f5833288 all: replace deprecated io/ioutil calls
The io/ioutil package's features were moved to
the io and os packages in Go 1.16.

x/net depends on Go 1.18. Drop ioutil calls,
so gopls doesn't warn about them.

Change-Id: Ibdb576d94f250808ae285aa142e2fd41e7e9afc9
Reviewed-on: https://go-review.googlesource.com/c/net/+/586244
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-21 19:59:00 +00:00
Damien Neil
fa11427993 quic: move package out of internal
For golang/go#58547

Change-Id: I119d820824f82bfdd236c6826f960d0c934745ca
Reviewed-on: https://go-review.googlesource.com/c/net/+/566295
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-27 18:30:56 +00:00
Damien Neil
591be7f10b quic: fix UDP on big-endian Linux, tests on various architectures
The following cmsgs contain a native-endian 32-bit integer:

  - IP_TOS, passed to sendmsg
  - IPV6_TCLASS, always

IP_TOS received from recvmsg contains a single byte, because why not.

We were inadvertently assuming little-endian integers in all cases.
Add endianness conversion as appropriate.

Disable tests that rely on IPv4-in-IPv6 mapped sockets on dragonfly
and openbsd, which don't support this feature. (A "udp" socket cannot
receive IPv6 packets on these platforms.)

Disable IPv6 tests on wasm, where the simulated networking appears
to generally not support IPv6.

Fixes golang/go#65906
Fixes golang/go#65907

Change-Id: Ie50af12e182a1a5d685ce4fbdf008748f6aee339
Reviewed-on: https://go-review.googlesource.com/c/net/+/566296
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2024-02-26 18:42:52 +00:00
Damien Neil
34cc4464c5 quic: temporarily disable networking tests failing on various platforms
For golang/go#65906
For golang/go#65907

Change-Id: I5fe83a27f47b6f2337d280465bf134dbd883809d
Reviewed-on: https://go-review.googlesource.com/c/net/+/566098
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2024-02-23 17:00:02 +00:00
Damien Neil
4bdc6df28e quic: expand package docs, and document Stream
For golang/go#58547

Change-Id: Ie5dd0ed383ea7a5b3a45103cb730ff62792f62e1
Reviewed-on: https://go-review.googlesource.com/c/net/+/565797
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-23 02:05:19 +00:00
Damien Neil
22cbde9a56 quic: set ServerName in client connection TLSConfig
Client connections must set tls.Config.ServerName to authenticate
the identity of the server. (RFC 9001, Section 4.4.)

Previously, we specified a single tls.Config per Endpoint.
Change the Config passed to Listen to only apply to
client connections accepted by the endpoint.
Add a Config parameter to Listener.Dial to allow specifying a
separate config per outbound connection, allowing the user
to set the ServerName field.

When the user does not set ServerName, set it ourselves.

For golang/go#58547

Change-Id: Ie2500ae7c7a85400e6cc1c10cefa2bd4c746e313
Reviewed-on: https://go-review.googlesource.com/c/net/+/565796
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-23 02:04:56 +00:00
Damien Neil
57e4cc7d88 quic: handle PATH_CHALLENGE and PATH_RESPONSE frames
We do not support path migration yet, and will ignore packets
sent from anything other than the peer's original address.
Handle PATH_CHALLENGE frames by sending a PATH_RESPONSE.
Handle PATH_RESPONSE frames by closing the connection
(since we never send a challenge to respond to).

For golang/go#58547

Change-Id: I828b9dcb23e17f5edf3d605b8f04efdafb392807
Reviewed-on: https://go-review.googlesource.com/c/net/+/565795
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-23 02:04:46 +00:00
Damien Neil
a6a24dd292 quic: source address and ECN support in the network layer
Make the abstraction over UDP connections higher level,
and add support for setting the source address and ECN
bits in sent packets, and receving the destination
address and ECN bits in received packets.

There is no good way that I can find to identify the
source IP address of packets we send. Look up the
destination IP address of the first packet received on
each connection, and use this as the source address
for all future packets we send. This avoids unexpected
path migration, where the address we send from changes
without our knowing it.

Reject received packets sent from an unexpected peer
address.

In the future, when we support path migration, we will want
to relax these restrictions.

ECN bits may be used to detect network congestion.
We don't make use of them at this time, but this CL adds
the necessary UDP layer support to do so in the future.

This CL also lays the groundwork for using more efficient
platform APIs to send/receive packets in the future.
(sendmmsg/recvmmsg/GSO/GRO)

These features require platform-specific APIs.
Add support for Darwin and Linux to start with,
with a graceful fallback on other OSs.

For golang/go#58547

Change-Id: I1c97cc0d3e52fff18e724feaaac4a50d3df671bc
Reviewed-on: https://go-review.googlesource.com/c/net/+/565255
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-21 20:54:12 +00:00
Damien Neil
2a8baeab18 quic: don't record fin bit as sent when it wasn't
When appendStreamFrame is provided with the last chunk of data
for a stream, doesn't have enough space in the packet to include
all the data, don't incorrectly record the packet as including
a FIN bit. We were correctly sending a STREAM frame with no FIN
bit--it's just the sent packet accounting that was off.

No test, because I can't figure out a scenario where this
actually has an observable effect, since we're always going
to send the FIN when the remaining stream data is sent.

Change-Id: I0ee81273165fcf10a52da76b33d2bf1b9c4f3523
Reviewed-on: https://go-review.googlesource.com/c/net/+/564796
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-21 16:16:25 +00:00
Damien Neil
5e097125fd quic: fast path for stream writes
Similar to the fast-path for reads, writes are buffered in an
unsynchronized []byte allowing for lock-free small writes.

For golang/go#58547

Change-Id: I305cb5f91eff662a473f44a4bc051acc7c213e4c
Reviewed-on: https://go-review.googlesource.com/c/net/+/564496
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-21 00:51:05 +00:00
Damien Neil
08d27e39b9 quic: fast path for stream reads
Keep a reference to the next chunk of bytes available for reading
in an unsynchronized buffer. Read and ReadByte calls read from this
buffer when possible, avoiding the need to lock the stream.

This change makes it unnecessary to wrap a stream in a *bytes.Buffer
when making small reads, at the expense of making reads
concurrency-unsafe. Since the quic package is a low-level one and
this lets us avoid an extra buffer in the HTTP/3 implementation,
the tradeoff seems worthwhile.

For golang/go#58547

Change-Id: Ib3ca446311974571c2367295b302f36a6349b00d
Reviewed-on: https://go-review.googlesource.com/c/net/+/564495
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-21 00:50:54 +00:00
Tobias Klauser
cc568eace4 internal/quic: use slices.Equal in TestAcksSent
The module go.mod uses go 1.18 and acks_test.go has a go:build go1.21
tag.

Change-Id: Ic0785bcb4795bedecc6a752f5e67a967851237e6
Reviewed-on: https://go-review.googlesource.com/c/net/+/565137
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-20 15:06:31 +00:00
Damien Neil
dda3687b19 quic: add Stream.ReadByte, Stream.WriteByte
Currently unoptimized and slow.
Adding along with a benchmark to compare to the fast-path followup.

For golang/go#58547

Change-Id: If02b65e6e7cfc770d3f949e5fb9fbb9d8a765a90
Reviewed-on: https://go-review.googlesource.com/c/net/+/564477
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-16 16:59:37 +00:00