diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-08-19 18:21:37 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-08-20 20:27:48 +0200 |
commit | 30587fb27b73fdb3f0aab1a78844edcaaae1c3bb (patch) | |
tree | 1669a7735428c9cfa074a8095e9a7e4c6b6ec366 /pkg/vpn/bonafide/eip_service.go | |
parent | 9882dfc474e410b5745388ca7d1bbc873be836b3 (diff) |
[feat] pick only the top 3 gateways
fixes bug: do not initialize an empty list of gateways
Diffstat (limited to 'pkg/vpn/bonafide/eip_service.go')
-rw-r--r-- | pkg/vpn/bonafide/eip_service.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/pkg/vpn/bonafide/eip_service.go b/pkg/vpn/bonafide/eip_service.go index 49f4bb1..961ac40 100644 --- a/pkg/vpn/bonafide/eip_service.go +++ b/pkg/vpn/bonafide/eip_service.go @@ -116,6 +116,9 @@ func (b *Bonafide) fetchEipJSON() error { } b.setupAuthentication(b.eip) + /* TODO we could launch the looping call from here. + but smells: calls a bonafide method that in turn calls methods in this file + */ b.sortGateways() return nil } @@ -204,8 +207,9 @@ func (eip eipService) getOpenvpnArgs() []string { } func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) { - gws := make([]gatewayV3, len(eip.Gateways)) + gws := make([]gatewayV3, 0) + /* TODO this probably should be moved out of this method */ if eip.defaultGateway != "" { for _, gw := range eip.Gateways { if gw.Location == eip.defaultGateway { @@ -213,6 +217,8 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) { break } } + // a manually selected gateway means we do want exactly one remote + return } for _, host := range geolocatedGateways { @@ -224,7 +230,9 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) { } if len(gws) == 0 { - log.Println("ERROR: avoiding to replace eip.Gateways will null list. Is the geolocation service properly configured?") + // this can happen if a misconfigured geoip service does not match the + // providers list we got. + log.Println("ERROR: avoiding to nullify eip.Gateways. Is the geolocation service properly configured?") } else { if len(gws) > 2 { eip.Gateways = gws[:3] |