summaryrefslogtreecommitdiff
path: root/pkg/vpn/bonafide/bonafide.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-08-26 16:10:32 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-05-04 14:58:38 +0200
commit16f53bd79a9ffb6f89c4e9c81af110287c85d265 (patch)
treeaf4063f70cbcc50e606e04f20357aeaf7f4f07dc /pkg/vpn/bonafide/bonafide.go
parent2124a55d4a3d0ca00f8eab8f86c292ba1e7ccccf (diff)
[refactor] some renaming, preliminar refactor
Diffstat (limited to 'pkg/vpn/bonafide/bonafide.go')
-rw-r--r--pkg/vpn/bonafide/bonafide.go35
1 files changed, 18 insertions, 17 deletions
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
+}