impl: uquic with utls

This commit is contained in:
Gaukas Wang 2023-07-29 23:45:16 -06:00
parent 251b3afe6e
commit fca46117e4
No known key found for this signature in database
GPG key ID: 9E2F8986D76F8B5D
56 changed files with 445 additions and 88 deletions

View file

@ -2,10 +2,11 @@ package quic
import (
"context"
"crypto/tls"
"errors"
"net"
tls "github.com/refraction-networking/utls"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/utils"
"github.com/quic-go/quic-go/logging"
@ -37,6 +38,8 @@ type client struct {
tracer logging.ConnectionTracer
tracingID uint64
logger utils.Logger
chs *tls.ClientHelloSpec // [UQUIC]
}
// make it possible to mock connection ID for initial generation in the tests
@ -157,6 +160,42 @@ func dial(
if c.tracer != nil {
c.tracer.StartedConnection(c.sendConn.LocalAddr(), c.sendConn.RemoteAddr(), c.srcConnID, c.destConnID)
}
if err := c.dial(ctx); err != nil {
return nil, err
}
return c.conn, nil
}
func dialWithCHS(
ctx context.Context,
conn sendConn,
connIDGenerator ConnectionIDGenerator,
packetHandlers packetHandlerManager,
tlsConf *tls.Config,
config *Config,
onClose func(),
use0RTT bool,
chs *tls.ClientHelloSpec,
) (quicConn, error) {
c, err := newClient(conn, connIDGenerator, config, tlsConf, onClose, use0RTT)
if err != nil {
return nil, err
}
c.packetHandlers = packetHandlers
c.tracingID = nextConnTracingID()
if c.config.Tracer != nil {
c.tracer = c.config.Tracer(context.WithValue(ctx, ConnectionTracingKey, c.tracingID), protocol.PerspectiveClient, c.destConnID)
}
if c.tracer != nil {
c.tracer.StartedConnection(c.sendConn.LocalAddr(), c.sendConn.RemoteAddr(), c.srcConnID, c.destConnID)
}
// [UQUIC]
c.chs = chs
// [/UQUIC]
if err := c.dial(ctx); err != nil {
return nil, err
}
@ -213,22 +252,46 @@ func newClient(sendConn sendConn, connIDGenerator ConnectionIDGenerator, config
func (c *client) dial(ctx context.Context) error {
c.logger.Infof("Starting new connection to %s (%s -> %s), source connection ID %s, destination connection ID %s, version %s", c.tlsConf.ServerName, c.sendConn.LocalAddr(), c.sendConn.RemoteAddr(), c.srcConnID, c.destConnID, c.version)
c.conn = newClientConnection(
c.sendConn,
c.packetHandlers,
c.destConnID,
c.srcConnID,
c.connIDGenerator,
c.config,
c.tlsConf,
c.initialPacketNumber,
c.use0RTT,
c.hasNegotiatedVersion,
c.tracer,
c.tracingID,
c.logger,
c.version,
)
// [UQUIC]
if c.chs == nil {
c.conn = newClientConnection(
c.sendConn,
c.packetHandlers,
c.destConnID,
c.srcConnID,
c.connIDGenerator,
c.config,
c.tlsConf,
c.initialPacketNumber,
c.use0RTT,
c.hasNegotiatedVersion,
c.tracer,
c.tracingID,
c.logger,
c.version,
)
} else {
// [UQUIC]: use custom version of the connection
c.conn = newUClientConnection(
c.sendConn,
c.packetHandlers,
c.destConnID,
c.srcConnID,
c.connIDGenerator,
c.config,
c.tlsConf,
c.initialPacketNumber,
c.use0RTT,
c.hasNegotiatedVersion,
c.tracer,
c.tracingID,
c.logger,
c.version,
c.chs,
)
}
// [/UQUIC]
c.packetHandlers.Add(c.srcConnID, c.conn)
errorChan := make(chan error, 1)