diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-09-06 21:08:14 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-23 21:51:01 +0100 |
commit | 8543125fa656ddc2c114072adfc27e4e7c461695 (patch) | |
tree | 176f90c03f64c2645932dbaf3d87f2ad22b61489 /pkg/vpn | |
parent | b8e0fe3b5003d22043042110e8036f4383602545 (diff) |
[ui] transient connecting state
Diffstat (limited to 'pkg/vpn')
-rw-r--r-- | pkg/vpn/bonafide/bonafide.go | 11 | ||||
-rw-r--r-- | pkg/vpn/bonafide/gateways.go | 27 | ||||
-rw-r--r-- | pkg/vpn/openvpn.go | 4 | ||||
-rw-r--r-- | pkg/vpn/status.go | 4 |
4 files changed, 46 insertions, 0 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index a9a7d85..cff5fc2 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -278,6 +278,10 @@ func (b *Bonafide) ListLocationFullness(transport string) map[string]float64 { return b.gateways.listLocationFullness(transport) } +func (b *Bonafide) ListLocationLabels(transport string) map[string][]string { + return b.gateways.listLocationLabels(transport) +} + func (b *Bonafide) SetManualGateway(label string) { b.gateways.setUserChoice(label) } @@ -286,6 +290,13 @@ func (b *Bonafide) SetAutomaticGateway() { b.gateways.setAutomaticChoice() } +func (b *Bonafide) GetBestLocation(transport string) string { + if b.gateways == nil { + return "" + } + return b.gateways.getBestLocation(transport, b.tzOffsetHours) +} + func (b *Bonafide) IsManualLocation() bool { if b.gateways == nil { return false diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go index 53ab320..4299bb2 100644 --- a/pkg/vpn/bonafide/gateways.go +++ b/pkg/vpn/bonafide/gateways.go @@ -113,6 +113,20 @@ func (p *gatewayPool) listLocationFullness(transport string) map[string]float64 return cm } +/* returns a map of location: labels for the ui to use */ +func (p *gatewayPool) listLocationLabels(transport string) map[string][]string { + cm := make(map[string][]string) + locations := p.getLocations() + if len(locations) == 0 { + return cm + } + for _, loc := range locations { + current := p.locations[loc] + cm[loc] = []string{current.Name, current.CountryCode} + } + return cm +} + /* this method should only be used if we have no usable menshen list. */ func (p *gatewayPool) getRandomGatewaysByLocation(location, transport string) ([]Gateway, error) { if !p.isValidLocation(location) { @@ -274,6 +288,19 @@ func (p *gatewayPool) getBest(transport string, tz, max int) ([]Gateway, error) } } +/* returns the location for the first recommended gateway */ +func (p *gatewayPool) getBestLocation(transport string, tz int) string { + best, err := p.getBest(transport, tz, 1) + if err != nil { + return "" + } + if len(best) != 1 { + return "" + } + return best[0].Location + +} + func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) { if len(p.recommended) != 0 { return p.getGatewaysFromMenshen(transport, 999) diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go index b15530b..fe10b69 100644 --- a/pkg/vpn/openvpn.go +++ b/pkg/vpn/openvpn.go @@ -326,6 +326,10 @@ func (b *Bitmask) ListLocationFullness(transport string) map[string]float64 { return b.bonafide.ListLocationFullness(transport) } +func (b *Bitmask) ListLocationLabels(transport string) map[string][]string { + return b.bonafide.ListLocationLabels(transport) +} + // UseGateway selects a gateway, by label, as the default gateway func (b *Bitmask) UseGateway(label string) { b.bonafide.SetManualGateway(label) diff --git a/pkg/vpn/status.go b/pkg/vpn/status.go index 0b04c3b..88735e6 100644 --- a/pkg/vpn/status.go +++ b/pkg/vpn/status.go @@ -103,6 +103,10 @@ func (b *Bitmask) GetCurrentCountry() string { return b.onGateway.CountryCode } +func (b *Bitmask) GetBestLocation(transport string) string { + return b.bonafide.GetBestLocation(transport) +} + func (b *Bitmask) IsManualLocation() bool { return b.bonafide.IsManualLocation() } |