refactor: move ErrorWrapperQUICDialer to errorsx (#420)
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.
This commit is contained in:
parent
5c52d99d57
commit
ec350cba1a
6 changed files with 132 additions and 116 deletions
38
internal/errorsx/quic.go
Normal file
38
internal/errorsx/quic.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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
|
||||
}
|
||||
Loading…
Reference in a new issue