Skip to content

Commit

Permalink
refactor(riseupvpn): rename structs, change progress, bump version
Browse files Browse the repository at this point in the history
This diff renames some structs, changes the code emitting the progress,
and bumps the experiment version. In my previous commit, I said I did
bump the version number but that was not actually the case.

This diff has been extracted from #1125.

This diff is part of ooni/probe#1432
  • Loading branch information
bassosimone committed Oct 11, 2023
1 parent 82b11fc commit 0df2d7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
37 changes: 21 additions & 16 deletions internal/experiment/riseupvpn/riseupvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,28 @@ import (

const (
testName = "riseupvpn"
testVersion = "0.2.0"
testVersion = "0.3.0"
eipServiceURL = "https://api.black.riseup.net:443/3/config/eip-service.json"
providerURL = "https://riseup.net/provider.json"
geoServiceURL = "https://api.black.riseup.net:9001/json"
tcpConnect = "tcpconnect://"
)

// EipService is the main JSON object of eip-service.json.
type EipService struct {
// EIPServiceV3 is the main JSON object returned by eip-service.json.
type EIPServiceV3 struct {
Gateways []GatewayV3
}

// CapabilitiesV3 is a list of transports a gateway supports
type CapabilitiesV3 struct {
Transport []TransportV3
}

// GatewayV3 describes a gateway.
type GatewayV3 struct {
Capabilities struct {
Transport []TransportV3
}
Host string
IPAddress string `json:"ip_address"`
Capabilities CapabilitiesV3
Host string
IPAddress string `json:"ip_address"`
}

// TransportV3 describes a transport.
Expand Down Expand Up @@ -203,7 +206,7 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
FailOnHTTPError: true,
}},
}
for entry := range multi.CollectOverall(ctx, inputs, 0, 50, "riseupvpn", callbacks) {
for entry := range multi.CollectOverall(ctx, inputs, 0, 20, "riseupvpn", callbacks) {
tk := entry.TestKeys
testkeys.AddCACertFetchTestKeys(tk)
if tk.Failure != nil {
Expand Down Expand Up @@ -241,7 +244,7 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
FailOnHTTPError: true,
}},
}
for entry := range multi.CollectOverall(ctx, inputs, 1, 50, "riseupvpn", callbacks) {
for entry := range multi.CollectOverall(ctx, inputs, 1, 20, "riseupvpn", callbacks) {
testkeys.UpdateProviderAPITestKeys(entry)
}

Expand All @@ -251,19 +254,21 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
openvpnEndpoints := generateMultiInputs(gateways, "openvpn")
obfs4Endpoints := generateMultiInputs(gateways, "obfs4")
overallCount := 1 + len(inputs) + len(openvpnEndpoints) + len(obfs4Endpoints)
startCount := 1 + len(inputs)

// measure openvpn in parallel
for entry := range multi.CollectOverall(
ctx, openvpnEndpoints, 1+len(inputs), overallCount, "riseupvpn", callbacks) {
ctx, openvpnEndpoints, startCount, overallCount, "riseupvpn", callbacks) {
testkeys.AddGatewayConnectTestKeys(entry, "openvpn")
}

// measure obfs4 in parallel
// TODO(bassosimone): when urlgetter is able to do obfs4 handshakes, here
// can possibly also test for the obfs4 handshake.
// See https://github.com/ooni/probe/issues/1463.
startCount += len(openvpnEndpoints)
for entry := range multi.CollectOverall(
ctx, obfs4Endpoints, 1+len(inputs)+len(openvpnEndpoints), overallCount, "riseupvpn", callbacks) {
ctx, obfs4Endpoints, startCount, overallCount, "riseupvpn", callbacks) {
testkeys.AddGatewayConnectTestKeys(entry, "obfs4")
}

Expand Down Expand Up @@ -303,7 +308,7 @@ func parseGateways(testKeys *TestKeys) []GatewayV3 {
// TODO(bassosimone,cyberta): is it reasonable that we discard
// the error when the JSON we fetched cannot be parsed?
// See https://github.com/ooni/probe/issues/1432
eipService, err := DecodeEIP3(string(requestEntry.Response.Body))
eipService, err := DecodeEIPService3(string(requestEntry.Response.Body))
if err == nil {
return eipService.Gateways
}
Expand All @@ -312,9 +317,9 @@ func parseGateways(testKeys *TestKeys) []GatewayV3 {
return nil
}

// DecodeEIP3 decodes eip-service.json version 3
func DecodeEIP3(body string) (*EipService, error) {
var eip EipService
// DecodeEIPService3 decodes eip-service.json version 3
func DecodeEIPService3(body string) (*EIPServiceV3, error) {
var eip EIPServiceV3
err := json.Unmarshal([]byte(body), &eip)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/experiment/riseupvpn/riseupvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
if measurer.ExperimentName() != "riseupvpn" {
t.Fatal("unexpected name")
}
if measurer.ExperimentVersion() != "0.2.0" {
if measurer.ExperimentVersion() != "0.3.0" {
t.Fatal("unexpected version")
}
}
Expand Down Expand Up @@ -549,7 +549,7 @@ func TestFailureTransport(t *testing.T) {
}

func TestMissingTransport(t *testing.T) {
eipService, err := riseupvpn.DecodeEIP3(eipservice)
eipService, err := riseupvpn.DecodeEIPService3(eipservice)
if err != nil {
t.Fatal("Preconditions for the test are not met.")
}
Expand Down

0 comments on commit 0df2d7f

Please sign in to comment.