introduce Transport.ConnContext, use client's context on the connection (#4507)

* introduce Transport.ConnContext, use client's context on the connection

* panic if ConnContext returns nil
This commit is contained in:
Marten Seemann
2024-05-27 12:30:19 +08:00
committed by GitHub
parent e2fbf3cdcd
commit 0d1e27d77c
15 changed files with 260 additions and 97 deletions

View File

@@ -203,8 +203,8 @@ func (h *cryptoSetup) SetLargest1RTTAcked(pn protocol.PacketNumber) error {
return h.aead.SetLargestAcked(pn)
}
func (h *cryptoSetup) StartHandshake() error {
err := h.conn.Start(context.WithValue(context.Background(), QUICVersionContextKey, h.version))
func (h *cryptoSetup) StartHandshake(ctx context.Context) error {
err := h.conn.Start(context.WithValue(ctx, QUICVersionContextKey, h.version))
if err != nil {
return wrapError(err)
}

View File

@@ -1,6 +1,7 @@
package handshake
import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
@@ -75,7 +76,7 @@ var _ = Describe("Crypto Setup TLS", func() {
protocol.Version1,
)
Expect(cl.StartHandshake()).To(MatchError(&qerr.TransportError{
Expect(cl.StartHandshake(context.Background())).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.InternalError,
ErrorMessage: "tls: invalid NextProtos value",
}))
@@ -96,7 +97,7 @@ var _ = Describe("Crypto Setup TLS", func() {
protocol.Version1,
)
Expect(server.StartHandshake()).To(Succeed())
Expect(server.StartHandshake(context.Background())).To(Succeed())
fakeCH := append([]byte{typeClientHello, 0, 0, 6}, []byte("foobar")...)
// wrong encryption level
@@ -189,8 +190,8 @@ var _ = Describe("Crypto Setup TLS", func() {
// The clientEvents and serverEvents contain all events that were not processed by the function,
// i.e. not EventWriteInitialData, EventWriteHandshakeData, EventHandshakeComplete.
handshake := func(client, server CryptoSetup) (clientEvents []Event, clientErr error, serverEvents []Event, serverErr error) {
Expect(client.StartHandshake()).To(Succeed())
Expect(server.StartHandshake()).To(Succeed())
Expect(client.StartHandshake(context.Background())).To(Succeed())
Expect(server.StartHandshake(context.Background())).To(Succeed())
var clientHandshakeComplete, serverHandshakeComplete bool

View File

@@ -1,6 +1,7 @@
package handshake
import (
"context"
"crypto/tls"
"errors"
"io"
@@ -91,7 +92,7 @@ type Event struct {
// CryptoSetup handles the handshake and protecting / unprotecting packets
type CryptoSetup interface {
StartHandshake() error
StartHandshake(context.Context) error
io.Closer
ChangeConnectionID(protocol.ConnectionID)
GetSessionTicket() ([]byte, error)