Skip to content

Commit

Permalink
webconnectivity: remove unused function (#807)
Browse files Browse the repository at this point in the history
Part of #776
  • Loading branch information
bassosimone authored Jul 15, 2020
1 parent f86f382 commit a3ee1ce
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 104 deletions.
37 changes: 0 additions & 37 deletions experiment/webconnectivity/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package webconnectivity

import (
"context"
"net"
"sort"
"strconv"

"github.com/ooni/probe-engine/experiment/urlgetter"
"github.com/ooni/probe-engine/geoiplookup/mmdblookup"
"github.com/ooni/probe-engine/internal/httpx"
"github.com/ooni/probe-engine/model"
Expand All @@ -21,39 +17,6 @@ type ControlRequest struct {
TCPConnect []string `json:"tcp_connect"`
}

// NewControlRequest creates a new control request from the target
// URL and the result obtained by measuring it.
func NewControlRequest(
target model.MeasurementTarget, result urlgetter.TestKeys) (out ControlRequest) {
out.HTTPRequest = string(target)
out.HTTPRequestHeaders = make(map[string][]string)
if len(result.Requests) >= 1 { // defensive
// Only these headers are accepted by the control service. We use the
// canonical header keys, which is what Go enforces.
for _, key := range []string{"User-Agent", "Accept", "Accept-Language"} {
// We never set multi line headers so using the map instead of the list
// is totally fine and saves us some extra lines of code. Also, we never
// put binary values in headers, so we can just use value.Value.
if value, ok := result.Requests[0].Request.Headers[key]; ok {
out.HTTPRequestHeaders[key] = []string{value.Value}
}
}
}
// Just in case we have multiple endpoints/attempts, reduce them:
out.TCPConnect = []string{}
epnts := make(map[string]int)
for _, entry := range result.TCPConnect {
epnts[net.JoinHostPort(entry.IP, strconv.Itoa(entry.Port))]++
}
for key := range epnts {
out.TCPConnect = append(out.TCPConnect, key)
}
sort.Slice(out.TCPConnect, func(i, j int) bool { // stable output wrt map iteration
return out.TCPConnect[i] < out.TCPConnect[j]
})
return
}

// ControlTCPConnectResult is the result of the TCP connect
// attempt performed by the control vantage point.
type ControlTCPConnectResult struct {
Expand Down
67 changes: 0 additions & 67 deletions experiment/webconnectivity/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,10 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-engine/experiment/urlgetter"
"github.com/ooni/probe-engine/experiment/webconnectivity"
"github.com/ooni/probe-engine/internal/mockable"
"github.com/ooni/probe-engine/model"
"github.com/ooni/probe-engine/netx/archival"
)

func TestNewControlRequest(t *testing.T) {
type args struct {
target model.MeasurementTarget
result urlgetter.TestKeys
}
tests := []struct {
name string
args args
wantOut webconnectivity.ControlRequest
}{{
name: "with empty input",
wantOut: webconnectivity.ControlRequest{
HTTPRequestHeaders: make(map[string][]string),
TCPConnect: []string{},
},
}, {
name: "common case",
args: args{
target: "http://www.example.com/",
result: urlgetter.TestKeys{
Requests: []archival.RequestEntry{{
Request: archival.HTTPRequest{
Headers: map[string]archival.MaybeBinaryValue{
"User-Agent": {Value: "antani/1.0"},
"Accept": {Value: "*/*"},
"Accept-Language": {Value: "en_UK"},
"Host": {Value: "www.example.com"}, // extra!
},
},
}},
TCPConnect: []archival.TCPConnectEntry{{
IP: "10.0.0.1",
Port: 80,
}, {
IP: "10.0.0.2",
Port: 443,
}, {
IP: "10.0.0.1", // duplicate: do we reduce it?
Port: 80,
}},
},
},
wantOut: webconnectivity.ControlRequest{
HTTPRequest: "http://www.example.com/",
HTTPRequestHeaders: map[string][]string{
"User-Agent": {"antani/1.0"},
"Accept": {"*/*"},
"Accept-Language": {"en_UK"},
},
TCPConnect: []string{
"10.0.0.1:80", "10.0.0.2:443",
},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotOut := webconnectivity.NewControlRequest(tt.args.target, tt.args.result)
if diff := cmp.Diff(tt.wantOut, gotOut); diff != "" {
t.Fatal(diff)
}
})
}
}

func TestFillASNsEmpty(t *testing.T) {
dns := new(webconnectivity.ControlDNSResult)
dns.FillASNs(new(mockable.ExperimentSession))
Expand Down

0 comments on commit a3ee1ce

Please sign in to comment.