Skip to content
Snippets Groups Projects
Unverified Commit 30587fb2 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[feat] pick only the top 3 gateways

fixes bug: do not initialize an empty list of gateways
parent 9882dfc4
No related branches found
No related tags found
1 merge request!105Sip login
...@@ -232,7 +232,7 @@ func (b *Bonafide) GetOpenvpnArgs() ([]string, error) { ...@@ -232,7 +232,7 @@ func (b *Bonafide) GetOpenvpnArgs() ([]string, error) {
} }
func (b *Bonafide) fetchGeolocation() ([]string, error) { func (b *Bonafide) fetchGeolocation() ([]string, error) {
/* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate. /* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate, but in riseup is served behind the api certificate.
So this is a workaround until we streamline that behavior */ So this is a workaround until we streamline that behavior */
resp, err := b.client.Post(config.GeolocationAPI, "", nil) resp, err := b.client.Post(config.GeolocationAPI, "", nil)
if err != nil { if err != nil {
......
...@@ -116,6 +116,9 @@ func (b *Bonafide) fetchEipJSON() error { ...@@ -116,6 +116,9 @@ func (b *Bonafide) fetchEipJSON() error {
} }
b.setupAuthentication(b.eip) 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() b.sortGateways()
return nil return nil
} }
...@@ -204,8 +207,9 @@ func (eip eipService) getOpenvpnArgs() []string { ...@@ -204,8 +207,9 @@ func (eip eipService) getOpenvpnArgs() []string {
} }
func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []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 != "" { if eip.defaultGateway != "" {
for _, gw := range eip.Gateways { for _, gw := range eip.Gateways {
if gw.Location == eip.defaultGateway { if gw.Location == eip.defaultGateway {
...@@ -213,6 +217,8 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) { ...@@ -213,6 +217,8 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) {
break break
} }
} }
// a manually selected gateway means we do want exactly one remote
return
} }
for _, host := range geolocatedGateways { for _, host := range geolocatedGateways {
...@@ -224,7 +230,9 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) { ...@@ -224,7 +230,9 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) {
} }
if len(gws) == 0 { 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 { } else {
if len(gws) > 2 { if len(gws) > 2 {
eip.Gateways = gws[:3] eip.Gateways = gws[:3]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment