* quic-go upgrade: replaced Session/EarlySession with Connection/EarlyConnection

* quic-go upgrade: added context to RoundTripper.Dial

* quic-go upgrade: made corresponding changes to tutorial

* quic-go upgrade: changed sess variable instances to qconn

* quic-go upgrade: made corresponding changes to tutorial

* cleanup: remove unnecessary comments

Those comments made sense in terms of illustrating the changes
but they're going to be less useful once we merge.

* fix(go.mod): apparently we needed `go1.18.1 mod tidy`

VSCode just warned me about this. It seems fine to apply this
change as part of the pull request at hand.

* cleanup(netxlite): http3dialer can be removed

We used to use http3dialer to glue a QUIC dialer, which had a
context as its first argument, to the Dial function used by the
HTTP3 transport, which did not have a context as its first
argument.

Now that HTTP3 transport has a Dial function taking a context as
its first argument, we don't need http3dialer
anymore, since we can use the QUIC dialer directly.

Cc: @DecFox

* Revert "cleanup(netxlite): http3dialer can be removed"

This reverts commit c62244c620cee5fadcc2ca89d8228c8db0b96add
to investigate the build failure mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* chore(netx): show that test was already broken

We didn't see the breakage before because we were not using
the created transport, but the issue of using a nil dialer was
already present before, we just didn't see it.

Now we understand why removing the http3transport in
c62244c620cee5fadcc2ca89d8228c8db0b96add did cause the
breakage mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* fix(netx): convert broken integration test to working unit test

There's no point in using the network here. Add a fake dialer that
breaks and ensure we're getting the expected error.

We've now improved upon the original test because the original test was
not doing anything while now we're testing whether we get back a QUIC
dialer that _can be used_.

After this commit, I can then readd the cleanup commit
c62244c620cee5fadcc2ca89d8228c8db0b96add and it won't be
broken anymore (at least, this is what I expected to happen).

* Revert "Revert "cleanup(netxlite): http3dialer can be removed""

This reverts commit 0e254bfc6ba3bfd65365ce3d8de2c8ec51b925ff
because now we should have fixed the broken test.

Co-authored-by: decfox <decfox>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
DecFox
2022-05-06 15:54:03 +05:30
committed by GitHub
parent a72cc7151c
commit 5d2afaade4
27 changed files with 285 additions and 294 deletions
+23 -23
View File
@@ -25,7 +25,7 @@ func (ql *QUICListener) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) {
type QUICDialer struct {
// MockDialContext allows mocking DialContext.
MockDialContext func(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error)
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error)
// MockCloseIdleConnections allows mocking CloseIdleConnections.
MockCloseIdleConnections func()
@@ -33,7 +33,7 @@ type QUICDialer struct {
// DialContext calls MockDialContext.
func (qcd *QUICDialer) DialContext(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return qcd.MockDialContext(ctx, network, address, tlsConfig, quicConfig)
}
@@ -42,8 +42,8 @@ func (qcd *QUICDialer) CloseIdleConnections() {
qcd.MockCloseIdleConnections()
}
// QUICEarlySession is a mockable quic.EarlySession.
type QUICEarlySession struct {
// QUICEarlyConnection is a mockable quic.EarlyConnection.
type QUICEarlyConnection struct {
MockAcceptStream func(context.Context) (quic.Stream, error)
MockAcceptUniStream func(context.Context) (quic.ReceiveStream, error)
MockOpenStream func() (quic.Stream, error)
@@ -56,86 +56,86 @@ type QUICEarlySession struct {
MockContext func() context.Context
MockConnectionState func() quic.ConnectionState
MockHandshakeComplete func() context.Context
MockNextSession func() quic.Session
MockNextConnection func() quic.Connection
MockSendMessage func(b []byte) error
MockReceiveMessage func() ([]byte, error)
}
var _ quic.EarlySession = &QUICEarlySession{}
var _ quic.EarlyConnection = &QUICEarlyConnection{}
// AcceptStream calls MockAcceptStream.
func (s *QUICEarlySession) AcceptStream(ctx context.Context) (quic.Stream, error) {
func (s *QUICEarlyConnection) AcceptStream(ctx context.Context) (quic.Stream, error) {
return s.MockAcceptStream(ctx)
}
// AcceptUniStream calls MockAcceptUniStream.
func (s *QUICEarlySession) AcceptUniStream(ctx context.Context) (quic.ReceiveStream, error) {
func (s *QUICEarlyConnection) AcceptUniStream(ctx context.Context) (quic.ReceiveStream, error) {
return s.MockAcceptUniStream(ctx)
}
// OpenStream calls MockOpenStream.
func (s *QUICEarlySession) OpenStream() (quic.Stream, error) {
func (s *QUICEarlyConnection) OpenStream() (quic.Stream, error) {
return s.MockOpenStream()
}
// OpenStreamSync calls MockOpenStreamSync.
func (s *QUICEarlySession) OpenStreamSync(ctx context.Context) (quic.Stream, error) {
func (s *QUICEarlyConnection) OpenStreamSync(ctx context.Context) (quic.Stream, error) {
return s.MockOpenStreamSync(ctx)
}
// OpenUniStream calls MockOpenUniStream.
func (s *QUICEarlySession) OpenUniStream() (quic.SendStream, error) {
func (s *QUICEarlyConnection) OpenUniStream() (quic.SendStream, error) {
return s.MockOpenUniStream()
}
// OpenUniStreamSync calls MockOpenUniStreamSync.
func (s *QUICEarlySession) OpenUniStreamSync(ctx context.Context) (quic.SendStream, error) {
func (s *QUICEarlyConnection) OpenUniStreamSync(ctx context.Context) (quic.SendStream, error) {
return s.MockOpenUniStreamSync(ctx)
}
// LocalAddr class MockLocalAddr.
func (c *QUICEarlySession) LocalAddr() net.Addr {
func (c *QUICEarlyConnection) LocalAddr() net.Addr {
return c.MockLocalAddr()
}
// RemoteAddr calls MockRemoteAddr.
func (c *QUICEarlySession) RemoteAddr() net.Addr {
func (c *QUICEarlyConnection) RemoteAddr() net.Addr {
return c.MockRemoteAddr()
}
// CloseWithError calls MockCloseWithError.
func (c *QUICEarlySession) CloseWithError(
func (c *QUICEarlyConnection) CloseWithError(
code quic.ApplicationErrorCode, reason string) error {
return c.MockCloseWithError(code, reason)
}
// Context calls MockContext.
func (s *QUICEarlySession) Context() context.Context {
func (s *QUICEarlyConnection) Context() context.Context {
return s.MockContext()
}
// ConnectionState calls MockConnectionState.
func (s *QUICEarlySession) ConnectionState() quic.ConnectionState {
func (s *QUICEarlyConnection) ConnectionState() quic.ConnectionState {
return s.MockConnectionState()
}
// HandshakeComplete calls MockHandshakeComplete.
func (s *QUICEarlySession) HandshakeComplete() context.Context {
func (s *QUICEarlyConnection) HandshakeComplete() context.Context {
return s.MockHandshakeComplete()
}
// NextSession calls MockNextSession.
func (s *QUICEarlySession) NextSession() quic.Session {
return s.MockNextSession()
// NextConnection calls MockNextConnection.
func (s *QUICEarlyConnection) NextConnection() quic.Connection {
return s.MockNextConnection()
}
// SendMessage calls MockSendMessage.
func (s *QUICEarlySession) SendMessage(b []byte) error {
func (s *QUICEarlyConnection) SendMessage(b []byte) error {
return s.MockSendMessage(b)
}
// ReceiveMessage calls MockReceiveMessage.
func (s *QUICEarlySession) ReceiveMessage() ([]byte, error) {
func (s *QUICEarlyConnection) ReceiveMessage() ([]byte, error) {
return s.MockReceiveMessage()
}
+38 -38
View File
@@ -37,19 +37,19 @@ func TestQUICDialer(t *testing.T) {
t.Run("DialContext", func(t *testing.T) {
expected := errors.New("mocked error")
qcd := &QUICDialer{
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return nil, expected
},
}
ctx := context.Background()
tlsConfig := &tls.Config{}
quicConfig := &quic.Config{}
sess, err := qcd.DialContext(ctx, "udp", "dns.google:443", tlsConfig, quicConfig)
qconn, err := qcd.DialContext(ctx, "udp", "dns.google:443", tlsConfig, quicConfig)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
if sess != nil {
t.Fatal("expected nil session")
if qconn != nil {
t.Fatal("expected nil connection")
}
})
@@ -67,16 +67,16 @@ func TestQUICDialer(t *testing.T) {
})
}
func TestQUICEarlySession(t *testing.T) {
func TestQUICEarlyConnection(t *testing.T) {
t.Run("AcceptStream", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockAcceptStream: func(ctx context.Context) (quic.Stream, error) {
return nil, expected
},
}
ctx := context.Background()
stream, err := sess.AcceptStream(ctx)
stream, err := qconn.AcceptStream(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -87,13 +87,13 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("AcceptUniStream", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockAcceptUniStream: func(ctx context.Context) (quic.ReceiveStream, error) {
return nil, expected
},
}
ctx := context.Background()
stream, err := sess.AcceptUniStream(ctx)
stream, err := qconn.AcceptUniStream(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -104,12 +104,12 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("OpenStream", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockOpenStream: func() (quic.Stream, error) {
return nil, expected
},
}
stream, err := sess.OpenStream()
stream, err := qconn.OpenStream()
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -120,13 +120,13 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("OpenStreamSync", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockOpenStreamSync: func(ctx context.Context) (quic.Stream, error) {
return nil, expected
},
}
ctx := context.Background()
stream, err := sess.OpenStreamSync(ctx)
stream, err := qconn.OpenStreamSync(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -137,12 +137,12 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("OpenUniStream", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockOpenUniStream: func() (quic.SendStream, error) {
return nil, expected
},
}
stream, err := sess.OpenUniStream()
stream, err := qconn.OpenUniStream()
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -153,13 +153,13 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("OpenUniStreamSync", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockOpenUniStreamSync: func(ctx context.Context) (quic.SendStream, error) {
return nil, expected
},
}
ctx := context.Background()
stream, err := sess.OpenUniStreamSync(ctx)
stream, err := qconn.OpenUniStreamSync(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -169,24 +169,24 @@ func TestQUICEarlySession(t *testing.T) {
})
t.Run("LocalAddr", func(t *testing.T) {
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockLocalAddr: func() net.Addr {
return &net.UDPAddr{}
},
}
addr := sess.LocalAddr()
addr := qconn.LocalAddr()
if !reflect.ValueOf(addr).Elem().IsZero() {
t.Fatal("expected a zero address here")
}
})
t.Run("RemoteAddr", func(t *testing.T) {
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockRemoteAddr: func() net.Addr {
return &net.UDPAddr{}
},
}
addr := sess.RemoteAddr()
addr := qconn.RemoteAddr()
if !reflect.ValueOf(addr).Elem().IsZero() {
t.Fatal("expected a zero address here")
}
@@ -194,13 +194,13 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("CloseWithError", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockCloseWithError: func(
code quic.ApplicationErrorCode, reason string) error {
return expected
},
}
err := sess.CloseWithError(0, "")
err := qconn.CloseWithError(0, "")
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -208,12 +208,12 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("Context", func(t *testing.T) {
ctx := context.Background()
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockContext: func() context.Context {
return ctx
},
}
out := sess.Context()
out := qconn.Context()
if !reflect.DeepEqual(ctx, out) {
t.Fatal("not the context we expected")
}
@@ -221,12 +221,12 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("ConnectionState", func(t *testing.T) {
state := quic.ConnectionState{SupportsDatagrams: true}
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockConnectionState: func() quic.ConnectionState {
return state
},
}
out := sess.ConnectionState()
out := qconn.ConnectionState()
if !reflect.DeepEqual(state, out) {
t.Fatal("not the context we expected")
}
@@ -234,25 +234,25 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("HandshakeComplete", func(t *testing.T) {
ctx := context.Background()
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockHandshakeComplete: func() context.Context {
return ctx
},
}
out := sess.HandshakeComplete()
out := qconn.HandshakeComplete()
if !reflect.DeepEqual(ctx, out) {
t.Fatal("not the context we expected")
}
})
t.Run("NextSession", func(t *testing.T) {
next := &QUICEarlySession{}
sess := &QUICEarlySession{
MockNextSession: func() quic.Session {
t.Run("NextConnection", func(t *testing.T) {
next := &QUICEarlyConnection{}
qconn := &QUICEarlyConnection{
MockNextConnection: func() quic.Connection {
return next
},
}
out := sess.NextSession()
out := qconn.NextConnection()
if !reflect.DeepEqual(next, out) {
t.Fatal("not the context we expected")
}
@@ -260,13 +260,13 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("SendMessage", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockSendMessage: func(b []byte) error {
return expected
},
}
b := make([]byte, 17)
err := sess.SendMessage(b)
err := qconn.SendMessage(b)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
@@ -274,12 +274,12 @@ func TestQUICEarlySession(t *testing.T) {
t.Run("ReceiveMessage", func(t *testing.T) {
expected := errors.New("mocked error")
sess := &QUICEarlySession{
qconn := &QUICEarlyConnection{
MockReceiveMessage: func() ([]byte, error) {
return nil, expected
},
}
b, err := sess.ReceiveMessage()
b, err := qconn.ReceiveMessage()
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
+1 -1
View File
@@ -152,7 +152,7 @@ type QUICDialer interface {
//
// Typically, you want to pass `&quic.Config{}` as quicConfig.
DialContext(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error)
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error)
// CloseIdleConnections closes idle connections, if any.
CloseIdleConnections()