cli: upgrade to lucas-clemente/quic-go@v0.27.0 (#715)
* 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:
@@ -2,7 +2,7 @@
|
||||
# Chapter I: Using QUIC
|
||||
|
||||
In this chapter we will write together a `main.go` file that
|
||||
uses netxlite to establish a new QUIC session with an UDP endpoint.
|
||||
uses netxlite to establish a new QUIC connection with an UDP endpoint.
|
||||
|
||||
Conceptually, this program is very similar to the ones presented
|
||||
in chapters 2 and 3, except that here we use QUIC.
|
||||
@@ -58,7 +58,7 @@ Also, where previously we called `dialTLS` now we call
|
||||
a function with a similar API called `dialQUIC`.
|
||||
|
||||
```
|
||||
sess, state, err := dialQUIC(ctx, *address, config)
|
||||
qconn, state, err := dialQUIC(ctx, *address, config)
|
||||
```
|
||||
|
||||
The rest of the main function is pretty much the same.
|
||||
@@ -67,11 +67,11 @@ The rest of the main function is pretty much the same.
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
log.Infof("Sess type : %T", sess)
|
||||
log.Infof("Connection type : %T", qconn)
|
||||
log.Infof("Cipher suite : %s", netxlite.TLSCipherSuiteString(state.CipherSuite))
|
||||
log.Infof("Negotiated protocol: %s", state.NegotiatedProtocol)
|
||||
log.Infof("TLS version : %s", netxlite.TLSVersionString(state.Version))
|
||||
sess.CloseWithError(0, "")
|
||||
qconn.CloseWithError(0, "")
|
||||
}
|
||||
|
||||
```
|
||||
@@ -90,10 +90,10 @@ in the next two chapters.)
|
||||
|
||||
```Go
|
||||
func dialQUIC(ctx context.Context, address string,
|
||||
config *tls.Config) (quic.EarlySession, tls.ConnectionState, error) {
|
||||
config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) {
|
||||
ql := netxlite.NewQUICListener()
|
||||
d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log)
|
||||
sess, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
qconn, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
if err != nil {
|
||||
return nil, tls.ConnectionState{}, err
|
||||
}
|
||||
@@ -104,7 +104,7 @@ QUIC code to be of the same type of the ConnectionState that
|
||||
we returned in the previous chapters.
|
||||
|
||||
```Go
|
||||
return sess, sess.ConnectionState().TLS.ConnectionState, nil
|
||||
return qconn, qconn.ConnectionState().TLS.ConnectionState, nil
|
||||
}
|
||||
|
||||
```
|
||||
@@ -157,5 +157,5 @@ should give you a TLS error mentioning that the certificate is invalid.
|
||||
|
||||
## Conclusions
|
||||
|
||||
We have seen how to use netxlite to establish a QUIC session
|
||||
We have seen how to use netxlite to establish a QUIC connection
|
||||
with a remote UDP endpoint speaking QUIC.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// # Chapter I: Using QUIC
|
||||
//
|
||||
// In this chapter we will write together a `main.go` file that
|
||||
// uses netxlite to establish a new QUIC session with an UDP endpoint.
|
||||
// uses netxlite to establish a new QUIC connection with an UDP endpoint.
|
||||
//
|
||||
// Conceptually, this program is very similar to the ones presented
|
||||
// in chapters 2 and 3, except that here we use QUIC.
|
||||
@@ -59,7 +59,7 @@ func main() {
|
||||
// a function with a similar API called `dialQUIC`.
|
||||
//
|
||||
// ```
|
||||
sess, state, err := dialQUIC(ctx, *address, config)
|
||||
qconn, state, err := dialQUIC(ctx, *address, config)
|
||||
// ```
|
||||
//
|
||||
// The rest of the main function is pretty much the same.
|
||||
@@ -68,11 +68,11 @@ func main() {
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
log.Infof("Sess type : %T", sess)
|
||||
log.Infof("Connection type : %T", qconn)
|
||||
log.Infof("Cipher suite : %s", netxlite.TLSCipherSuiteString(state.CipherSuite))
|
||||
log.Infof("Negotiated protocol: %s", state.NegotiatedProtocol)
|
||||
log.Infof("TLS version : %s", netxlite.TLSVersionString(state.Version))
|
||||
sess.CloseWithError(0, "")
|
||||
qconn.CloseWithError(0, "")
|
||||
}
|
||||
|
||||
// ```
|
||||
@@ -91,10 +91,10 @@ func main() {
|
||||
//
|
||||
// ```Go
|
||||
func dialQUIC(ctx context.Context, address string,
|
||||
config *tls.Config) (quic.EarlySession, tls.ConnectionState, error) {
|
||||
config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) {
|
||||
ql := netxlite.NewQUICListener()
|
||||
d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log)
|
||||
sess, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
qconn, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
if err != nil {
|
||||
return nil, tls.ConnectionState{}, err
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func dialQUIC(ctx context.Context, address string,
|
||||
// we returned in the previous chapters.
|
||||
//
|
||||
// ```Go
|
||||
return sess, sess.ConnectionState().TLS.ConnectionState, nil
|
||||
return qconn, qconn.ConnectionState().TLS.ConnectionState, nil
|
||||
}
|
||||
|
||||
// ```
|
||||
@@ -158,5 +158,5 @@ func fatal(err error) {
|
||||
//
|
||||
// ## Conclusions
|
||||
//
|
||||
// We have seen how to use netxlite to establish a QUIC session
|
||||
// We have seen how to use netxlite to establish a QUIC connection
|
||||
// with a remote UDP endpoint speaking QUIC.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
# Chapter I: HTTP GET with QUIC sess
|
||||
# Chapter I: HTTP GET with QUIC conn
|
||||
|
||||
In this chapter we will write together a `main.go` file that
|
||||
uses netxlite to establish a QUIC session to a remote endpoint
|
||||
uses netxlite to establish a QUIC connection to a remote endpoint
|
||||
and then fetches a webpage from it using GET.
|
||||
|
||||
This file is basically the same as the one used in chapter04
|
||||
@@ -49,11 +49,11 @@ func main() {
|
||||
NextProtos: []string{"h3"},
|
||||
RootCAs: netxlite.NewDefaultCertPool(),
|
||||
}
|
||||
sess, _, err := dialQUIC(ctx, *address, config)
|
||||
qconn, _, err := dialQUIC(ctx, *address, config)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
log.Infof("Sess type : %T", sess)
|
||||
log.Infof("Connection type : %T", qconn)
|
||||
```
|
||||
|
||||
This is where things diverge. We create an HTTP client
|
||||
@@ -61,13 +61,13 @@ using a transport created with `netxlite.NewHTTP3Transport`.
|
||||
|
||||
This transport will use a "single use" QUIC dialer.
|
||||
What does this mean? Well, we create such a QUICDialer
|
||||
using the session we already established. The first
|
||||
using the connection we already established. The first
|
||||
time the HTTP code dials for QUIC, the QUICDialer will
|
||||
return the session we passed to its constructor
|
||||
return the connection we passed to its constructor
|
||||
immediately. Every subsequent QUIC dial attempt will fail.
|
||||
|
||||
The result is an HTTPTransport suitable for performing
|
||||
a single request using the given QUIC sess.
|
||||
a single request using the given QUIC conn.
|
||||
|
||||
(A similar construct allows to create an HTTPTransport that
|
||||
uses a cleartext TCP connection. In the previous chapter we've
|
||||
@@ -75,7 +75,7 @@ seen how to do the same using TLS conns.)
|
||||
|
||||
```Go
|
||||
clnt := &http.Client{Transport: netxlite.NewHTTP3Transport(
|
||||
log.Log, netxlite.NewSingleUseQUICDialer(sess), &tls.Config{},
|
||||
log.Log, netxlite.NewSingleUseQUICDialer(qconn), &tls.Config{},
|
||||
)}
|
||||
```
|
||||
|
||||
@@ -103,14 +103,14 @@ exactly like what we've seen in chapter04.
|
||||
```Go
|
||||
|
||||
func dialQUIC(ctx context.Context, address string,
|
||||
config *tls.Config) (quic.EarlySession, tls.ConnectionState, error) {
|
||||
config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) {
|
||||
ql := netxlite.NewQUICListener()
|
||||
d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log)
|
||||
sess, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
qconn, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
if err != nil {
|
||||
return nil, tls.ConnectionState{}, err
|
||||
}
|
||||
return sess, sess.ConnectionState().TLS.ConnectionState, nil
|
||||
return qconn, qconn.ConnectionState().TLS.ConnectionState, nil
|
||||
}
|
||||
|
||||
func fatal(err error) {
|
||||
@@ -158,5 +158,5 @@ should give you an error mentioning the certificate is invalid.
|
||||
|
||||
## Conclusions
|
||||
|
||||
We have seen how to establish a QUIC session with a website
|
||||
and then how to GET a webpage using such a session.
|
||||
We have seen how to establish a QUIC connection with a website
|
||||
and then how to GET a webpage using such a connection.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// -=-=- StartHere -=-=-
|
||||
//
|
||||
// # Chapter I: HTTP GET with QUIC sess
|
||||
// # Chapter I: HTTP GET with QUIC conn
|
||||
//
|
||||
// In this chapter we will write together a `main.go` file that
|
||||
// uses netxlite to establish a QUIC session to a remote endpoint
|
||||
// uses netxlite to establish a QUIC connection to a remote endpoint
|
||||
// and then fetches a webpage from it using GET.
|
||||
//
|
||||
// This file is basically the same as the one used in chapter04
|
||||
@@ -50,11 +50,11 @@ func main() {
|
||||
NextProtos: []string{"h3"},
|
||||
RootCAs: netxlite.NewDefaultCertPool(),
|
||||
}
|
||||
sess, _, err := dialQUIC(ctx, *address, config)
|
||||
qconn, _, err := dialQUIC(ctx, *address, config)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
log.Infof("Sess type : %T", sess)
|
||||
log.Infof("Connection type : %T", qconn)
|
||||
// ```
|
||||
//
|
||||
// This is where things diverge. We create an HTTP client
|
||||
@@ -62,13 +62,13 @@ func main() {
|
||||
//
|
||||
// This transport will use a "single use" QUIC dialer.
|
||||
// What does this mean? Well, we create such a QUICDialer
|
||||
// using the session we already established. The first
|
||||
// using the connection we already established. The first
|
||||
// time the HTTP code dials for QUIC, the QUICDialer will
|
||||
// return the session we passed to its constructor
|
||||
// return the connection we passed to its constructor
|
||||
// immediately. Every subsequent QUIC dial attempt will fail.
|
||||
//
|
||||
// The result is an HTTPTransport suitable for performing
|
||||
// a single request using the given QUIC sess.
|
||||
// a single request using the given QUIC conn.
|
||||
//
|
||||
// (A similar construct allows to create an HTTPTransport that
|
||||
// uses a cleartext TCP connection. In the previous chapter we've
|
||||
@@ -76,7 +76,7 @@ func main() {
|
||||
//
|
||||
// ```Go
|
||||
clnt := &http.Client{Transport: netxlite.NewHTTP3Transport(
|
||||
log.Log, netxlite.NewSingleUseQUICDialer(sess), &tls.Config{},
|
||||
log.Log, netxlite.NewSingleUseQUICDialer(qconn), &tls.Config{},
|
||||
)}
|
||||
// ```
|
||||
//
|
||||
@@ -104,14 +104,14 @@ func main() {
|
||||
// ```Go
|
||||
|
||||
func dialQUIC(ctx context.Context, address string,
|
||||
config *tls.Config) (quic.EarlySession, tls.ConnectionState, error) {
|
||||
config *tls.Config) (quic.EarlyConnection, tls.ConnectionState, error) {
|
||||
ql := netxlite.NewQUICListener()
|
||||
d := netxlite.NewQUICDialerWithoutResolver(ql, log.Log)
|
||||
sess, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
qconn, err := d.DialContext(ctx, "udp", address, config, &quic.Config{})
|
||||
if err != nil {
|
||||
return nil, tls.ConnectionState{}, err
|
||||
}
|
||||
return sess, sess.ConnectionState().TLS.ConnectionState, nil
|
||||
return qconn, qconn.ConnectionState().TLS.ConnectionState, nil
|
||||
}
|
||||
|
||||
func fatal(err error) {
|
||||
@@ -159,5 +159,5 @@ func fatal(err error) {
|
||||
//
|
||||
// ## Conclusions
|
||||
//
|
||||
// We have seen how to establish a QUIC session with a website
|
||||
// and then how to GET a webpage using such a session.
|
||||
// We have seen how to establish a QUIC connection with a website
|
||||
// and then how to GET a webpage using such a connection.
|
||||
|
||||
Reference in New Issue
Block a user