Commit 3baa3b7e authored by Kali Kaneko's avatar Kali Kaneko
Browse files

fix filter gws by transport

parent 67bdccaa
......@@ -54,7 +54,7 @@ StateGroup {
}
PropertyChanges {
target: mainCurrentGateway
text: qsTr("Connected to ") + ctx.currentGateway
text: qsTr("Connected to ") + ctx.currentLocation
}
PropertyChanges {
target: mainOnBtn
......
......@@ -23,9 +23,6 @@ Window {
property var loginDone
property var allowEmptyPass
onWidthChanged: displayGatewayMarker()
onHeightChanged: displayGatewayMarker()
GridLayout {
visible: true
......@@ -37,6 +34,7 @@ Window {
Layout.leftMargin: app.width * 0.10
ColumnLayout {
Layout.alignment: Qt.AlignHCenter
Text {
......@@ -88,7 +86,8 @@ Window {
target: jsonModel
onDataChanged: {
ctx = JSON.parse(jsonModel.getJson())
console.debug(jsonModel.getJson())
// TODO pass QML_DEBUG variable to be hyper-verbose
//console.debug(jsonModel.getJson())
gwSelector.model = Object.keys(ctx.gateways)
if (ctx.donateDialog == 'true') {
......@@ -194,6 +193,8 @@ Window {
}
}
/* TODO change this!!! automatic: Paris (FR) */
function toHumanWithLocation(st) {
switch (st) {
case "off":
......@@ -202,12 +203,12 @@ Window {
case "on":
//: %1 -> application name
//: %2 -> current gateway
return qsTr("%1 on - %2").arg(ctx.appName).arg(ctx.currentGateway)
return qsTr("%1 on - %2").arg(ctx.appName).arg(ctx.currentLocation)
case "connecting":
//: %1 -> application name
//: %2 -> current gateway
return qsTr("Connecting to %1 - %2").arg(ctx.appName).arg(
ctx.currentGateway)
ctx.currentLocation)
case "stopping":
//: %1 -> application name
return qsTr("Stopping %1").arg(ctx.appName)
......
......@@ -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)
......
......@@ -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
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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
}
......
......@@ -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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment