ec350cba1a
I needed to add some tests as integration tests due to circular imports, but this is ~fine because we quite likely want many integration tests in the errorsx package anyway. Part of https://github.com/ooni/probe/issues/1505.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package errorsx
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
|
|
"github.com/lucas-clemente/quic-go"
|
|
)
|
|
|
|
// QUICContextDialer is a dialer for QUIC using Context.
|
|
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)
|
|
}
|
|
|
|
// ErrorWrapperQUICDialer is a dialer that performs quic err wrapping
|
|
type ErrorWrapperQUICDialer struct {
|
|
Dialer QUICContextDialer
|
|
}
|
|
|
|
// DialContext implements ContextDialer.DialContext
|
|
func (d *ErrorWrapperQUICDialer) DialContext(
|
|
ctx context.Context, network string, host string,
|
|
tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) {
|
|
sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg)
|
|
err = SafeErrWrapperBuilder{
|
|
Classifier: ClassifyQUICFailure,
|
|
Error: err,
|
|
Operation: QUICHandshakeOperation,
|
|
}.MaybeBuild()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return sess, nil
|
|
}
|