diff --git a/go.mod b/go.mod index 2f2f5cd205..c65c55711f 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/pborman/getopt/v2 v2.1.0 github.com/pion/stun v0.6.1 github.com/pkg/errors v0.9.1 - github.com/quic-go/quic-go v0.33.0 + github.com/quic-go/quic-go v0.37.3 github.com/rogpeppe/go-internal v1.11.0 github.com/rubenv/sql-migrate v1.5.1 github.com/schollz/progressbar/v3 v3.13.1 @@ -74,7 +74,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect + github.com/quic-go/qtls-go1-20 v0.3.1 // indirect github.com/refraction-networking/conjure v0.4.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/segmentio/fasthash v1.0.3 // indirect diff --git a/go.sum b/go.sum index 327cbd7c56..abdbff4779 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= +github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU= github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -173,6 +174,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= @@ -338,6 +340,7 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/josharian/native v1.0.0 h1:Ts/E8zCSEsG17dUqv7joXJFybuMLjQfWE04tsBODTxk= @@ -357,6 +360,8 @@ github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1 github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/keltia/proxy v0.9.3/go.mod h1:fLU4DmBPG0oh0md9fWggE2oG2m7Lchv3eim+GiO3pZY= +github.com/keltia/ripe-atlas v0.0.0-20211221125000-f6eb808d5dc6/go.mod h1:zYa+dM8811qRhclezc/AKX9imyQwPjjSk2cH0xTgTag= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= @@ -448,6 +453,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/mroth/weightedrand v1.0.0 h1:V8JeHChvl2MP1sAoXq4brElOcza+jxLkRuwvtQu8L3E= @@ -620,8 +626,16 @@ github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc8 github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= +github.com/quic-go/qtls-go1-20 v0.3.1 h1:O4BLOM3hwfVF3AcktIylQXyl7Yi2iBNVy5QsV+ySxbg= +github.com/quic-go/qtls-go1-20 v0.3.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= +github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= +github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g= +github.com/quic-go/quic-go v0.36.0 h1:JIrO7p7Ug6hssFcARjWDiqS2RAKJHCiwPxBAA989rbI= +github.com/quic-go/quic-go v0.36.0/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= +github.com/quic-go/quic-go v0.37.3 h1:pkHH3xaMNUNAh6OtgEV/0K6Fz+YIJXhPzgd/ShiRDm4= +github.com/quic-go/quic-go v0.37.3/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/refraction-networking/conjure v0.4.0 h1:YObJ+6L/MnupE82N2+3m93GMzlHjHSHe1ysIYDOpqug= github.com/refraction-networking/conjure v0.4.0/go.mod h1:7na+SFWdaTOToNoNrsJRIj4CIMwdGFZ4kwb/CO5Z0rQ= diff --git a/internal/dslx/quic.go b/internal/dslx/quic.go index e0677280b1..16018b485f 100644 --- a/internal/dslx/quic.go +++ b/internal/dslx/quic.go @@ -97,10 +97,10 @@ func (f *quicHandshakeFunc) Apply( ) // setup - quicListener := netxlite.NewQUICListener() + udpListener := netxlite.NewUDPListener() quicDialer := f.dialer if quicDialer == nil { - quicDialer = trace.NewQUICDialerWithoutResolver(quicListener, input.Logger) + quicDialer = trace.NewQUICDialerWithoutResolver(udpListener, input.Logger) } config := &tls.Config{ NextProtos: []string{"h3"}, @@ -119,7 +119,7 @@ func (f *quicHandshakeFunc) Apply( var tlsState tls.ConnectionState if quicConn != nil { closerConn = &quicCloserConn{quicConn} - tlsState = quicConn.ConnectionState().TLS.ConnectionState // only quicConn can be nil + tlsState = quicConn.ConnectionState().TLS // only quicConn can be nil } // possibly track established conn for late close diff --git a/internal/experiment/simplequicping/simplequicping.go b/internal/experiment/simplequicping/simplequicping.go index 1e91a7281b..55f3b67d80 100644 --- a/internal/experiment/simplequicping/simplequicping.go +++ b/internal/experiment/simplequicping/simplequicping.go @@ -171,7 +171,7 @@ func (m *Measurer) quicHandshake(ctx context.Context, index int64, alpn := strings.Split(m.config.alpn(), " ") trace := measurexlite.NewTrace(index, zeroTime) ol := measurexlite.NewOperationLogger(logger, "SimpleQUICPing #%d %s %s %v", index, address, sni, alpn) - listener := netxlite.NewQUICListener() + listener := netxlite.NewUDPListener() dialer := trace.NewQUICDialerWithoutResolver(listener, logger) // See https://github.com/ooni/probe/issues/2413 to understand // why we're using nil to force netxlite to use the cached diff --git a/internal/legacy/netx/quic.go b/internal/legacy/netx/quic.go index e48de760d6..15ad905e66 100644 --- a/internal/legacy/netx/quic.go +++ b/internal/legacy/netx/quic.go @@ -16,7 +16,7 @@ func NewQUICDialer(config Config) model.QUICDialer { } // TODO(https://github.com/ooni/probe/issues/2121#issuecomment-1147424810): we // should count the bytes consumed by this QUIC dialer - ql := config.ReadWriteSaver.WrapQUICListener(netxlite.NewQUICListener()) + ql := config.ReadWriteSaver.WrapUDPListener(netxlite.NewUDPListener()) logger := model.ValidLoggerOrDefault(config.Logger) return netxlite.NewQUICDialerWithResolver(ql, logger, config.FullResolver, config.Saver) } diff --git a/internal/measurex/quic.go b/internal/measurex/quic.go index d53bd80eea..7fdcae0a17 100644 --- a/internal/measurex/quic.go +++ b/internal/measurex/quic.go @@ -17,14 +17,14 @@ import ( "github.com/quic-go/quic-go" ) -type quicListenerDB struct { - model.QUICListener +type udpListenerDB struct { + model.UDPListener begin time.Time db WritableDB } -func (ql *quicListenerDB) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { - pconn, err := ql.QUICListener.Listen(addr) +func (ql *udpListenerDB) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { + pconn, err := ql.UDPListener.Listen(addr) if err != nil { return nil, err } @@ -109,17 +109,17 @@ func (qh *quicDialerDB) DialContext(ctx context.Context, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { started := time.Since(qh.begin).Seconds() var state tls.ConnectionState - listener := &quicListenerDB{ - QUICListener: netxlite.NewQUICListener(), - begin: qh.begin, - db: qh.db, + listener := &udpListenerDB{ + UDPListener: netxlite.NewUDPListener(), + begin: qh.begin, + db: qh.db, } dialer := netxlite.NewQUICDialerWithoutResolver(listener, qh.logger) defer dialer.CloseIdleConnections() sess, err := dialer.DialContext(ctx, address, tlsConfig, quicConfig) if err == nil { - <-sess.HandshakeComplete().Done() // robustness (the dialer already does that) - state = sess.ConnectionState().TLS.ConnectionState + <-sess.HandshakeComplete() // robustness (the dialer already does that) + state = sess.ConnectionState().TLS } finished := time.Since(qh.begin).Seconds() qh.db.InsertIntoQUICHandshake(&QUICTLSHandshakeEvent{ diff --git a/internal/measurexlite/quic.go b/internal/measurexlite/quic.go index d69760be9c..d75aed649c 100644 --- a/internal/measurexlite/quic.go +++ b/internal/measurexlite/quic.go @@ -16,7 +16,7 @@ import ( // NewQUICDialerWithoutResolver is equivalent to netxlite.NewQUICDialerWithoutResolver // except that it returns a model.QUICDialer that uses this trace. -func (tx *Trace) NewQUICDialerWithoutResolver(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { +func (tx *Trace) NewQUICDialerWithoutResolver(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { return &quicDialerTrace{ qd: tx.newQUICDialerWithoutResolver(listener, dl), tx: tx, @@ -60,7 +60,7 @@ func (tx *Trace) OnQUICHandshakeDone(started time.Time, remoteAddr string, qconn state := tls.ConnectionState{} if qconn != nil { - state = qconn.ConnectionState().TLS.ConnectionState + state = qconn.ConnectionState().TLS } select { diff --git a/internal/measurexlite/quic_test.go b/internal/measurexlite/quic_test.go index daebfca9e6..78083643e2 100644 --- a/internal/measurexlite/quic_test.go +++ b/internal/measurexlite/quic_test.go @@ -23,10 +23,10 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { underlying := &mocks.QUICDialer{} zeroTime := time.Now() trace := NewTrace(0, zeroTime) - trace.newQUICDialerWithoutResolverFn = func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { + trace.newQUICDialerWithoutResolverFn = func(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { return underlying } - listener := &mocks.QUICListener{} + listener := &mocks.UDPListener{} dialer := trace.NewQUICDialerWithoutResolver(listener, model.DiscardLogger) dt := dialer.(*quicDialerTrace) if dt.qd != underlying { @@ -50,10 +50,10 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { return nil, expectedErr }, } - trace.newQUICDialerWithoutResolverFn = func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { + trace.newQUICDialerWithoutResolverFn = func(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { return underlying } - listener := &mocks.QUICListener{} + listener := &mocks.UDPListener{} dialer := trace.NewQUICDialerWithoutResolver(listener, model.DiscardLogger) ctx := context.Background() conn, err := dialer.DialContext(ctx, "1.1.1.1:443", &tls.Config{}, &quic.Config{}) @@ -77,10 +77,10 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { called = true }, } - trace.newQUICDialerWithoutResolverFn = func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { + trace.newQUICDialerWithoutResolverFn = func(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { return underlying } - listener := &mocks.QUICListener{} + listener := &mocks.UDPListener{} dialer := trace.NewQUICDialerWithoutResolver(listener, model.DiscardLogger) dialer.CloseIdleConnections() if !called { @@ -97,6 +97,9 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { pconn := &mocks.UDPLikeConn{ MockLocalAddr: func() net.Addr { return &net.UDPAddr{ + // quic-go does not allow the use of the same net.PacketConn for multiple "Dial" + // calls (unless a quic.Transport is used), so we have to make sure to mock local + // addresses with different ports, as tests run in parallel. Port: 0, } }, @@ -111,8 +114,11 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { MockClose: func() error { return nil }, + MockSetReadBuffer: func(n int) error { + return nil + }, } - listener := &mocks.QUICListener{ + listener := &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return pconn, nil }, @@ -207,7 +213,10 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { pconn := &mocks.UDPLikeConn{ MockLocalAddr: func() net.Addr { return &net.UDPAddr{ - Port: 0, + // quic-go does not allow the use of the same net.PacketConn for multiple "Dial" + // calls (unless a quic.Transport is used), so we have to make sure to mock local + // addresses with different ports, as tests run in parallel. + Port: 1, } }, MockRemoteAddr: func() net.Addr { @@ -221,8 +230,11 @@ func TestNewQUICDialerWithoutResolver(t *testing.T) { MockClose: func() error { return nil }, + MockSetReadBuffer: func(n int) error { + return nil + }, } - listener := &mocks.QUICListener{ + listener := &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return pconn, nil }, @@ -262,8 +274,8 @@ func TestOnQUICHandshakeDoneExtractsTheConnectionState(t *testing.T) { trace := NewTrace(0, time.Now()) // create a QUIC dialer - quicListener := netxlite.NewQUICListener() - quicDialer := trace.NewQUICDialerWithoutResolver(quicListener, model.DiscardLogger) + udpListener := netxlite.NewUDPListener() + quicDialer := trace.NewQUICDialerWithoutResolver(udpListener, model.DiscardLogger) // dial with the endpoint we use for testing quicConn, err := quicDialer.DialContext( diff --git a/internal/measurexlite/trace.go b/internal/measurexlite/trace.go index 7f69eed017..2ae953125d 100644 --- a/internal/measurexlite/trace.go +++ b/internal/measurexlite/trace.go @@ -69,7 +69,7 @@ type Trace struct { // NewDialerWithoutResolverFn is OPTIONAL and can be used to override // calls to the netxlite.NewQUICDialerWithoutResolver factory. - newQUICDialerWithoutResolverFn func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer + newQUICDialerWithoutResolverFn func(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer // dnsLookup is MANDATORY and buffers DNS Lookup observations. dnsLookup chan *model.ArchivalDNSLookupResult @@ -229,7 +229,7 @@ func (tx *Trace) newTLSHandshakerUTLS(dl model.DebugLogger, id *utls.ClientHello // newQUICDialerWithoutResolver indirectly calls netxlite.NewQUICDialerWithoutResolver // thus allowing us to mock this func for testing. -func (tx *Trace) newQUICDialerWithoutResolver(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { +func (tx *Trace) newQUICDialerWithoutResolver(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { if tx.newQUICDialerWithoutResolverFn != nil { return tx.newQUICDialerWithoutResolverFn(listener, dl) } diff --git a/internal/measurexlite/trace_test.go b/internal/measurexlite/trace_test.go index bbcb46096a..e7950f93ad 100644 --- a/internal/measurexlite/trace_test.go +++ b/internal/measurexlite/trace_test.go @@ -508,7 +508,7 @@ func TestTrace(t *testing.T) { t.Run("when not nil", func(t *testing.T) { mockedErr := errors.New("mocked") tx := &Trace{ - newQUICDialerWithoutResolverFn: func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer { + newQUICDialerWithoutResolverFn: func(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { return &mocks.QUICDialer{ MockDialContext: func(ctx context.Context, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { @@ -517,7 +517,7 @@ func TestTrace(t *testing.T) { } }, } - qdx := tx.newQUICDialerWithoutResolver(&mocks.QUICListener{}, model.DiscardLogger) + qdx := tx.newQUICDialerWithoutResolver(&mocks.UDPListener{}, model.DiscardLogger) ctx := context.Background() qconn, err := qdx.DialContext(ctx, "1.1.1.1:443", &tls.Config{}, &quic.Config{}) if !errors.Is(err, mockedErr) { @@ -536,6 +536,9 @@ func TestTrace(t *testing.T) { pconn := &mocks.UDPLikeConn{ MockLocalAddr: func() net.Addr { return &net.UDPAddr{ + // quic-go does not allow the use of the same net.PacketConn for multiple "Dial" + // calls (unless a quic.Transport is used), so we have to make sure to mock local + // addresses with different ports, as tests run in parallel. Port: 0, } }, @@ -550,8 +553,11 @@ func TestTrace(t *testing.T) { MockClose: func() error { return nil }, + MockSetReadBuffer: func(n int) error { + return nil + }, } - listener := &mocks.QUICListener{ + listener := &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return pconn, nil }, diff --git a/internal/mocks/quic.go b/internal/mocks/quic.go index 3e90d54d09..102bb2f1dd 100644 --- a/internal/mocks/quic.go +++ b/internal/mocks/quic.go @@ -11,13 +11,13 @@ import ( "github.com/quic-go/quic-go" ) -// QUICListener is a mockable netxlite.QUICListener. -type QUICListener struct { +// UDPListener is a mockable netxlite.UDPListener. +type UDPListener struct { MockListen func(addr *net.UDPAddr) (model.UDPLikeConn, error) } // Listen calls MockListen. -func (ql *QUICListener) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { +func (ql *UDPListener) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { return ql.MockListen(addr) } @@ -57,10 +57,10 @@ type QUICEarlyConnection struct { MockCloseWithError func(code quic.ApplicationErrorCode, reason string) error MockContext func() context.Context MockConnectionState func() quic.ConnectionState - MockHandshakeComplete func() context.Context + MockHandshakeComplete func() <-chan struct{} MockNextConnection func() quic.Connection MockSendMessage func(b []byte) error - MockReceiveMessage func() ([]byte, error) + MockReceiveMessage func(ctx context.Context) ([]byte, error) } var _ quic.EarlyConnection = &QUICEarlyConnection{} @@ -122,7 +122,7 @@ func (s *QUICEarlyConnection) ConnectionState() quic.ConnectionState { } // HandshakeComplete calls MockHandshakeComplete. -func (s *QUICEarlyConnection) HandshakeComplete() context.Context { +func (s *QUICEarlyConnection) HandshakeComplete() <-chan struct{} { return s.MockHandshakeComplete() } @@ -137,8 +137,8 @@ func (s *QUICEarlyConnection) SendMessage(b []byte) error { } // ReceiveMessage calls MockReceiveMessage. -func (s *QUICEarlyConnection) ReceiveMessage() ([]byte, error) { - return s.MockReceiveMessage() +func (s *QUICEarlyConnection) ReceiveMessage(ctx context.Context) ([]byte, error) { + return s.MockReceiveMessage(ctx) } // UDPLikeConn is an UDP conn used by QUIC. diff --git a/internal/mocks/quic_test.go b/internal/mocks/quic_test.go index d275448208..bb5505f437 100644 --- a/internal/mocks/quic_test.go +++ b/internal/mocks/quic_test.go @@ -15,10 +15,10 @@ import ( "github.com/quic-go/quic-go" ) -func TestQUICListenerListen(t *testing.T) { +func TestUDPListenerListen(t *testing.T) { t.Run("Listen", func(t *testing.T) { expected := errors.New("mocked error") - ql := &QUICListener{ + ql := &UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return nil, expected }, @@ -235,13 +235,13 @@ func TestQUICEarlyConnection(t *testing.T) { t.Run("HandshakeComplete", func(t *testing.T) { ctx := context.Background() qconn := &QUICEarlyConnection{ - MockHandshakeComplete: func() context.Context { - return ctx + MockHandshakeComplete: func() <-chan struct{} { + return ctx.Done() }, } out := qconn.HandshakeComplete() - if !reflect.DeepEqual(ctx, out) { - t.Fatal("not the context we expected") + if !reflect.DeepEqual(ctx.Done(), out) { + t.Fatal("not the channel we expected") } }) @@ -274,12 +274,13 @@ func TestQUICEarlyConnection(t *testing.T) { t.Run("ReceiveMessage", func(t *testing.T) { expected := errors.New("mocked error") + ctx := context.Background() qconn := &QUICEarlyConnection{ - MockReceiveMessage: func() ([]byte, error) { + MockReceiveMessage: func(ctx context.Context) ([]byte, error) { return nil, expected }, } - b, err := qconn.ReceiveMessage() + b, err := qconn.ReceiveMessage(ctx) if !errors.Is(err, expected) { t.Fatal("not the error we expected", err) } diff --git a/internal/model/netx.go b/internal/model/netx.go index f24db2ac64..3148922511 100644 --- a/internal/model/netx.go +++ b/internal/model/netx.go @@ -181,8 +181,8 @@ type HTTPSSvc struct { IPv6 []string } -// QUICListener listens for QUIC connections. -type QUICListener interface { +// UDPListener listens for connections over UDP, e.g. QUIC. +type UDPListener interface { // Listen creates a new listening UDPLikeConn. Listen(addr *net.UDPAddr) (UDPLikeConn, error) } diff --git a/internal/netxlite/http3.go b/internal/netxlite/http3.go index 92093062d1..dcc667bc87 100644 --- a/internal/netxlite/http3.go +++ b/internal/netxlite/http3.go @@ -65,7 +65,7 @@ func NewHTTP3Transport( // NewHTTP3TransportStdlib creates a new HTTPTransport using http3 that // uses standard functionality for everything but the logger. func NewHTTP3TransportStdlib(logger model.DebugLogger) model.HTTPTransport { - ql := NewQUICListener() + ql := NewUDPListener() reso := NewStdlibResolver(logger) qd := NewQUICDialerWithResolver(ql, logger, reso) return NewHTTP3Transport(logger, qd, nil) @@ -74,7 +74,7 @@ func NewHTTP3TransportStdlib(logger model.DebugLogger) model.HTTPTransport { // NewHTTPTransportWithResolver creates a new HTTPTransport using http3 // that uses the given logger and the given resolver. func NewHTTP3TransportWithResolver(logger model.DebugLogger, reso model.Resolver) model.HTTPTransport { - qd := NewQUICDialerWithResolver(NewQUICListener(), logger, reso) + qd := NewQUICDialerWithResolver(NewUDPListener(), logger, reso) return NewHTTP3Transport(logger, qd, nil) } diff --git a/internal/netxlite/http3_test.go b/internal/netxlite/http3_test.go index 3f1038ab5d..7d7dbee4dc 100644 --- a/internal/netxlite/http3_test.go +++ b/internal/netxlite/http3_test.go @@ -162,7 +162,7 @@ func TestNewHTTP3ClientWithResolver(t *testing.T) { if dialerReso.Resolver != reso { t.Fatal("invalid resolver") } - if dialerQUICGo.QUICListener == nil { - t.Fatal("QUICListener should not be nil") + if dialerQUICGo.UDPListener == nil { + t.Fatal("UDPListener should not be nil") } } diff --git a/internal/netxlite/integration_test.go b/internal/netxlite/integration_test.go index 9710ed141b..dd08256a64 100644 --- a/internal/netxlite/integration_test.go +++ b/internal/netxlite/integration_test.go @@ -475,7 +475,7 @@ func TestMeasureWithQUICDialer(t *testing.T) { // t.Run("on success", func(t *testing.T) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) defer d.CloseIdleConnections() ctx := context.Background() @@ -498,7 +498,7 @@ func TestMeasureWithQUICDialer(t *testing.T) { }) t.Run("on timeout", func(t *testing.T) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) defer d.CloseIdleConnections() ctx := context.Background() @@ -576,7 +576,7 @@ func TestHTTP3Transport(t *testing.T) { t.Run("works as intended", func(t *testing.T) { d := netxlite.NewQUICDialerWithResolver( - netxlite.NewQUICListener(), + netxlite.NewUDPListener(), log.Log, netxlite.NewStdlibResolver(log.Log), ) diff --git a/internal/netxlite/netx.go b/internal/netxlite/netx.go index c309efc801..51e2c40306 100644 --- a/internal/netxlite/netx.go +++ b/internal/netxlite/netx.go @@ -39,17 +39,17 @@ func (n *Netx) NewDialerWithResolver(dl model.DebugLogger, r model.Resolver, w . // NewQUICListener is like [netxlite.NewQUICListener] but the constructed [model.QUICListener] // uses the [UnderlyingNetwork] configured inside the [Net] structure. -func (n *Netx) NewQUICListener() model.QUICListener { - return &quicListenerErrWrapper{&quicListenerStdlib{provider: n.tproxyNilSafeProvider()}} +func (n *Netx) NewQUICListener() model.UDPListener { + return &udpListenerErrWrapper{&udpListenerStdlib{provider: n.tproxyNilSafeProvider()}} } // NewQUICDialerWithResolver is like [netxlite.NewQUICDialerWithResolver] but the constructed // [model.QUICDialer] uses the [UnderlyingNetwork] configured inside the [Net] structure. -func (n *Netx) NewQUICDialerWithResolver(listener model.QUICListener, logger model.DebugLogger, +func (n *Netx) NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, resolver model.Resolver, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { baseDialer := &quicDialerQUICGo{ - QUICListener: listener, - provider: n.tproxyNilSafeProvider(), + UDPListener: listener, + provider: n.tproxyNilSafeProvider(), } return WrapQUICDialer(logger, resolver, baseDialer, wrappers...) } diff --git a/internal/netxlite/quic.go b/internal/netxlite/quic.go index 20f810aa5f..23512764af 100644 --- a/internal/netxlite/quic.go +++ b/internal/netxlite/quic.go @@ -16,22 +16,22 @@ import ( "github.com/quic-go/quic-go" ) -// NewQUICListener creates a new QUICListener using the standard +// NewUDPListener creates a new UDPListener using the standard // library to create listening UDP sockets. -func NewQUICListener() model.QUICListener { - return &quicListenerErrWrapper{&quicListenerStdlib{}} +func NewUDPListener() model.UDPListener { + return &udpListenerErrWrapper{&udpListenerStdlib{}} } -// quicListenerStdlib is a QUICListener using the standard library. -type quicListenerStdlib struct { +// udpListenerStdlib is a UDPListener using the standard library. +type udpListenerStdlib struct { // provider is the OPTIONAL nil-safe [model.UnderlyingNetwork] provider. provider *MaybeCustomUnderlyingNetwork } -var _ model.QUICListener = &quicListenerStdlib{} +var _ model.UDPListener = &udpListenerStdlib{} -// Listen implements QUICListener.Listen. -func (qls *quicListenerStdlib) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { +// Listen implements UDPListener.Listen. +func (qls *udpListenerStdlib) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { return qls.provider.Get().ListenUDP("udp", addr) } @@ -52,10 +52,10 @@ func (qls *quicListenerStdlib) Listen(addr *net.UDPAddr) (model.UDPLikeConn, err // Unlike the dialer returned by WrapDialer, this dialer MAY attempt // happy eyeballs, perform parallel dial attempts, and return an error // that aggregates all the errors that occurred. -func NewQUICDialerWithResolver(listener model.QUICListener, logger model.DebugLogger, +func NewQUICDialerWithResolver(listener model.UDPListener, logger model.DebugLogger, resolver model.Resolver, wrappers ...model.QUICDialerWrapper) (outDialer model.QUICDialer) { baseDialer := &quicDialerQUICGo{ - QUICListener: listener, + UDPListener: listener, } return WrapQUICDialer(logger, resolver, baseDialer, wrappers...) } @@ -90,19 +90,19 @@ func WrapQUICDialer(logger model.DebugLogger, resolver model.Resolver, // NewQUICDialerWithoutResolver is equivalent to calling NewQUICDialerWithResolver // with the resolver argument set to &NullResolver{}. -func NewQUICDialerWithoutResolver(listener model.QUICListener, +func NewQUICDialerWithoutResolver(listener model.UDPListener, logger model.DebugLogger, wrappers ...model.QUICDialerWrapper) model.QUICDialer { return NewQUICDialerWithResolver(listener, logger, &NullResolver{}, wrappers...) } // quicDialerQUICGo dials using the quic-go/quic-go library. type quicDialerQUICGo struct { - // QUICListener is the underlying QUICListener to use. - QUICListener model.QUICListener + // UDPListener is the underlying UDPListener to use. + UDPListener model.UDPListener - // mockDialEarlyContext allows to mock quic.DialEarlyContext. - mockDialEarlyContext func(ctx context.Context, pconn net.PacketConn, - remoteAddr net.Addr, host string, tlsConfig *tls.Config, + // mockDialEarly allows to mock quic.DialEarly. + mockDialEarly func(ctx context.Context, pconn net.PacketConn, + remoteAddr net.Addr, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) // provider is the OPTIONAL nil-safe [model.UnderlyingNetwork] provider. @@ -152,7 +152,7 @@ func (d *quicDialerQUICGo) DialContext(ctx context.Context, if err != nil { return nil, err } - pconn, err := d.QUICListener.Listen(&net.UDPAddr{IP: net.IPv4zero, Port: 0, Zone: ""}) + pconn, err := d.UDPListener.Listen(&net.UDPAddr{IP: net.IPv4zero, Port: 0, Zone: ""}) if err != nil { return nil, err } @@ -161,8 +161,7 @@ func (d *quicDialerQUICGo) DialContext(ctx context.Context, pconn = trace.MaybeWrapUDPLikeConn(pconn) started := trace.TimeNow() trace.OnQUICHandshakeStart(started, address, quicConfig) - qconn, err := d.dialEarlyContext( - ctx, pconn, udpAddr, address, tlsConfig, quicConfig) + qconn, err := d.dialEarly(ctx, pconn, udpAddr, tlsConfig, quicConfig) finished := trace.TimeNow() err = MaybeNewErrWrapper(ClassifyQUICHandshakeError, QUICHandshakeOperation, err) trace.OnQUICHandshakeDone(started, address, qconn, tlsConfig, err, finished) @@ -173,15 +172,15 @@ func (d *quicDialerQUICGo) DialContext(ctx context.Context, return newQUICConnectionOwnsConn(qconn, pconn), nil } -func (d *quicDialerQUICGo) dialEarlyContext(ctx context.Context, - pconn net.PacketConn, remoteAddr net.Addr, address string, +func (d *quicDialerQUICGo) dialEarly(ctx context.Context, + pconn net.PacketConn, remoteAddr net.Addr, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { - if d.mockDialEarlyContext != nil { - return d.mockDialEarlyContext( - ctx, pconn, remoteAddr, address, tlsConfig, quicConfig) + if d.mockDialEarly != nil { + return d.mockDialEarly( + ctx, pconn, remoteAddr, tlsConfig, quicConfig) } - return quic.DialEarlyContext( - ctx, pconn, remoteAddr, address, tlsConfig, quicConfig) + return quic.DialEarly( + ctx, pconn, remoteAddr, tlsConfig, quicConfig) } // maybeApplyTLSDefaults ensures that we're using our certificate pool, if @@ -225,7 +224,7 @@ func (d *quicDialerHandshakeCompleter) DialContext( return nil, err } select { - case <-conn.HandshakeComplete().Done(): + case <-conn.HandshakeComplete(): return conn, nil case <-ctx.Done(): conn.CloseWithError(0, "") // we own the conn @@ -399,17 +398,17 @@ func (s *quicDialerSingleUse) CloseIdleConnections() { // nothing to do } -// quicListenerErrWrapper is a QUICListener that wraps errors. -type quicListenerErrWrapper struct { - // QUICListener is the underlying listener. - QUICListener model.QUICListener +// udpListenerErrWrapper is a UDPListener that wraps errors. +type udpListenerErrWrapper struct { + // UDPListener is the underlying listener. + UDPListener model.UDPListener } -var _ model.QUICListener = &quicListenerErrWrapper{} +var _ model.UDPListener = &udpListenerErrWrapper{} -// Listen implements QUICListener.Listen. -func (qls *quicListenerErrWrapper) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { - pconn, err := qls.QUICListener.Listen(addr) +// Listen implements UDPListener.Listen. +func (qls *udpListenerErrWrapper) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { + pconn, err := qls.UDPListener.Listen(addr) if err != nil { return nil, NewErrWrapper(ClassifyGenericError, QUICListenOperation, err) } diff --git a/internal/netxlite/quic_test.go b/internal/netxlite/quic_test.go index 8097dd67e8..33ba2d9e5d 100644 --- a/internal/netxlite/quic_test.go +++ b/internal/netxlite/quic_test.go @@ -19,10 +19,10 @@ import ( "github.com/quic-go/quic-go" ) -func TestNewQUICListener(t *testing.T) { - ql := NewQUICListener() - qew := ql.(*quicListenerErrWrapper) - _ = qew.QUICListener.(*quicListenerStdlib) +func TestNewUDPListener(t *testing.T) { + ql := NewUDPListener() + qew := ql.(*udpListenerErrWrapper) + _ = qew.UDPListener.(*udpListenerStdlib) } type extensionQUICDialerFirst struct { @@ -48,7 +48,7 @@ func (*quicDialerWrapperSecond) WrapQUICDialer(qd model.QUICDialer) model.QUICDi } func TestNewQUICDialer(t *testing.T) { - ql := NewQUICListener() + ql := NewUDPListener() extensions := []model.QUICDialerWrapper{ &quicDialerWrapperFirst{}, nil, // explicitly test for this documented case @@ -72,7 +72,7 @@ func TestNewQUICDialer(t *testing.T) { errWrapper := ext1.QUICDialer.(*quicDialerErrWrapper) handshakeCompleter := errWrapper.QUICDialer.(*quicDialerHandshakeCompleter) base := handshakeCompleter.Dialer.(*quicDialerQUICGo) - if base.QUICListener != ql { + if base.UDPListener != ql { t.Fatal("invalid quic listener") } } @@ -132,7 +132,7 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "www.google.com", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, + UDPListener: &udpListenerStdlib{}, } defer systemdialer.CloseIdleConnections() // just to see it running ctx := context.Background() @@ -151,7 +151,7 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "www.google.com", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, + UDPListener: &udpListenerStdlib{}, } ctx := context.Background() qconn, err := systemdialer.DialContext( @@ -169,7 +169,7 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "www.google.com", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, + UDPListener: &udpListenerStdlib{}, } ctx := context.Background() qconn, err := systemdialer.DialContext( @@ -188,7 +188,7 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "www.google.com", } systemdialer := quicDialerQUICGo{ - QUICListener: &mocks.QUICListener{ + UDPListener: &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return nil, expected }, @@ -210,7 +210,7 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "dns.google", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, + UDPListener: &udpListenerStdlib{}, } ctx, cancel := context.WithCancel(context.Background()) cancel() // fail immediately @@ -231,9 +231,9 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "dns.google", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, - mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn, - remoteAddr net.Addr, host string, tlsConfig *tls.Config, + UDPListener: &udpListenerStdlib{}, + mockDialEarly: func(ctx context.Context, pconn net.PacketConn, + remoteAddr net.Addr, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { gotTLSConfig = tlsConfig return nil, expected @@ -272,9 +272,9 @@ func TestQUICDialerQUICGo(t *testing.T) { ServerName: "dns.google", } systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, - mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn, - remoteAddr net.Addr, host string, tlsConfig *tls.Config, + UDPListener: &udpListenerStdlib{}, + mockDialEarly: func(ctx context.Context, pconn net.PacketConn, + remoteAddr net.Addr, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { gotTLSConfig = tlsConfig return nil, expected @@ -312,9 +312,9 @@ func TestQUICDialerQUICGo(t *testing.T) { } fakeconn := &mocks.QUICEarlyConnection{} systemdialer := quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, - mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn, - remoteAddr net.Addr, host string, tlsConfig *tls.Config, + UDPListener: &udpListenerStdlib{}, + mockDialEarly: func(ctx context.Context, pconn net.PacketConn, + remoteAddr net.Addr, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { return fakeconn, nil }, @@ -346,7 +346,7 @@ func TestQUICDialerWithCustomUnderlyingNetwork(t *testing.T) { }, } systemdialer := &quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{provider: &MaybeCustomUnderlyingNetwork{proxy}}, + UDPListener: &udpListenerStdlib{provider: &MaybeCustomUnderlyingNetwork{proxy}}, } qconn, err := systemdialer.DialContext(ctx, "8.8.8.8:443", tlsConf, qConf) if qconn != nil { @@ -376,9 +376,9 @@ func TestQUICDialerWithCustomUnderlyingNetwork(t *testing.T) { expected := errors.New("mocked") var gotTLSConfig *tls.Config systemdialer := &quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, - mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn, remoteAddr net.Addr, - host string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { + UDPListener: &udpListenerStdlib{}, + mockDialEarly: func(ctx context.Context, pconn net.PacketConn, remoteAddr net.Addr, + tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) { gotTLSConfig = tlsConfig return nil, expected }, @@ -428,9 +428,9 @@ func TestQUICDialerHandshakeCompleter(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) var called bool expected := &mocks.QUICEarlyConnection{ - MockHandshakeComplete: func() context.Context { + MockHandshakeComplete: func() <-chan struct{} { cancel() - return handshakeCtx + return handshakeCtx.Done() }, MockCloseWithError: func(code quic.ApplicationErrorCode, reason string) error { called = true @@ -461,9 +461,9 @@ func TestQUICDialerHandshakeCompleter(t *testing.T) { handshakeCtx, handshakeCancel := context.WithCancel(context.Background()) defer handshakeCancel() expected := &mocks.QUICEarlyConnection{ - MockHandshakeComplete: func() context.Context { + MockHandshakeComplete: func() <-chan struct{} { handshakeCancel() - return handshakeCtx + return handshakeCtx.Done() }, } d := &quicDialerHandshakeCompleter{ @@ -595,7 +595,7 @@ func TestQUICDialerResolver(t *testing.T) { dialer := &quicDialerResolver{ Resolver: NewStdlibResolver(log.Log), Dialer: &quicDialerQUICGo{ - QUICListener: &quicListenerStdlib{}, + UDPListener: &udpListenerStdlib{}, }} qconn, err := dialer.DialContext( context.Background(), "8.8.4.4:x", @@ -794,12 +794,12 @@ func TestNewSingleUseQUICDialer(t *testing.T) { } } -func TestQUICListenerErrWrapper(t *testing.T) { +func TestUDPListenerErrWrapper(t *testing.T) { t.Run("Listen", func(t *testing.T) { t.Run("on success", func(t *testing.T) { expectedConn := &mocks.UDPLikeConn{} - ql := &quicListenerErrWrapper{ - QUICListener: &mocks.QUICListener{ + ql := &udpListenerErrWrapper{ + UDPListener: &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return expectedConn, nil }, @@ -817,8 +817,8 @@ func TestQUICListenerErrWrapper(t *testing.T) { t.Run("on failure", func(t *testing.T) { expectedErr := io.EOF - ql := &quicListenerErrWrapper{ - QUICListener: &mocks.QUICListener{ + ql := &udpListenerErrWrapper{ + UDPListener: &mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return nil, expectedErr }, diff --git a/internal/oohelperd/handler.go b/internal/oohelperd/handler.go index 1bc6ad27ed..30ff5a87d0 100644 --- a/internal/oohelperd/handler.go +++ b/internal/oohelperd/handler.go @@ -90,7 +90,7 @@ func NewHandler() *Handler { }, NewQUICDialer: func(logger model.Logger) model.QUICDialer { return netxlite.NewQUICDialerWithoutResolver( - netxlite.NewQUICListener(), + netxlite.NewUDPListener(), logger, ) }, diff --git a/internal/tracex/quic.go b/internal/tracex/quic.go index faf684ac79..0d492685e7 100644 --- a/internal/tracex/quic.go +++ b/internal/tracex/quic.go @@ -93,36 +93,36 @@ func (h *QUICDialerSaver) CloseIdleConnections() { // quicConnectionState returns the ConnectionState of a QUIC Session. func quicConnectionState(sess quic.EarlyConnection) tls.ConnectionState { - return sess.ConnectionState().TLS.ConnectionState + return sess.ConnectionState().TLS } -// QUICListenerSaver is a QUICListener that also implements saving events. -type QUICListenerSaver struct { - // QUICListener is the underlying QUICListener. - QUICListener model.QUICListener +// UDPListenerSaver is a UDPListener that also implements saving events. +type UDPListenerSaver struct { + // UDPListener is the underlying UDPListener. + UDPListener model.UDPListener // Saver is the underlying Saver. Saver *Saver } -// WrapQUICListener wraps a model.QUICDialer with a QUICListenerSaver that will +// WrapUDPListener wraps a model.UDPDialer with a UDPListenerSaver that will // save the QUIC I/O packet conn events into this Saver. // // When this function is invoked on a nil Saver, it will directly return -// the original QUICListener without any wrapping. -func (s *Saver) WrapQUICListener(ql model.QUICListener) model.QUICListener { +// the original UDPListener without any wrapping. +func (s *Saver) WrapUDPListener(ql model.UDPListener) model.UDPListener { if s == nil { return ql } - return &QUICListenerSaver{ - QUICListener: ql, - Saver: s, + return &UDPListenerSaver{ + UDPListener: ql, + Saver: s, } } -// Listen implements QUICListener.Listen. -func (qls *QUICListenerSaver) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { - pconn, err := qls.QUICListener.Listen(addr) +// Listen implements UDPListener.Listen. +func (qls *UDPListenerSaver) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { + pconn, err := qls.UDPListener.Listen(addr) if err != nil { return nil, err } @@ -184,5 +184,5 @@ func (c *quicPacketConnWrapper) safeAddrString(addr net.Addr) (out string) { } var _ model.QUICDialer = &QUICDialerSaver{} -var _ model.QUICListener = &QUICListenerSaver{} +var _ model.UDPListener = &UDPListenerSaver{} var _ model.UDPLikeConn = &quicPacketConnWrapper{} diff --git a/internal/tracex/quic_test.go b/internal/tracex/quic_test.go index 7afe85d15a..7530b04ef7 100644 --- a/internal/tracex/quic_test.go +++ b/internal/tracex/quic_test.go @@ -81,7 +81,7 @@ func TestQUICDialerSaver(t *testing.T) { returnedConn := &mocks.QUICEarlyConnection{ MockConnectionState: func() quic.ConnectionState { cs := quic.ConnectionState{} - cs.TLS.ConnectionState.CipherSuite = tls.TLS_RSA_WITH_RC4_128_SHA + cs.TLS.CipherSuite = tls.TLS_RSA_WITH_RC4_128_SHA cs.TLS.NegotiatedProtocol = "h3" cs.TLS.PeerCertificates = []*x509.Certificate{{ Raw: []byte{1, 2, 3, 4}, @@ -177,19 +177,19 @@ func TestQUICDialerSaver(t *testing.T) { }) } -func TestWrapQUICListener(t *testing.T) { +func TestWrapUDPListener(t *testing.T) { var saver *Saver - ql := &mocks.QUICListener{} - if saver.WrapQUICListener(ql) != ql { + ql := &mocks.UDPListener{} + if saver.WrapUDPListener(ql) != ql { t.Fatal("unexpected result") } } -func TestQUICListenerSaver(t *testing.T) { +func TestUDPListenerSaver(t *testing.T) { t.Run("on failure", func(t *testing.T) { expected := errors.New("mocked error") saver := &Saver{} - qls := saver.WrapQUICListener(&mocks.QUICListener{ + qls := saver.WrapUDPListener(&mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return nil, expected }, @@ -210,7 +210,7 @@ func TestQUICListenerSaver(t *testing.T) { t.Run("on success", func(t *testing.T) { saver := &Saver{} returnedConn := &mocks.UDPLikeConn{} - qls := saver.WrapQUICListener(&mocks.QUICListener{ + qls := saver.WrapUDPListener(&mocks.UDPListener{ MockListen: func(addr *net.UDPAddr) (model.UDPLikeConn, error) { return returnedConn, nil }, diff --git a/internal/tutorial/netxlite/chapter04/README.md b/internal/tutorial/netxlite/chapter04/README.md index 7cc4c74c73..4cd709b94b 100644 --- a/internal/tutorial/netxlite/chapter04/README.md +++ b/internal/tutorial/netxlite/chapter04/README.md @@ -91,7 +91,7 @@ in the next two chapters.) ```Go func dialQUIC(ctx context.Context, address string, config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) qconn, err := d.DialContext(ctx, address, config, &quic.Config{}) if err != nil { diff --git a/internal/tutorial/netxlite/chapter04/main.go b/internal/tutorial/netxlite/chapter04/main.go index 4ba85bf58e..d1d649af77 100644 --- a/internal/tutorial/netxlite/chapter04/main.go +++ b/internal/tutorial/netxlite/chapter04/main.go @@ -92,7 +92,7 @@ func main() { // ```Go func dialQUIC(ctx context.Context, address string, config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) qconn, err := d.DialContext(ctx, address, config, &quic.Config{}) if err != nil { @@ -105,7 +105,7 @@ func dialQUIC(ctx context.Context, address string, // we returned in the previous chapters. // // ```Go - return qconn, qconn.ConnectionState().TLS.ConnectionState, nil + return qconn, qconn.ConnectionState().TLS, nil } // ``` diff --git a/internal/tutorial/netxlite/chapter08/README.md b/internal/tutorial/netxlite/chapter08/README.md index 77aa77ec01..027898cdd2 100644 --- a/internal/tutorial/netxlite/chapter08/README.md +++ b/internal/tutorial/netxlite/chapter08/README.md @@ -104,7 +104,7 @@ exactly like what we've seen in chapter04. func dialQUIC(ctx context.Context, address string, config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) qconn, err := d.DialContext(ctx, address, config, &quic.Config{}) if err != nil { diff --git a/internal/tutorial/netxlite/chapter08/main.go b/internal/tutorial/netxlite/chapter08/main.go index efc582f1b0..d7cc0886e8 100644 --- a/internal/tutorial/netxlite/chapter08/main.go +++ b/internal/tutorial/netxlite/chapter08/main.go @@ -105,13 +105,13 @@ func main() { func dialQUIC(ctx context.Context, address string, config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) { - ql := netxlite.NewQUICListener() + ql := netxlite.NewUDPListener() d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log) qconn, err := d.DialContext(ctx, address, config, &quic.Config{}) if err != nil { return nil, tls.ConnectionState{}, err } - return qconn, qconn.ConnectionState().TLS.ConnectionState, nil + return qconn, qconn.ConnectionState().TLS, nil } func fatal(err error) {