summaryrefslogtreecommitdiff
path: root/pkg/backend
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/backend')
-rw-r--r--pkg/backend/api.go25
-rw-r--r--pkg/backend/status.go6
2 files changed, 28 insertions, 3 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index f1fed57..d43751b 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -55,10 +55,31 @@ func SwitchOff() {
go stopVPN()
}
-// TODO implement Reconnect - do not tear whole fw down in between
-
func UseLocation(label string) {
+ if ctx.ManualLocation && label == ctx.CurrentLocation {
+ return
+ }
+
ctx.bm.UseGateway(label)
+ go trigger(OnStatusChanged)
+ if label != ctx.CurrentLocation {
+ reconnect()
+ }
+}
+
+func UseAutomaticGateway() {
+ if !ctx.ManualLocation {
+ return
+ }
+
+ ctx.bm.UseAutomaticGateway()
+ go trigger(OnStatusChanged)
+ reconnect()
+}
+
+// TODO implement Reconnect - do not tear whole fw down in between
+
+func reconnect() {
time.Sleep(200 * time.Millisecond)
SwitchOff()
time.Sleep(500 * time.Millisecond)
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index 0e92253..bdbdd35 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -47,17 +47,21 @@ type connectionCtx struct {
Locations map[string]float64 `json:"locations"`
CurrentGateway string `json:"currentGateway"`
CurrentLocation string `json:"currentLocation"`
+ CurrentCountry string `json:"currentCountry"`
+ ManualLocation bool `json:"manualLocation"`
bm bitmask.Bitmask
autostart bitmask.Autostart
cfg *config.Config
}
-func (c connectionCtx) toJson() ([]byte, error) {
+func (c *connectionCtx) toJson() ([]byte, error) {
statusMutex.Lock()
if c.bm != nil {
c.Locations = c.bm.ListLocationFullness("openvpn")
c.CurrentGateway = c.bm.GetCurrentGateway()
c.CurrentLocation = c.bm.GetCurrentLocation()
+ c.CurrentCountry = c.bm.GetCurrentCountry()
+ c.ManualLocation = c.bm.IsManualLocation()
}
defer statusMutex.Unlock()
b, err := json.Marshal(c)