Skip to content

Commit

Permalink
use the new HTTP/3 client API
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 13, 2024
1 parent d7d7865 commit d5be7e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
27 changes: 12 additions & 15 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type Client struct {
// QUICConfig is the QUIC config used when dialing the QUIC connection.
QUICConfig *quic.Config

dialOnce sync.Once
dialErr error
conn quic.Connection
rt *http3.SingleDestinationRoundTripper
dialOnce sync.Once
dialErr error
conn quic.Connection
clientConn *http3.ClientConn
}

// DialAddr dials a proxied connection to a target server.
Expand Down Expand Up @@ -104,31 +104,28 @@ func (c *Client) dial(ctx context.Context, expandedTemplate string) (net.PacketC
return
}
c.conn = conn
c.rt = &http3.SingleDestinationRoundTripper{
Connection: conn,
EnableDatagrams: true,
}
tr := &http3.Transport{EnableDatagrams: true}
c.clientConn = tr.NewClientConn(conn)
})
if c.dialErr != nil {
return nil, nil, c.dialErr
}
conn := c.rt.Start()
select {
case <-ctx.Done():
return nil, nil, context.Cause(ctx)
case <-conn.Context().Done():
return nil, nil, context.Cause(conn.Context())
case <-conn.ReceivedSettings():
case <-c.clientConn.Context().Done():
return nil, nil, context.Cause(c.clientConn.Context())
case <-c.clientConn.ReceivedSettings():
}
settings := conn.Settings()
settings := c.clientConn.Settings()
if !settings.EnableExtendedConnect {
return nil, nil, errors.New("masque: server didn't enable Extended CONNECT")
}
if !settings.EnableDatagrams {
return nil, nil, errors.New("masque: server didn't enable Datagrams")
}

rstr, err := c.rt.OpenRequestStream(ctx)
rstr, err := c.clientConn.OpenRequestStream(ctx)
if err != nil {
return nil, nil, fmt.Errorf("masque: failed to open request stream: %w", err)
}
Expand All @@ -149,7 +146,7 @@ func (c *Client) dial(ctx context.Context, expandedTemplate string) (net.PacketC
if rsp.StatusCode < 200 || rsp.StatusCode > 299 {
return nil, rsp, fmt.Errorf("masque: server responded with %d", rsp.StatusCode)
}
return newProxiedConn(rstr, conn.LocalAddr()), rsp, nil
return newProxiedConn(rstr, c.conn.LocalAddr()), rsp, nil
}

// Close closes the connection to the proxy.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/dunglas/httpsfv v1.0.2
github.com/quic-go/quic-go v0.47.0
github.com/quic-go/quic-go v0.47.1-0.20241013030513-771b20876385
github.com/stretchr/testify v1.9.0
github.com/yosida95/uritemplate/v3 v3.0.2
go.uber.org/goleak v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.47.0 h1:yXs3v7r2bm1wmPTYNLKAAJTHMYkPEsfYJmTazXrCZ7Y=
github.com/quic-go/quic-go v0.47.0/go.mod h1:3bCapYsJvXGZcipOHuu7plYtaV6tnF+z7wIFsU0WK9E=
github.com/quic-go/quic-go v0.47.1-0.20241013030513-771b20876385 h1:nRtcAJNKkLp6qaEtrrqvisV8c+qsfpvfZhxlnkgAS6U=
github.com/quic-go/quic-go v0.47.1-0.20241013030513-771b20876385/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit d5be7e1

Please sign in to comment.