Skip to content

Commit

Permalink
[backport] refactor: create common package for holding STUN input (#631)
Browse files Browse the repository at this point in the history
We want stunreachability to use the same STUN servers used by
snowflake, so let's start by making a common package holding the
servers. Let's also use this new package in Snowflake.

We're currently not using this package in stunreachability, but
I am going to apply this as a subsequent diff.

Reference issue: ooni/probe#1814. This
issue is a bit complex to address in a single PR, so we are going
to proceed incremntally.

This diff was extracted from #539.
  • Loading branch information
bassosimone committed Dec 3, 2021
1 parent 9ec2ebc commit f7b238a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 14 deletions.
16 changes: 2 additions & 14 deletions internal/ptx/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"

sflib "git.torproject.org/pluggable-transports/snowflake.git/client/lib"
"github.com/ooni/probe-cli/v3/internal/stuninput"
)

// SnowflakeDialer is a dialer for snowflake. When optional fields are
Expand Down Expand Up @@ -115,20 +116,7 @@ func (d *SnowflakeDialer) iceAddresses() []string {
if len(d.ICEAddresses) > 0 {
return d.ICEAddresses
}
return []string{
"stun:stun.voip.blackberry.com:3478",
"stun:stun.altar.com.pl:3478",
"stun:stun.antisip.com:3478",
"stun:stun.bluesip.net:3478",
"stun:stun.dus.net:3478",
"stun:stun.epygi.com:3478",
"stun:stun.sonetel.com:3478",
"stun:stun.sonetel.net:3478",
"stun:stun.stunprotocol.org:3478",
"stun:stun.uls.co.za:3478",
"stun:stun.voipgate.com:3478",
"stun:stun.voys.nl:3478",
}
return stuninput.AsSnowflakeInput()
}

// maxSnowflakes returns the number of snowflakes to collect.
Expand Down
44 changes: 44 additions & 0 deletions internal/stuninput/stuninput.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package stuninput contains stun targets as well as
// code to format such targets according to various conventions.
package stuninput

import (
"fmt"
"net/url"
)

// TODO(bassosimone): we need to keep this list in sync with
// the list internally used by TPO's snowflake.
var inputs = []string{
"stun.voip.blackberry.com:3478",
"stun.altar.com.pl:3478",
"stun.antisip.com:3478",
"stun.bluesip.net:3478",
"stun.dus.net:3478",
"stun.epygi.com:3478",
"stun.sonetel.com:3478",
"stun.sonetel.net:3478",
"stun.stunprotocol.org:3478",
"stun.uls.co.za:3478",
"stun.voipgate.com:3478",
"stun.voys.nl:3478",
}

// AsSnowflakeInput formats the input in the format
// that is expected by snowflake.
func AsSnowflakeInput() (output []string) {
for _, input := range inputs {
output = append(output, fmt.Sprintf("stun:%s", input))
}
return
}

// AsnStunReachabilityInput formats the input in
// the format that is expected by stunreachability.
func AsnStunReachabilityInput() (output []string) {
for _, input := range inputs {
serio := (&url.URL{Scheme: "stun", Host: input})
output = append(output, serio.String())
}
return
}
31 changes: 31 additions & 0 deletions internal/stuninput/stuninput_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package stuninput

import "testing"

func TestAsSnowflakeInput(t *testing.T) {
outputs := AsSnowflakeInput()
if len(outputs) != len(inputs) {
t.Fatal("unexpected number of entries")
}
for idx := 0; idx < len(inputs); idx++ {
output := outputs[idx]
input := "stun:" + inputs[idx]
if input != output {
t.Fatal("mismatch")
}
}
}

func TestAsStunReachabilityInput(t *testing.T) {
outputs := AsnStunReachabilityInput()
if len(outputs) != len(inputs) {
t.Fatal("unexpected number of entries")
}
for idx := 0; idx < len(inputs); idx++ {
output := outputs[idx]
input := "stun://" + inputs[idx]
if input != output {
t.Fatal("mismatch")
}
}
}

0 comments on commit f7b238a

Please sign in to comment.