Skip to content

Commit

Permalink
client: Add DialEarlyContext and DialAddrEarlyContext API
Browse files Browse the repository at this point in the history
  • Loading branch information
VinozzZ committed Oct 6, 2020
1 parent 93e733a commit 217455f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
33 changes: 31 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,23 @@ func DialAddrEarly(
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
sess, err := dialAddrContext(context.Background(), addr, tlsConf, config, true)
sess, err := DialAddrEarlyContext(context.Background(), addr, tlsConf, config)
if err != nil {
return nil, err
}
utils.Logger.WithPrefix(utils.DefaultLogger, "client").Debugf("Returning early session")
return sess, nil
}

// DialAddrEarly establishes a new 0-RTT QUIC connection to a server using provided context.
// See DialAddrEarly for details
func DialAddrEarlyContext(
ctx context.Context,
addr string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
sess, err := dialAddrContext(ctx, addr, tlsConf, config, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -134,7 +150,20 @@ func DialEarly(
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
return dialContext(context.Background(), pconn, remoteAddr, host, tlsConf, config, true, false)
return DialEarlyContext(context.Background(), pconn, remoteAddr, host, tlsConf, config)
}

// DialEarlyContext establishes a new 0-RTT QUIC connection to a server using a net.PacketConn using the provided context.
// See DialEarly for details.
func DialEarlyContext(
ctx context.Context,
pconn net.PacketConn,
remoteAddr net.Addr,
host string,
tlsConf *tls.Config,
config *Config,
) (EarlySession, error) {
return dialContext(ctx, pconn, remoteAddr, host, tlsConf, config, true, false)
}

// DialContext establishes a new QUIC connection to a server using a net.PacketConn using the provided context.
Expand Down
19 changes: 19 additions & 0 deletions integrationtests/self/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ var _ = Describe("Timeout tests", func() {
Expect(err).To(MatchError(context.DeadlineExceeded))
})

It("returns the context error when the context expires with 0RTT enabled", func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
errChan := make(chan error)
go func() {
_, err := quic.DialAddrEarlyContext(
ctx,
"localhost:12345",
getTLSClientConfig(),
getQuicConfig(nil),
)
errChan <- err
}()
var err error
Eventually(errChan).Should(Receive(&err))
// This is not a net.Error timeout error
Expect(err).To(MatchError(context.DeadlineExceeded))
})

It("returns net.Error timeout errors when an idle timeout occurs", func() {
const idleTimeout = 100 * time.Millisecond

Expand Down

0 comments on commit 217455f

Please sign in to comment.