From 16f53bd79a9ffb6f89c4e9c81af110287c85d265 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Wed, 26 Aug 2020 16:10:32 +0200 Subject: [refactor] some renaming, preliminar refactor --- pkg/vpn/bonafide/bonafide.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'pkg/vpn/bonafide/bonafide.go') diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index 28cfe44..4426da6 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -203,22 +203,13 @@ func (b *Bonafide) GetGateways(transport string) ([]Gateway, error) { return b.eip.getGateways(transport), nil } -func (b *Bonafide) SetDefaultGateway(name string) { - b.eip.setDefaultGateway(name) - b.sortGateways() +func (b *Bonafide) SetManualGateway(name string) { + /* TODO use gateway-id instead - a location-id is probably more useful than + * the gateway hostname */ + b.eip.setManualGateway(name) } -func (b *Bonafide) GetOpenvpnArgs() ([]string, error) { - if b.eip == nil { - err := b.fetchEipJSON() - if err != nil { - return nil, err - } - } - return b.eip.getOpenvpnArgs(), nil -} - -func (b *Bonafide) fetchGeolocation() ([]string, error) { +func (b *Bonafide) requestBestGatewaysFromService() ([]string, error) { /* 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 */ resp, err := b.client.Post(config.GeolocationAPI, "", nil) @@ -254,12 +245,22 @@ func (b *Bonafide) fetchGeolocation() ([]string, error) { } func (b *Bonafide) sortGateways() { - geolocatedGateways, _ := b.fetchGeolocation() + serviceSelection, _ := b.requestBestGatewaysFromService() - if len(geolocatedGateways) > 0 { - b.eip.sortGatewaysByGeolocation(geolocatedGateways) + if len(serviceSelection) > 0 { + b.eip.autoSortGateways(serviceSelection) } else { log.Printf("Falling back to timezone heuristic for gateway selection") b.eip.sortGatewaysByTimezone(b.tzOffsetHours) } } + +func (b *Bonafide) GetOpenvpnArgs() ([]string, error) { + if b.eip == nil { + err := b.fetchEipJSON() + if err != nil { + return nil, err + } + } + return b.eip.getOpenvpnArgs(), nil +} -- cgit v1.2.3