cleanup: remove ConnID, DialID, TransactionID (#395)
We are not using them anymore. The only nettest still using the legacy netx implementation is tor, for which setting these fields is useless, because it performs each measurement into a separate goroutine. Hence, let us start removing this part of the legacy netx codebase, which is hampering progress in other areas. Occurred to me while doing testing for the recent changes in error mapping (https://github.com/ooni/probe/issues/1505).
This commit is contained in:
@@ -4,9 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/dialid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/transactionid"
|
||||
)
|
||||
|
||||
// EmitterTransport is a RoundTripper that emits events when they occur.
|
||||
@@ -20,8 +18,7 @@ func (txp EmitterTransport) RoundTrip(ctx context.Context, querydata []byte) ([]
|
||||
root.Handler.OnMeasurement(modelx.Measurement{
|
||||
DNSQuery: &modelx.DNSQueryEvent{
|
||||
Data: querydata,
|
||||
DialID: dialid.ContextDialID(ctx),
|
||||
DurationSinceBeginning: time.Now().Sub(root.Beginning),
|
||||
DurationSinceBeginning: time.Since(root.Beginning),
|
||||
},
|
||||
})
|
||||
replydata, err := txp.RoundTripper.RoundTrip(ctx, querydata)
|
||||
@@ -31,8 +28,7 @@ func (txp EmitterTransport) RoundTrip(ctx context.Context, querydata []byte) ([]
|
||||
root.Handler.OnMeasurement(modelx.Measurement{
|
||||
DNSReply: &modelx.DNSReplyEvent{
|
||||
Data: replydata,
|
||||
DialID: dialid.ContextDialID(ctx),
|
||||
DurationSinceBeginning: time.Now().Sub(root.Beginning),
|
||||
DurationSinceBeginning: time.Since(root.Beginning),
|
||||
},
|
||||
})
|
||||
return replydata, nil
|
||||
@@ -56,15 +52,11 @@ func (r EmitterResolver) LookupHost(ctx context.Context, hostname string) ([]str
|
||||
txp := qr.Transport()
|
||||
network, address = txp.Network(), txp.Address()
|
||||
}
|
||||
dialID := dialid.ContextDialID(ctx)
|
||||
txID := transactionid.ContextTransactionID(ctx)
|
||||
root := modelx.ContextMeasurementRootOrDefault(ctx)
|
||||
root.Handler.OnMeasurement(modelx.Measurement{
|
||||
ResolveStart: &modelx.ResolveStartEvent{
|
||||
DialID: dialID,
|
||||
DurationSinceBeginning: time.Now().Sub(root.Beginning),
|
||||
DurationSinceBeginning: time.Since(root.Beginning),
|
||||
Hostname: hostname,
|
||||
TransactionID: txID,
|
||||
TransportAddress: address,
|
||||
TransportNetwork: network,
|
||||
},
|
||||
@@ -73,11 +65,9 @@ func (r EmitterResolver) LookupHost(ctx context.Context, hostname string) ([]str
|
||||
root.Handler.OnMeasurement(modelx.Measurement{
|
||||
ResolveDone: &modelx.ResolveDoneEvent{
|
||||
Addresses: addrs,
|
||||
DialID: dialID,
|
||||
DurationSinceBeginning: time.Now().Sub(root.Beginning),
|
||||
DurationSinceBeginning: time.Since(root.Beginning),
|
||||
Error: err,
|
||||
Hostname: hostname,
|
||||
TransactionID: txID,
|
||||
TransportAddress: address,
|
||||
TransportNetwork: network,
|
||||
},
|
||||
|
||||
@@ -10,16 +10,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/dialid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/transactionid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver"
|
||||
)
|
||||
|
||||
func TestEmitterTransportSuccess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = dialid.WithDialID(ctx)
|
||||
handler := &handlers.SavingHandler{}
|
||||
root := &modelx.MeasurementRoot{
|
||||
Beginning: time.Now(),
|
||||
@@ -48,9 +45,6 @@ func TestEmitterTransportSuccess(t *testing.T) {
|
||||
if !bytes.Equal(events[0].DNSQuery.Data, querydata) {
|
||||
t.Fatal("invalid query data")
|
||||
}
|
||||
if events[0].DNSQuery.DialID == 0 {
|
||||
t.Fatal("invalid query DialID")
|
||||
}
|
||||
if events[0].DNSQuery.DurationSinceBeginning <= 0 {
|
||||
t.Fatal("invalid duration since beginning")
|
||||
}
|
||||
@@ -60,9 +54,6 @@ func TestEmitterTransportSuccess(t *testing.T) {
|
||||
if !bytes.Equal(events[1].DNSReply.Data, replydata) {
|
||||
t.Fatal("missing reply data")
|
||||
}
|
||||
if events[1].DNSReply.DialID != 1 {
|
||||
t.Fatal("invalid query DialID")
|
||||
}
|
||||
if events[1].DNSReply.DurationSinceBeginning <= 0 {
|
||||
t.Fatal("invalid duration since beginning")
|
||||
}
|
||||
@@ -70,7 +61,6 @@ func TestEmitterTransportSuccess(t *testing.T) {
|
||||
|
||||
func TestEmitterTransportFailure(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = dialid.WithDialID(ctx)
|
||||
handler := &handlers.SavingHandler{}
|
||||
root := &modelx.MeasurementRoot{
|
||||
Beginning: time.Now(),
|
||||
@@ -103,9 +93,6 @@ func TestEmitterTransportFailure(t *testing.T) {
|
||||
if !bytes.Equal(events[0].DNSQuery.Data, querydata) {
|
||||
t.Fatal("invalid query data")
|
||||
}
|
||||
if events[0].DNSQuery.DialID == 0 {
|
||||
t.Fatal("invalid query DialID")
|
||||
}
|
||||
if events[0].DNSQuery.DurationSinceBeginning <= 0 {
|
||||
t.Fatal("invalid duration since beginning")
|
||||
}
|
||||
@@ -113,8 +100,6 @@ func TestEmitterTransportFailure(t *testing.T) {
|
||||
|
||||
func TestEmitterResolverFailure(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = dialid.WithDialID(ctx)
|
||||
ctx = transactionid.WithTransactionID(ctx)
|
||||
handler := &handlers.SavingHandler{}
|
||||
root := &modelx.MeasurementRoot{
|
||||
Beginning: time.Now(),
|
||||
@@ -143,18 +128,12 @@ func TestEmitterResolverFailure(t *testing.T) {
|
||||
if events[0].ResolveStart == nil {
|
||||
t.Fatal("missing ResolveStart field")
|
||||
}
|
||||
if events[0].ResolveStart.DialID == 0 {
|
||||
t.Fatal("invalid DialID")
|
||||
}
|
||||
if events[0].ResolveStart.DurationSinceBeginning <= 0 {
|
||||
t.Fatal("invalid duration since beginning")
|
||||
}
|
||||
if events[0].ResolveStart.Hostname != "www.google.com" {
|
||||
t.Fatal("invalid Hostname")
|
||||
}
|
||||
if events[0].ResolveStart.TransactionID == 0 {
|
||||
t.Fatal("invalid TransactionID")
|
||||
}
|
||||
if events[0].ResolveStart.TransportAddress != "https://dns.google.com/" {
|
||||
t.Fatal("invalid TransportAddress")
|
||||
}
|
||||
@@ -164,9 +143,6 @@ func TestEmitterResolverFailure(t *testing.T) {
|
||||
if events[1].ResolveDone == nil {
|
||||
t.Fatal("missing ResolveDone field")
|
||||
}
|
||||
if events[1].ResolveDone.DialID == 0 {
|
||||
t.Fatal("invalid DialID")
|
||||
}
|
||||
if events[1].ResolveDone.DurationSinceBeginning <= 0 {
|
||||
t.Fatal("invalid duration since beginning")
|
||||
}
|
||||
@@ -176,9 +152,6 @@ func TestEmitterResolverFailure(t *testing.T) {
|
||||
if events[1].ResolveDone.Hostname != "www.google.com" {
|
||||
t.Fatal("invalid Hostname")
|
||||
}
|
||||
if events[1].ResolveDone.TransactionID == 0 {
|
||||
t.Fatal("invalid TransactionID")
|
||||
}
|
||||
if events[1].ResolveDone.TransportAddress != "https://dns.google.com/" {
|
||||
t.Fatal("invalid TransportAddress")
|
||||
}
|
||||
@@ -189,8 +162,6 @@ func TestEmitterResolverFailure(t *testing.T) {
|
||||
|
||||
func TestEmitterResolverSuccess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = dialid.WithDialID(ctx)
|
||||
ctx = transactionid.WithTransactionID(ctx)
|
||||
handler := &handlers.SavingHandler{}
|
||||
root := &modelx.MeasurementRoot{
|
||||
Beginning: time.Now(),
|
||||
|
||||
@@ -3,8 +3,6 @@ package resolver
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/dialid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/transactionid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
|
||||
)
|
||||
|
||||
@@ -15,15 +13,11 @@ type ErrorWrapperResolver struct {
|
||||
|
||||
// LookupHost implements Resolver.LookupHost
|
||||
func (r ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
|
||||
dialID := dialid.ContextDialID(ctx)
|
||||
txID := transactionid.ContextTransactionID(ctx)
|
||||
addrs, err := r.Resolver.LookupHost(ctx, hostname)
|
||||
err = errorx.SafeErrWrapperBuilder{
|
||||
Classifier: errorx.ClassifyResolveFailure,
|
||||
DialID: dialID,
|
||||
Error: err,
|
||||
Operation: errorx.ResolveOperation,
|
||||
TransactionID: txID,
|
||||
Classifier: errorx.ClassifyResolveFailure,
|
||||
Error: err,
|
||||
Operation: errorx.ResolveOperation,
|
||||
}.MaybeBuild()
|
||||
return addrs, err
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/dialid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/transactionid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver"
|
||||
)
|
||||
@@ -30,8 +28,6 @@ func TestErrorWrapperFailure(t *testing.T) {
|
||||
Resolver: resolver.NewFakeResolverThatFails(),
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx = dialid.WithDialID(ctx)
|
||||
ctx = transactionid.WithTransactionID(ctx)
|
||||
addrs, err := r.LookupHost(ctx, "dns.google.com")
|
||||
if addrs != nil {
|
||||
t.Fatal("expected nil addr here")
|
||||
@@ -43,15 +39,6 @@ func TestErrorWrapperFailure(t *testing.T) {
|
||||
if errWrapper.Failure != errorx.FailureDNSNXDOMAINError {
|
||||
t.Fatal("unexpected failure")
|
||||
}
|
||||
if errWrapper.ConnID != 0 {
|
||||
t.Fatal("unexpected ConnID")
|
||||
}
|
||||
if errWrapper.DialID == 0 {
|
||||
t.Fatal("unexpected DialID")
|
||||
}
|
||||
if errWrapper.TransactionID == 0 {
|
||||
t.Fatal("unexpected TransactionID")
|
||||
}
|
||||
if errWrapper.Operation != errorx.ResolveOperation {
|
||||
t.Fatal("unexpected Operation")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user