fix(netxlite): clearly document quirk and make code robust (#468)
This quirk really saddens me. It's a piece of tech debt we're carrying over from the original netx implementation. We cannot remove it _until_ we have legacy netx code around. The second best thing we can do is to clearly move this code in a place where it's clear it's a quirk and write and use some extra code that makes sure the quirk's assumptions are always met. Sigh. See https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
ba5bae4769
commit
aa77867145
6 changed files with 153 additions and 77 deletions
|
|
@ -2,44 +2,9 @@ package netxlite
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/errorsx"
|
||||
)
|
||||
|
||||
// reduceErrors finds a known error in a list of errors since
|
||||
// it's probably most relevant.
|
||||
//
|
||||
// Deprecation warning
|
||||
//
|
||||
// Albeit still used, this function is now DEPRECATED.
|
||||
//
|
||||
// In perspective, we would like to transition to a scenario where
|
||||
// full dialing is NOT used for measurements and we return a multierror here.
|
||||
func reduceErrors(errorslist []error) error {
|
||||
if len(errorslist) == 0 {
|
||||
return nil
|
||||
}
|
||||
// If we have a known error, let's consider this the real error
|
||||
// since it's probably most relevant. Otherwise let's return the
|
||||
// first considering that (1) local resolvers likely will give
|
||||
// us IPv4 first and (2) also our resolver does that. So, in case
|
||||
// the user has no IPv6 connectivity, an IPv6 error is going to
|
||||
// appear later in the list of errors.
|
||||
for _, err := range errorslist {
|
||||
var wrapper *errorsx.ErrWrapper
|
||||
if errors.As(err, &wrapper) && !strings.HasPrefix(
|
||||
err.Error(), "unknown_failure",
|
||||
) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// TODO(bassosimone): handle this case in a better way
|
||||
return errorslist[0]
|
||||
}
|
||||
|
||||
// These vars export internal names to legacy ooni/probe-cli code.
|
||||
var (
|
||||
DefaultDialer = defaultDialer
|
||||
|
|
|
|||
Loading…
Reference in a new issue