Skip to content

Commit

Permalink
refactor(telegram): allow mocking DC initialization (#1182)
Browse files Browse the repository at this point in the history
This diff modifies the telegram experiment to allow mocking DC
initialization. In turn, this change will help us to write netem-based
tests for this experiment. See
ooni/probe#2461.

---------

Co-authored-by: kelmenhorst <[email protected]>
  • Loading branch information
2 people authored and cyBerta committed Aug 4, 2023
1 parent 0f93d0a commit e41e586
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions internal/experiment/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
testName = "telegram"
testVersion = "0.3.0"
testVersion = "0.3.1"
)

// Config contains the telegram experiment config.
Expand Down Expand Up @@ -87,6 +87,16 @@ func (m Measurer) ExperimentVersion() string {
return testVersion
}

// DatacenterIPAddrs contains the list of Telegram data centers IP addresses to measure.
var DatacenterIPAddrs = []string{
"149.154.175.50",
"149.154.167.51",
"149.154.175.100",
"149.154.167.91",
"149.154.171.5",
"95.161.76.100",
}

// Run implements ExperimentMeasurer.Run
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
callbacks := args.Callbacks
Expand All @@ -97,28 +107,20 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
defer cancel()
urlgetter.RegisterExtensions(measurement)
inputs := []urlgetter.MultiInput{
{Target: "http://149.154.175.50/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.167.51/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.175.100/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.167.91/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.171.5/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://95.161.76.100/", Config: urlgetter.Config{Method: "POST"}},

// Note: the following list contains the same endpoints as above with HTTP (not a typo using
// https _would not work_ here) _and_ port 443.
{Target: "http://149.154.175.50:443/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.167.51:443/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.175.100:443/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.167.91:443/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://149.154.171.5:443/", Config: urlgetter.Config{Method: "POST"}},
{Target: "http://95.161.76.100:443/", Config: urlgetter.Config{Method: "POST"}},

// Here we need to provide the method explicitly. See
// https://github.com/ooni/probe-engine/issues/827.
{Target: "https://web.telegram.org/", Config: urlgetter.Config{
Method: "GET",
}},
}

// We need to measure each address twice. Once using port 80 and once using port 443. In both
// cases, the protocol MUST be HTTP. The DCs do not support access on port 443 using TLS.
for _, dc := range DatacenterIPAddrs {
inputs = append(inputs, urlgetter.MultiInput{Target: "http://" + dc + "/", Config: urlgetter.Config{Method: "POST"}})
inputs = append(inputs, urlgetter.MultiInput{Target: "http://" + dc + ":443/", Config: urlgetter.Config{Method: "POST"}})
}

multi := urlgetter.Multi{Begin: time.Now(), Getter: m.Getter, Session: sess}
testkeys := NewTestKeys()
testkeys.Agent = "redirect"
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
if measurer.ExperimentName() != "telegram" {
t.Fatal("unexpected name")
}
if measurer.ExperimentVersion() != "0.3.0" {
if measurer.ExperimentVersion() != "0.3.1" {
t.Fatal("unexpected version")
}
}
Expand Down

0 comments on commit e41e586

Please sign in to comment.