Commit b14d048e authored by meskio's avatar meskio Committed by Kali Kaneko
Browse files

Don't expose the full gateway out of the vpn module

We just care about locations and fullness.
parent 8c4edf29
......@@ -177,7 +177,7 @@ Window {
ctx = JSON.parse(jsonModel.getJson())
// TODO pass QML_DEBUG variable to be hyper-verbose
//console.debug(jsonModel.getJson())
gwSelector.model = Object.keys(ctx.gateways)
gwSelector.model = Object.keys(ctx.locations)
if (ctx.donateDialog == 'true') {
console.debug(jsonModel.getJson())
......
......@@ -8,7 +8,6 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/bitmask-vpn/pkg/vpn/bonafide"
)
const (
......@@ -33,22 +32,21 @@ var updateMutex sync.Mutex
// them.
type connectionCtx struct {
AppName string `json:"appName"`
Provider string `json:"provider"`
TosURL string `json:"tosURL"`
HelpURL string `json:"helpURL"`
AskForDonations bool `json:"askForDonations"`
DonateDialog bool `json:"donateDialog"`
DonateURL string `json:"donateURL"`
LoginDialog bool `json:"loginDialog"`
LoginOk bool `json:"loginOk"`
Version string `json:"version"`
Errors string `json:"errors"`
Status status `json:"status"`
/* XXX perhaps rename to GatewaysByCity */
Gateways map[string]bonafide.Gateway `json:"gateways"`
CurrentGateway string `json:"currentGateway"`
CurrentLocation string `json:"currentLocation"`
AppName string `json:"appName"`
Provider string `json:"provider"`
TosURL string `json:"tosURL"`
HelpURL string `json:"helpURL"`
AskForDonations bool `json:"askForDonations"`
DonateDialog bool `json:"donateDialog"`
DonateURL string `json:"donateURL"`
LoginDialog bool `json:"loginDialog"`
LoginOk bool `json:"loginOk"`
Version string `json:"version"`
Errors string `json:"errors"`
Status status `json:"status"`
Locations map[string]float64 `json:"locations"`
CurrentGateway string `json:"currentGateway"`
CurrentLocation string `json:"currentLocation"`
bm bitmask.Bitmask
autostart bitmask.Autostart
cfg *config.Config
......@@ -57,11 +55,7 @@ type connectionCtx struct {
func (c connectionCtx) toJson() ([]byte, error) {
statusMutex.Lock()
if c.bm != nil {
gws, err := c.bm.ListGatewaysByCity("openvpn")
if err != nil {
log.Println("error getting gateways for city")
}
c.Gateways = gws
c.Locations = c.bm.ListLocationFullness("openvpn")
c.CurrentGateway = c.bm.GetCurrentGateway()
c.CurrentLocation = c.bm.GetCurrentLocation()
}
......
......@@ -64,12 +64,11 @@ func webGatewaySet(w http.ResponseWriter, r *http.Request) {
}
func webGatewayList(w http.ResponseWriter, r *http.Request) {
gws, err := ctx.bm.ListGatewaysByCity(ctx.Provider)
locationJson, err := json.Marshal(ctx.bm.ListLocationFullness("openvpn"))
if err != nil {
fmt.Fprintf(w, "ListGatewaysByCity() err: %v", err)
fmt.Fprintf(w, "Error converting json: %v", err)
}
gwJson, _ := json.Marshal(gws)
fmt.Fprintf(w, string(gwJson))
fmt.Fprintf(w, string(locationJson))
}
// TODO
......
......@@ -15,10 +15,6 @@
package bitmask
import (
"0xacab.org/leap/bitmask-vpn/pkg/vpn/bonafide"
)
type Bitmask interface {
GetStatusCh() <-chan string
Close()
......@@ -30,12 +26,10 @@ type Bitmask interface {
GetStatus() (string, error)
InstallHelpers() error
VPNCheck() (helpers bool, priviledge bool, err error)
/* this is kind of breaking the abstract interface, maybe we don't need this anymore */
ListGatewaysByCity(protocol string) (map[string]bonafide.Gateway, error)
ListLocationFullness(protocol string) map[string]float64
UseGateway(name string) error
GetCurrentGateway() string
GetCurrentLocation() string
GetGatewayDetails(label string) (interface{}, error)
UseTransport(transport string) error
NeedsCredentials() bool
DoLogin(username, password string) (bool, error)
......
......@@ -224,13 +224,8 @@ func (b *Bonafide) GetAllGateways(transport string) ([]Gateway, error) {
return gws, err
}
func (b *Bonafide) PickGatewayForCities(transport string) (map[string]Gateway, error) {
return b.gateways.pickGatewayForCities(transport), nil
}
func (b *Bonafide) GetGatewayDetails(host string) (Gateway, error) {
gw, err := b.gateways.getGatewayByHost(host)
return gw, err
func (b *Bonafide) ListLocationFullness(transport string) map[string]float64 {
return b.gateways.listLocationFullness(transport)
}
func (b *Bonafide) SetManualGateway(label string) {
......
......@@ -34,7 +34,7 @@ type Gateway struct {
Protocols []string
Options map[string]string
Transport string
Fullness float32
Fullness float64
}
/* gatewayDistance is used in the timezone distance fallback */
......@@ -96,13 +96,13 @@ func (p *gatewayPool) isValidCity(city string) bool {
return valid
}
/* returns a map of city: gateway for the ui to use */
func (p *gatewayPool) pickGatewayForCities(transport string) map[string]Gateway {
/* returns a map of location: fullness for the ui to use */
func (p *gatewayPool) listLocationFullness(transport string) map[string]float64 {
cities := p.getCities()
cm := make(map[string]Gateway)
cm := make(map[string]float64)
for _, city := range cities {
gw, _ := p.getRandomGatewayByCity(city, transport)
cm[city] = gw
cm[city] = gw.Fullness
}
return cm
}
......
......@@ -25,7 +25,6 @@ import (
"strconv"
"strings"
"0xacab.org/leap/bitmask-vpn/pkg/vpn/bonafide"
"0xacab.org/leap/shapeshifter"
)
......@@ -231,17 +230,8 @@ func (b *Bitmask) VPNCheck() (helpers bool, privilege bool, err error) {
return b.launch.check()
}
func (b *Bitmask) ListGatewaysByCity(transport string) (map[string]bonafide.Gateway, error) {
gwForCities, err := b.bonafide.PickGatewayForCities(transport)
return gwForCities, err
}
func (b *Bitmask) GetGatewayDetails(host string) (interface{}, error) {
gw, err := b.bonafide.GetGatewayDetails(host)
if err != nil {
return bonafide.Gateway{}, err
}
return gw, nil
func (b *Bitmask) ListLocationFullness(transport string) map[string]float64 {
return b.bonafide.ListLocationFullness(transport)
}
// UseGateway selects a gateway, by label, as the default gateway
......
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