Skip to content

Commit

Permalink
remove default endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Jun 24, 2024
1 parent bac3681 commit 9a649d6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
41 changes: 3 additions & 38 deletions internal/experiment/openvpn/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package openvpn

import (
"fmt"
"math/rand"
"net"
"net/url"
"slices"
Expand Down Expand Up @@ -149,60 +148,26 @@ func (e *endpoint) AsInputURI() string {
return url.String()
}

// endpointList is a list of endpoints.
type endpointList []*endpoint

// DefaultEndpoints contains a subset of known endpoints to be used if no input is passed to the experiment and
// the backend query fails for whatever reason. We risk distributing endpoints that can go stale, so we should be careful about
// the stability of the endpoints selected here, but in restrictive environments it's useful to have something
// to probe in absence of an useful OONI API. Valid credentials are still needed, though.
var DefaultEndpoints = endpointList{
{
Provider: "riseup",
IPAddr: "51.15.187.53",
Port: "1194",
Protocol: "openvpn",
Transport: "tcp",
},
{
Provider: "riseup",
IPAddr: "51.15.187.53",
Port: "1194",
Protocol: "openvpn",
Transport: "udp",
},
}

// Shuffle randomizes the order of items in the endpoint list.
func (e endpointList) Shuffle() endpointList {
rand.Shuffle(len(e), func(i, j int) {
e[i], e[j] = e[j], e[i]
})
return e
}

// APIEnabledProviders is the list of providers that the stable API Endpoint knows about.
// This array will be a subset of the keys in defaultOptionsByProvider, but it might make sense
// to still register info about more providers that the API officially knows about.
var APIEnabledProviders = []string{
// TODO(ainghazal): fix the backend so that we can remove the spurious "vpn" suffix here.
"riseupvpn",
}

// isValidProvider returns true if the provider is found as key in the array of APIEnabledProviders
// isValidProvider returns true if the provider is found as key in the array of [APIEnabledProviders].
func isValidProvider(provider string) bool {
return slices.Contains(APIEnabledProviders, provider)
}

// mergeOpenVPNConfig returns a properly configured [*vpnconfig.Config] object for the given endpoint.
// newOpenVPNConfig returns a properly configured [*vpnconfig.Config] object for the given endpoint.
// To obtain that, we merge the endpoint specific configuration with the options passed as richer input targets.
func mergeOpenVPNConfig(
func newOpenVPNConfig(
tracer *vpntracex.Tracer,
logger model.Logger,
endpoint *endpoint,
config *Config) (*vpnconfig.Config, error) {

// TODO(ainghazal): use merge ability in vpnconfig.OpenVPNOptions merge (pending PR)
provider := endpoint.Provider
if !isValidProvider(provider) {
return nil, fmt.Errorf("%w: unknown provider: %s", ErrInvalidInput, provider)
Expand Down
4 changes: 2 additions & 2 deletions internal/experiment/openvpn/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func Test_mergeVPNConfig(t *testing.T) {
SafeKey: "key",
}

cfg, err := mergeOpenVPNConfig(tracer, nil, e, config)
cfg, err := newOpenVPNConfig(tracer, nil, e, config)
if err != nil {
t.Fatalf("did not expect error, got: %v", err)
}
Expand Down Expand Up @@ -355,7 +355,7 @@ func Test_mergeOpenVPNConfig_with_unknown_provider(t *testing.T) {
SafeCert: "cert",
SafeKey: "key",
}
_, err := mergeOpenVPNConfig(tracer, nil, e, cfg)
_, err := newOpenVPNConfig(tracer, nil, e, cfg)
if !errors.Is(err, ErrInvalidInput) {
t.Fatalf("expected invalid input error, got: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/openvpn/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
}

// 3. build openvpn config from endpoint and options
openvpnConfig, err := mergeOpenVPNConfig(handshakeTracer, sess.Logger(), endpoint, config)
openvpnConfig, err := newOpenVPNConfig(handshakeTracer, sess.Logger(), endpoint, config)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion internal/experiment/openvpn/openvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,4 @@ func TestTimestampsFromHandshake(t *testing.T) {
if duration != 2 {
t.Fatal("expected duration == 2")
}

}

0 comments on commit 9a649d6

Please sign in to comment.