fix(oohelperd): reduce errors to what the old TH would emit (#543)
Reducing the errors is not done in a perfect way. We have documented the most striking differences inside https://github.com/ooni/probe/issues/1707#issuecomment-942283746 and some attempts to improve the situation further inside https://github.com/ooni/probe/issues/1707#issuecomment-942341255. A better strategy for the future would be to introduce more specific timeout errors, such as dns_timeout_error, etc. More testing may be needed to further validate and compare the old and the new TH, but this requires Jafar improvements to more precisely simulate more complex censorship.
This commit is contained in:
parent
299834174a
commit
4b8cae692b
6 changed files with 315 additions and 8 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) {
|
|||
if err != nil {
|
||||
config.Out <- CtrlHTTPResponse{ // fix: emit -1 like the old test helper does
|
||||
BodyLength: -1,
|
||||
Failure: newfailure(err),
|
||||
Failure: httpMapFailure(err),
|
||||
StatusCode: -1,
|
||||
Headers: map[string]string{},
|
||||
}
|
||||
|
|
@ -52,7 +53,7 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) {
|
|||
if err != nil {
|
||||
config.Out <- CtrlHTTPResponse{ // fix: emit -1 like old test helper does
|
||||
BodyLength: -1,
|
||||
Failure: newfailure(err),
|
||||
Failure: httpMapFailure(err),
|
||||
StatusCode: -1,
|
||||
Headers: map[string]string{},
|
||||
}
|
||||
|
|
@ -67,9 +68,56 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) {
|
|||
data, err := netxlite.ReadAllContext(ctx, reader)
|
||||
config.Out <- CtrlHTTPResponse{
|
||||
BodyLength: int64(len(data)),
|
||||
Failure: newfailure(err),
|
||||
Failure: httpMapFailure(err),
|
||||
StatusCode: int64(resp.StatusCode),
|
||||
Headers: headers,
|
||||
Title: webconnectivity.GetTitle(string(data)),
|
||||
}
|
||||
}
|
||||
|
||||
// httpMapFailure attempts to map netxlite failures to the strings
|
||||
// used by the original OONI test helper.
|
||||
//
|
||||
// See https://github.com/ooni/backend/blob/6ec4fda5b18/oonib/testhelpers/http_helpers.py#L361
|
||||
func httpMapFailure(err error) *string {
|
||||
failure := newfailure(err)
|
||||
failedOperation := archival.NewFailedOperation(err)
|
||||
switch failure {
|
||||
case nil:
|
||||
return nil
|
||||
default:
|
||||
switch *failure {
|
||||
case netxlite.FailureDNSNXDOMAINError,
|
||||
netxlite.FailureDNSNoAnswer,
|
||||
netxlite.FailureDNSNonRecoverableFailure,
|
||||
netxlite.FailureDNSRefusedError,
|
||||
netxlite.FailureDNSServerMisbehaving,
|
||||
netxlite.FailureDNSTemporaryFailure:
|
||||
// Strangely the HTTP code uses the more broad
|
||||
// dns_lookup_error and does not check for
|
||||
// the NXDOMAIN-equivalent-error dns_name_error
|
||||
s := "dns_lookup_error"
|
||||
return &s
|
||||
case netxlite.FailureGenericTimeoutError:
|
||||
// The old TH would return "dns_lookup_error" when
|
||||
// there is a timeout error during the DNS phase of HTTP.
|
||||
switch failedOperation {
|
||||
case nil:
|
||||
// nothing
|
||||
default:
|
||||
switch *failedOperation {
|
||||
case netxlite.ResolveOperation:
|
||||
s := "dns_lookup_error"
|
||||
return &s
|
||||
}
|
||||
}
|
||||
return failure // already using the same name
|
||||
case netxlite.FailureConnectionRefused:
|
||||
s := "connection_refused_error"
|
||||
return &s
|
||||
default:
|
||||
s := "unknown_error"
|
||||
return &s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue