Commit Graph

253 Commits

Author SHA1 Message Date
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
Damien Neil
e94da73eed quic: reduce ack frequency after the first 100 packets
RFC 9000 recommends sending an ack for every second ack-eliciting
packet received. This frequency is high enough to have a noticeable
impact on performance.

Follow the approach used by Google QUICHE: Ack every other packet
for the first 100 packets, and then switch to acking every 10th
packet.

(Various other implementations also use a reduced ack frequency;
see Custura et al., 2022.)

For golang/go#58547

Change-Id: Idc7051cec23c279811030eb555bc49bb888d6795
Reviewed-on: https://go-review.googlesource.com/c/net/+/564476
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-16 16:10:36 +00:00
Damien Neil
117945d00a quic: add throughput and stream creation benchmarks
For golang/go#58547

Change-Id: Ie62fcf596bf020bda5a167f7a0d3d95bac9e591a
Reviewed-on: https://go-review.googlesource.com/c/net/+/564475
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-15 18:32:21 +00:00
Damien Neil
93be8fe122 quic: log packet_dropped events
Log unparsable or otherwise discarded packets.

For golang/go#58547

Change-Id: Ief64174d91c93691bd524515aa6518e487543ced
Reviewed-on: https://go-review.googlesource.com/c/net/+/564017
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-15 16:13:12 +00:00
Damien Neil
6e383c4aaf quic: add qlog recovery metrics
Log events for various congestion control and loss recovery metrics.

For golang/go#58547

Change-Id: Ife3b3897f6ca731049c78b934a7123aa1ed4aee2
Reviewed-on: https://go-review.googlesource.com/c/net/+/564016
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-15 16:12:14 +00:00
Damien Neil
840656f921 quic/qlog: don't output empty slog.Attrs
For golang/go#58547

Change-Id: I49a27ab82781c817511c6f7da0268529abc3f27f
Reviewed-on: https://go-review.googlesource.com/c/net/+/564015
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-14 21:57:10 +00:00
Damien Neil
5a444b4f2f quic: add Stream.Set{Read,Write}Context, drop {Read,Write,Close}Context
The ReadContext, WriteContext, and CloseContext Stream methods are
difficult to use in conjunction with functions that operate on an
io.Reader, io.Writer, or io.Closer. For example, it's reasonable
to want to use io.ReadFull with a Stream, but doing so with a context
is cumbersome.

Drop the Stream methods that take a Context in favor of stateful
methods that set the Context to use for read and write operations.
(Close counts as a write operation, since it blocks waiting for
data to be sent.)

Intentionally make Set{Read,Write}Context not concurrency safe,
to allow the race detector to catch misuse. This shouldn't be a
problem for correct programs, since reads and writes are
inherently not concurrency-safe.

For golang/go#58547

Change-Id: I41378eb552d89a720921fc8644d3637c1a545676
Reviewed-on: https://go-review.googlesource.com/c/net/+/550795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-02-08 18:20:20 +00:00
btwiuse
b2208d046d internal/quic/qlog: fix typo
VantageClient -> VantageServer

Change-Id: Ie9738cffb06f03f961815853247e6f9cbe7fe466
GitHub-Last-Rev: 5d440ad29c
GitHub-Pull-Request: golang/net#202
Reviewed-on: https://go-review.googlesource.com/c/net/+/555795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2024-01-31 16:48:01 +00:00
Damien Neil
26b646ea02 quic: avoid deadlock in Endpoint.Close
Don't hold Endpoint.connsMu while calling Conn methods that can
indirectly depend on acquiring it.

Also change test cleanup to not wait for connections to drain
when closing a test Endpoint, removing an unnecessary 0.1s delay
in test runtime.

Fixes golang/go#64982.

Change-Id: If336e63b0a7f5b8d2ef63986d36f9ee38a92c477
Reviewed-on: https://go-review.googlesource.com/c/net/+/554695
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-08 18:45:12 +00:00
Damien Neil
689bbc7005 quic: deflake TestStreamsCreateConcurrency
This test assumed that creating a stream and flushing it on the
client ensured the server had accepted the stream. This isn't
the case; the stream has been delivered to the server, but there's
no guarantee that it been accepted by the user layer.

Change the test to make a full loop: The client creates a stream,
and then waits for the server to close it.

Fixes golang/go#64788

Change-Id: I24f08502e9f5d8bd5a17e680b0aa19dcc2623841
Reviewed-on: https://go-review.googlesource.com/c/net/+/554175
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-04 19:50:13 +00:00
Damien Neil
f12db26b1c internal/quic/cmd/interop: use wget --no-verbose in Dockerfile
Pass --no-verbose to wget to avoid spamming the build logs with
progress indicators.

Change-Id: I36a0b91f8dac09cc4055c5d5db3fc61c9b269d6e
Reviewed-on: https://go-review.googlesource.com/c/net/+/551495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-12-19 21:36:31 +00:00
Damien Neil
c136d0c937 quic: avoid panic when PTO expires and implicitly-created streams exist
The streams map contains nil entries for implicitly-created streams.
(Receiving a packet for stream N implicitly creates all streams of the
same type <N.)

We weren't checking for nil entries when iterating the map on PTO,
resulting in a panic.

Change the map value to be a wrapper type to make it more explicit that
nil entries exist.

Change-Id: I070c6d60631744018a6e6f2645c95a2f3d3d24b6
Reviewed-on: https://go-review.googlesource.com/c/net/+/550798
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-19 18:24:40 +00:00
Damien Neil
f9726a9e4a quic: fix packet size logging
The qlog schema puts packet sizes as part of a "raw" field
of type RawInfo, not in the packet_sent/packet_received event.
Move to the correct location.

Change-Id: I4308d4bdb961cf83e29af014b60f50ed029cb915
Reviewed-on: https://go-review.googlesource.com/c/net/+/550797
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-12-19 00:11:13 +00:00
Damien Neil
c337daf7db quic: enable qlog output in tests
Set QLOG=/some/dir to enable qlog logging in tests.

Change-Id: Id4006c66fd555ad0ca47914d0af9f9ab46467c9c
Reviewed-on: https://go-review.googlesource.com/c/net/+/550796
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-19 00:11:06 +00:00
Damien Neil
2b416c3c96 quic/qlog: create log files with O_EXCL
Avoid confusing log corruption if two loggers try to write
to the same file simultaneously.

Change-Id: I3bfbcf56aa55c778ada0178d7c662c414878c9d1
Reviewed-on: https://go-review.googlesource.com/c/net/+/545577
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-18 17:09:42 +00:00
Damien Neil
1e59a7e58c quic/qlog: correctly write negative durations
"-10.000001", not "10.-000001".

Change-Id: I84f6487bad15ab3a190e73e655236376b1781e85
Reviewed-on: https://go-review.googlesource.com/c/net/+/545576
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-18 17:09:33 +00:00
Damien Neil
b0eb4d6c94 quic: compute pnum len from max ack received, not sent
QUIC packet numbers are truncated to include only the least
significant bits of the packet number. The number of bits
which must be retained is computed based on the largest
packet number known to have been received by the peer.
See RFC 9000, section 17.1.

We were incorrectly using the largest packet number
we have received *from* the peer. Oops.

(Test infrastructure change: Include the header byte
in the testPacket structure, so we can see how many
bytes the packet number was encoded with. Ignore this
byte when comparing packets.)

Change-Id: Iec17c69f007f8b39d14d24b0ca216c6a0018ae22
Reviewed-on: https://go-review.googlesource.com/c/net/+/545575
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-18 17:09:24 +00:00
Damien Neil
b952594c26 quic: fix data race in connection close
We were failing to hold streamsState.streamsMu when removing
a closed stream from the conn's stream map.

Rework this to remove the mutex entirely.
The only access to the map that isn't on the conn's loop is
during stream creation. Send a message to the loop to
register the stream instead of using a mutex.

Change-Id: I2e87089e87c61a6ade8219dfb8acec3809bf95de
Reviewed-on: https://go-review.googlesource.com/c/net/+/545217
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-12-18 17:09:09 +00:00
Damien Neil
577e44a5ce quic: skip leaked goroutine check on GOOS=js
Fixes golang/go#64620

Change-Id: I3b5ff4d1e1132a47b7cc7eb00861e9f7b76f8764
Reviewed-on: https://go-review.googlesource.com/c/net/+/548455
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-08 16:07:49 +00:00
Damien Neil
65efbad947 quic: avoid leaking tls goroutines in tests
Change-Id: Iaf273294ba3245bfeb387a72e068c048d0fcf93a
Reviewed-on: https://go-review.googlesource.com/c/net/+/547736
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-07 01:27:06 +00:00
Damien Neil
08a78b1eea quic: unblock operations when closing conns
Blocking operations associated with a connection,
such as accepting a stream or writing data to a stream,
should be canceled when the connection is closed.

Change-Id: I3b25789885a6c1a2b5aa2178a8d6219a8ea77cbb
Reviewed-on: https://go-review.googlesource.com/c/net/+/545216
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>
2023-12-05 23:17:45 +00:00
Damien Neil
c1b6eee3f6 quic: send occasional ack-eliciting packets
A receiver that is sending only non-ack-eliciting packets
(for example, a connection reading data from a stream but not sending
anything other than ACKs in response) can accumulate a large amount
of state for in-flight, unacknowledged packets.

Add an occasional PING frame when in this state, to cause the peer
to send an ACK for our outstanding packets.

Change-Id: Iaf6b5a9735fa356fdebaff24200420a280b0c9a5
Reviewed-on: https://go-review.googlesource.com/c/net/+/545215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-12-05 20:38:13 +00:00
Damien Neil
491f354593 quic: log packets and frames
For golang/go#58547

Change-Id: I601f1e74417c0de206f71da58cef5938bba6e860
Reviewed-on: https://go-review.googlesource.com/c/net/+/543084
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-05 20:38:03 +00:00
Damien Neil
13e88dd2f7 quic: rename listener{_test}.go to endpoint{_test}.go
Separate from CL 543298 to help git recognize that this is a rename.

Change-Id: I1cbdffeb66d0960c951a564b8fc1a3dcf2cf40f6
Reviewed-on: https://go-review.googlesource.com/c/net/+/543299
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-17 21:35:08 +00:00
Damien Neil
e26b9a4457 quic: rename Listener to Endpoint
The name Listener is confusing, because unlike a net.Listener
a quic.Listener manages outgoing connections as well as inbound ones.

Rename to "endpoint" which doesn't map to any existing
net package name and matches the terminology of the QUIC RFCs.

For golang/go#58547

Change-Id: If87f8c67ac7dd15d89d2d082a8ba2c63ea7f6e26
Reviewed-on: https://go-review.googlesource.com/c/net/+/543298
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-11-17 21:33:25 +00:00
Damien Neil
399218d6bc quic: implement stream flush
Do not commit data written to a stream to the network until
the user explicitly flushes the stream, the stream output
buffer fills, or the output buffer contains enough data to
fill a packet.

We could write data immediately (as net.TCPConn does),
but this can require the user to put their own buffer in
front of the stream. Since we necessarily need to maintain
a retransmit buffer in the stream, this is redundant.

We could do something like Nagle's algorithm, but nobody
wants that.

So make flushes explicit.

For golang/go#58547

Change-Id: I29dc9d79556c7a358a360ef79beb38b45040b6bc
Reviewed-on: https://go-review.googlesource.com/c/net/+/543083
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>
2023-11-17 18:40:32 +00:00
Damien Neil
d87f99be5d quic: idle timeouts, handshake timeouts, and keepalive
Negotiate the connection idle timeout based on the sent and received
max_idle_timeout transport parameter values.

Set a configurable limit on how long a handshake can take to complete.

Add a configuration option to send keep-alive PING frames to avoid
connection closure due to the idle timeout.

RFC 9000, Section 10.1.

For golang/go#58547

Change-Id: If6a611090ab836cd6937fcfbb1360a0f07425102
Reviewed-on: https://go-review.googlesource.com/c/net/+/540895
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-11-17 18:04:24 +00:00
Damien Neil
7b5abfaf7f quic: basic qlog support
Add the structure for generating and writing qlog events.

Events are generated as slog events using the structure of
the qlog events (draft-ietf-quic-qlog-quic-events-03).

The qlog package contains a slog Handler implementation
that converts the quic package events to qlog JSON.

This CL generates events for connection creation and closure.
Future CLs will add additional events.

Events follow draft-ietf-quic-qlog-quic-events-03, which
is the most recent draft supported by the qvis visualization
tool.

https://www.ietf.org/archive/id/draft-ietf-quic-qlog-main-schema-04.html
https://www.ietf.org/archive/id/draft-ietf-quic-qlog-quic-events-03.html

For golang/go#58547

Change-Id: I5fb1b7653d0257cb86726bd5bc9e8775da74686a
Reviewed-on: https://go-review.googlesource.com/c/net/+/537936
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>
2023-11-17 16:13:12 +00:00
Damien Neil
a7ef1a2680 internal/quic/cmd/interop: don't t.Log after test finishes
Fixes golang/go#63971

Change-Id: I795356202880daa2d4a0cfd019c542e5820e8020
Reviewed-on: https://go-review.googlesource.com/c/net/+/539857
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-07 18:09:47 +00:00
Damien Neil
39c9d01355 quic: don't send CONNECTION_CLOSE after stateless reset
After receiving a stateless reset, we must enter the draining
state and send no further packets (including CONNECTION_CLOSE).
We were sending one last CONNECTION_CLOSE after the user
closed the Conn; fix this.

RFC 9000, Section 10.3.1.

Change-Id: I6a9cc6019470a25476df518022a32eefe0c50fcd
Reviewed-on: https://go-review.googlesource.com/c/net/+/540117
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-11-06 20:51:22 +00:00
Damien Neil
45fa414209 quic: undo accidental rename of test helpers
https://go.dev/cl/539341 inadvertently made the
newLocalConnPair and newLocalListener helpers exported.
These are test-only functions, so the change isn't really important,
but undo the rename to keep them consistent with other test helpers.

Change-Id: Ie3860db3584fc83c0c0aa2ad0dda4cc5cb03351a
Reviewed-on: https://go-review.googlesource.com/c/net/+/540116
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-11-06 20:51:14 +00:00
Damien Neil
434956a1a8 quic: include more detail in connection close errors
When closing a connection with an error, include a reason
string in the CONNECTION_CLOSE frame as well as the
error code, when the code isn't sufficient to explain the error.

Change-Id: I055a4e11b222e87d1ff01d8c45fcb7cc17fe4196
Reviewed-on: https://go-review.googlesource.com/c/net/+/539342
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-11-06 18:06:55 +00:00
Damien Neil
ec29a9498a quic: provide source conn ID when creating server conns
New server-side conns need to know a variety of connection IDs,
such as the Initial DCID used to create Initial encryption keys.
We've been providing these as an ever-growing list of []byte
parameters to newConn. Bundle them all up into a struct.

Add the client's SCID to the set of IDs we pass to newConn.
Up until now, we've been setting this when processing the
first Initial packet from the client. Passing it to newConn
will makes it available when logging the connection_started event.

Update some test infrastructure to deal with the fact that
we need to know the peer's SCID earlier in the test now.

Change-Id: I760ee94af36125acf21c5bf135f1168830ba1ab8
Reviewed-on: https://go-review.googlesource.com/c/net/+/539341
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-06 18:06:44 +00:00
Damien Neil
5791239e3d internal/quic/cmd/interop: skip tests when exec is unavailable
Some platforms, such as js and wasip1, can't exec.
Skip tests that need exec when it isn't available.

Change-Id: Id3787b28c2ffe780eb24800c59fe69d12e04bbdd
Reviewed-on: https://go-review.googlesource.com/c/net/+/539035
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-01 21:30:58 +00:00
Damien Neil
4865e2af27 internal/quic/cmd/interop: add interop test runner
The QUIC interop tests at https://interop.seemann.io/
invoke a program and instruct it to perform some set
of operations (mostly serve files from a directory,
or download a set of files).

The cmd/interop binary executes test cases for our
implementation.

For golang/go#58547

Change-Id: Ic1c8be2f3f49a30464650d9eaa5ded74c92fa5a7
Reviewed-on: https://go-review.googlesource.com/c/net/+/532435
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>
2023-10-31 21:19:14 +00:00
Damien Neil
770149e988 quic: pad ack-eliciting server Initial datagrams
UDP datagrams containing Initial packets are expanded to 1200 bytes
to validate that the path is capable of supporting the smallest
allowed maximum QUIC datagram size.

(In addition, client Initial packets must be sent in datagrams
of at least 1200 bytes, to defend against amplification attacks.)

We were expanding client datagrams containing Initial packets,
but not server datagrams. Fix this. (More specifically, server
datagrams must be expanded to 1200 bytes when they contain
ack-eliciting Initial packets.)

RFC 9000, Section 14.1.

Change-Id: I0c0c36321c055e960be3e29a49d7cb7620640b82
Reviewed-on: https://go-review.googlesource.com/c/net/+/538776
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-31 21:05:27 +00:00
Damien Neil
05086a79fc quic: fix panic when handling resent CRYPTO data
When pipe.discardBefore was called with an offset greater
than the current pipe.end position, we would update
pipe.start but not pipe.end, leaving the pipe in an
inconsistent state where start > end. This could then
subsequently cause a panic when writing data that
lies before pipe.start.

This sequence occurs when handling several in-order
CRYPTO frames (where we skip writing in-order data
to the pipe, but still call discardBefore), followed
by an out-of-order frame containing resent data.

Change-Id: Ibac0caad53cd30dac1cd4719a825226809872d96
Reviewed-on: https://go-review.googlesource.com/c/net/+/538775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2023-10-31 18:01:49 +00:00
Damien Neil
0526b49b34 quic: fix data race caused by aliased DCID
The initServer function was retaining a reference to a []byte that
aliases a packet buffer, which is subsequently recycled.

Make a copy of the data before retaining it.

Fixes golang/go#63783

Change-Id: I3dbb0cdfd78681014dec97ff9909ff6c7dbf82ba
Reviewed-on: https://go-review.googlesource.com/c/net/+/538615
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>
2023-10-30 20:00:15 +00:00