summaryrefslogtreecommitdiff
path: root/pkg/backend/api.go
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2021-03-31 18:14:20 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-05-04 14:58:39 +0200
commit2e7702904813dbdbfb2f1fa24979e80222bb2e27 (patch)
tree51abb39edc6641f36779f936ba876dba57123f2f /pkg/backend/api.go
parentaae83bfac7005e303193acaef7b69497a0f323c0 (diff)
Add a proper reconnection mechanism
Diffstat (limited to 'pkg/backend/api.go')
-rw-r--r--pkg/backend/api.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index d43751b..60d51f3 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -7,7 +7,7 @@ import (
"encoding/json"
"log"
"strconv"
- "time"
+ "strings"
"unsafe"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
@@ -62,8 +62,8 @@ func UseLocation(label string) {
ctx.bm.UseGateway(label)
go trigger(OnStatusChanged)
- if label != ctx.CurrentLocation {
- reconnect()
+ if ctx.Status == on && label != strings.ToLower(ctx.CurrentLocation) {
+ ctx.bm.Reconnect()
}
}
@@ -74,16 +74,9 @@ func UseAutomaticGateway() {
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)
- SwitchOn()
+ if ctx.Status == on {
+ ctx.bm.Reconnect()
+ }
}
func UseTransport(label string) {