5ebdeb56ca
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: https://github.com/ooni/probe/issues/2158 - [x] if you changed anything related how experiments work and you need to reflect these changes in the ooni/spec repository, please link to the related ooni/spec pull request: https://github.com/ooni/spec/pull/250 ## Description This diff refactors the codebase to reimplement tlsping and tcpping to use the step-by-step measurements style. See docs/design/dd-003-step-by-step.md for more information on the step-by-step measurement style.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package netxlite
|
|
|
|
//
|
|
// Generic DNS transport code.
|
|
//
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
// WrapDNSTransport wraps a DNSTransport to provide error wrapping. This function will
|
|
// apply all the provided wrappers around the default transport wrapping. If any of the
|
|
// wrappers is nil, we just silently and gracefully ignore it.
|
|
func WrapDNSTransport(txp model.DNSTransport,
|
|
wrappers ...model.DNSTransportWrapper) (out model.DNSTransport) {
|
|
out = &dnsTransportErrWrapper{
|
|
DNSTransport: txp,
|
|
}
|
|
for _, wrapper := range wrappers {
|
|
if wrapper == nil {
|
|
continue // skip as documented
|
|
}
|
|
out = wrapper.WrapDNSTransport(out) // compose with user-provided wrappers
|
|
}
|
|
return
|
|
}
|
|
|
|
// dnsTransportErrWrapper wraps DNSTransport to provide error wrapping.
|
|
type dnsTransportErrWrapper struct {
|
|
DNSTransport model.DNSTransport
|
|
}
|
|
|
|
var _ model.DNSTransport = &dnsTransportErrWrapper{}
|
|
|
|
func (t *dnsTransportErrWrapper) RoundTrip(
|
|
ctx context.Context, query model.DNSQuery) (model.DNSResponse, error) {
|
|
resp, err := t.DNSTransport.RoundTrip(ctx, query)
|
|
if err != nil {
|
|
return nil, NewErrWrapper(ClassifyResolverError, DNSRoundTripOperation, err)
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (t *dnsTransportErrWrapper) RequiresPadding() bool {
|
|
return t.DNSTransport.RequiresPadding()
|
|
}
|
|
|
|
func (t *dnsTransportErrWrapper) Network() string {
|
|
return t.DNSTransport.Network()
|
|
}
|
|
|
|
func (t *dnsTransportErrWrapper) Address() string {
|
|
return t.DNSTransport.Address()
|
|
}
|
|
|
|
func (t *dnsTransportErrWrapper) CloseIdleConnections() {
|
|
t.DNSTransport.CloseIdleConnections()
|
|
}
|