feat(netxlite): add CloseIdleConnections to quic dialer (#469)

Like before, do not touch the rest of the tree. Rather create
compatibility types declared as legacy.

We will soon be able to close idle connections for an HTTP3
transport using any kind of resolvers more easily.

See https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-06 20:56:14 +02:00 committed by GitHub
commit 3ba5626b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 209 additions and 21 deletions

View file

@ -2,7 +2,10 @@ package netxlite
import (
"context"
"crypto/tls"
"net"
"github.com/lucas-clemente/quic-go"
)
// These vars export internal names to legacy ooni/probe-cli code.
@ -129,3 +132,39 @@ func (d *DialerLegacyAdapter) CloseIdleConnections() {
ra.CloseIdleConnections()
}
}
// QUICContextDialer is a dialer for QUIC using Context.
//
// This is a LEGACY name. New code should use QUICDialer directly.
//
// Use NewQUICDialerFromContextDialerAdapter if you need to
// adapt an existing QUICContextDialer to a QUICDialer.
type QUICContextDialer interface {
// DialContext establishes a new QUIC session using the given
// network and address. The tlsConfig and the quicConfig arguments
// MUST NOT be nil. Returns either the session or an error.
DialContext(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error)
}
// NewQUICDialerFromContextDialerAdapter creates a new
// QUICDialer from a QUICContextDialer.
func NewQUICDialerFromContextDialerAdapter(d QUICContextDialer) QUICDialer {
return &QUICContextDialerAdapter{d}
}
// QUICContextDialerAdapter adapta a QUICContextDialer to be a QUICDialer.
type QUICContextDialerAdapter struct {
QUICContextDialer
}
type quicContextDialerConnectionsCloser interface {
CloseIdleConnections()
}
// CloseIdleConnections implements QUICDialer.CloseIdleConnections.
func (d *QUICContextDialerAdapter) CloseIdleConnections() {
if o, ok := d.QUICContextDialer.(quicContextDialerConnectionsCloser); ok {
o.CloseIdleConnections()
}
}