summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/backend/status.go25
-rw-r--r--pkg/bitmask/bitmask.go8
-rw-r--r--pkg/vpn/bonafide/bonafide.go4
-rw-r--r--pkg/vpn/bonafide/gateways.go24
-rw-r--r--pkg/vpn/openvpn.go5
-rw-r--r--pkg/vpn/status.go4
6 files changed, 35 insertions, 35 deletions
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index cfc68d1..3d78a0b 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -45,26 +45,25 @@ type connectionCtx struct {
Version string `json:"version"`
Errors string `json:"errors"`
Status status `json:"status"`
- /* XXX rename to GatewaysByCity */
- Gateways map[string]bonafide.Gateway `json:"gateways"`
- CurrentGateway string `json:"currentGateway"`
- bm bitmask.Bitmask
- autostart bitmask.Autostart
- cfg *config.Config
+ /* XXX perhaps rename to GatewaysByCity */
+ Gateways map[string]bonafide.Gateway `json:"gateways"`
+ CurrentGateway string `json:"currentGateway"`
+ CurrentLocation string `json:"currentLocation"`
+ bm bitmask.Bitmask
+ autostart bitmask.Autostart
+ cfg *config.Config
}
func (c connectionCtx) toJson() ([]byte, error) {
statusMutex.Lock()
if c.bm != nil {
- c.Gateways = map[string]bonafide.Gateway{}
- /* FIXME this returns hostnames, could return bonafide gateway directly */
- gateways, _ := c.bm.ListGatewaysByCity("openvpn")
- log.Println(">>> got gws for cities", gateways)
- for city, host := range gateways {
- gw, _ := c.bm.GetGatewayDetails(host)
- c.Gateways[city] = gw.(bonafide.Gateway)
+ gws, err := c.bm.ListGatewaysByCity("openvpn")
+ if err != nil {
+ log.Println("error getting gateways for city")
}
+ c.Gateways = gws
c.CurrentGateway = c.bm.GetCurrentGateway()
+ c.CurrentLocation = c.bm.GetCurrentLocation()
}
defer statusMutex.Unlock()
b, err := json.Marshal(c)
diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go
index e284541..156af58 100644
--- a/pkg/bitmask/bitmask.go
+++ b/pkg/bitmask/bitmask.go
@@ -15,6 +15,10 @@
package bitmask
+import (
+ "0xacab.org/leap/bitmask-vpn/pkg/vpn/bonafide"
+)
+
type Bitmask interface {
GetStatusCh() <-chan string
Close()
@@ -26,9 +30,11 @@ type Bitmask interface {
GetStatus() (string, error)
InstallHelpers() error
VPNCheck() (helpers bool, priviledge bool, err error)
- ListGatewaysByCity(provider string) (map[string]string, error)
+ /* this is kind of breaking the abstract interface, maybe we don't need this anymore */
+ ListGatewaysByCity(protocol string) (map[string]bonafide.Gateway, error)
UseGateway(name string) error
GetCurrentGateway() string
+ GetCurrentLocation() string
GetGatewayDetails(label string) (interface{}, error)
UseTransport(transport string) error
NeedsCredentials() bool
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index f0726b8..9dadc99 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -224,8 +224,8 @@ func (b *Bonafide) GetAllGateways(transport string) ([]Gateway, error) {
return gws, err
}
-func (b *Bonafide) PickGatewayForCities() (map[string]string, error) {
- return b.gateways.pickGatewayForCities(), nil
+func (b *Bonafide) PickGatewayForCities(transport string) (map[string]Gateway, error) {
+ return b.gateways.pickGatewayForCities(transport), nil
}
func (b *Bonafide) GetGatewayDetails(host string) (Gateway, error) {
diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go
index fa92661..6bfef7c 100644
--- a/pkg/vpn/bonafide/gateways.go
+++ b/pkg/vpn/bonafide/gateways.go
@@ -33,14 +33,6 @@ type Load struct {
Fullness string
}
-/*
-func (g *cityMap) Get(key string) []string {
- if val, ok := g.gws[key]; ok {
- return val
- }
-}
-*/
-
/* gatewayDistance is used in the timezone distance fallback */
type gatewayDistance struct {
gateway Gateway
@@ -92,18 +84,18 @@ func (p *gatewayPool) isValidCity(city string) bool {
}
/* returns a map of city: hostname for the ui to use */
-func (p *gatewayPool) pickGatewayForCities() map[string]string {
+func (p *gatewayPool) pickGatewayForCities(transport string) map[string]Gateway {
cities := p.getCities()
- cm := make(map[string]string)
+ cm := make(map[string]Gateway)
for _, city := range cities {
- gw, _ := p.getRandomGatewayByCity(city)
- cm[city] = gw.Host
+ gw, _ := p.getRandomGatewayByCity(city, transport)
+ cm[city] = gw
}
return cm
}
/* this method should only be used if we have no usable menshen list */
-func (p *gatewayPool) getRandomGatewayByCity(city string) (Gateway, error) {
+func (p *gatewayPool) getRandomGatewayByCity(city, transport string) (Gateway, error) {
if !p.isValidCity(city) {
return Gateway{}, errors.New("bonafide: BUG not a valid city: " + city)
}
@@ -115,11 +107,11 @@ func (p *gatewayPool) getRandomGatewayByCity(city string) (Gateway, error) {
r := rand.New(s)
host := gws[r.Intn(len(gws))]
for _, gw := range p.available {
- if gw.Host == host {
+ if (gw.Host == host) && (gw.Transport == transport) {
return gw, nil
}
}
- return Gateway{}, errors.New("bonafide: BUG should not reach here")
+ return Gateway{}, errors.New("bonafide: BUG could not find any gateway for that location")
}
func (p *gatewayPool) getGatewayByHost(host string) (Gateway, error) {
@@ -173,7 +165,7 @@ func (p *gatewayPool) getBest(transport string, tz, max int) ([]Gateway, error)
if len(p.userChoice) != 0 {
/* FIXME this is random because we still do not get menshen to return us load. after "new" menshen is deployed,
we can just get them by the order menshen reeturned */
- gw, err := p.getRandomGatewayByCity(string(p.userChoice))
+ gw, err := p.getRandomGatewayByCity(string(p.userChoice), transport)
gws = append(gws, gw)
return gws, err
} else if len(p.recommended) != 0 {
diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go
index 1857476..298ea75 100644
--- a/pkg/vpn/openvpn.go
+++ b/pkg/vpn/openvpn.go
@@ -231,9 +231,8 @@ func (b *Bitmask) VPNCheck() (helpers bool, privilege bool, err error) {
return b.launch.check()
}
-func (b *Bitmask) ListGatewaysByCity(transport string) (map[string]string, error) {
- /* TODO filter by transport */
- gwForCities, err := b.bonafide.PickGatewayForCities()
+func (b *Bitmask) ListGatewaysByCity(transport string) (map[string]bonafide.Gateway, error) {
+ gwForCities, err := b.bonafide.PickGatewayForCities(transport)
return gwForCities, err
}
diff --git a/pkg/vpn/status.go b/pkg/vpn/status.go
index 870bb1f..c812a9a 100644
--- a/pkg/vpn/status.go
+++ b/pkg/vpn/status.go
@@ -90,6 +90,10 @@ func (b *Bitmask) GetCurrentGateway() string {
return b.onGateway.Host
}
+func (b *Bitmask) GetCurrentLocation() string {
+ return b.onGateway.LocationName
+}
+
func (b *Bitmask) getOpenvpnState() (string, error) {
if b.managementClient == nil {
return "", fmt.Errorf("No management connected")