summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-06-22 17:57:29 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-06-22 18:04:48 +0200
commit9f1807c2c053e3b57881d42ebf58ec26dfee1b1d (patch)
tree70abd66546c6ad1f49edfc032eaf9f1cd8ca5d30
parent514a6a8a1f1188a8dd95c79db150711cdc30bc48 (diff)
[bug] populate gateways early on
- Closes: #511
-rw-r--r--pkg/backend/gatewaychecker.go32
-rw-r--r--pkg/backend/init.go1
-rw-r--r--pkg/vpn/main.go3
-rw-r--r--pkg/vpn/openvpn.go9
4 files changed, 44 insertions, 1 deletions
diff --git a/pkg/backend/gatewaychecker.go b/pkg/backend/gatewaychecker.go
new file mode 100644
index 0000000..f10e47e
--- /dev/null
+++ b/pkg/backend/gatewaychecker.go
@@ -0,0 +1,32 @@
+package backend
+
+import (
+ "time"
+)
+
+// The gateway selector gets populated asynchronously, so this spawns a goroutine that
+// checks whether they've been fetched to update status.
+func (c connectionCtx) delayCheckForGateways() {
+ go func() {
+ cnt := 0
+ for {
+ if cnt > 60*2 {
+ break
+ }
+ time.Sleep(time.Second * 5)
+ transport := c.bm.GetTransport()
+ locs := c.bm.ListLocationFullness(transport)
+ if len(locs) != 0 {
+ c.Locations = locs
+ updateStatusForGateways()
+ break
+ }
+ }
+ }()
+}
+
+func updateStatusForGateways() {
+ statusMutex.Lock()
+ defer statusMutex.Unlock()
+ go trigger(OnStatusChanged)
+}
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index 6fb794a..b7469c1 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -35,6 +35,7 @@ func initializeContext(opts *InitOpts) {
go checkErrors(errCh)
initializeBitmask(errCh, opts)
go trigger(OnStatusChanged)
+ ctx.delayCheckForGateways()
}
func checkErrors(errCh chan string) {
diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go
index 826e5d4..3a1f521 100644
--- a/pkg/vpn/main.go
+++ b/pkg/vpn/main.go
@@ -69,8 +69,9 @@ func Init() (*Bitmask, error) {
*/
err = ioutil.WriteFile(b.getTempCaCertPath(), config.CaCert, 0600)
-
+ go b.fetchGateways()
go b.openvpnManagement()
+
return &b, err
}
diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go
index 1a34c22..6682094 100644
--- a/pkg/vpn/openvpn.go
+++ b/pkg/vpn/openvpn.go
@@ -219,6 +219,15 @@ func (b *Bitmask) getCert() (certPath string, err error) {
return certPath, err
}
+// Explicit call to GetGateways, to be able to fetch them all before starting the vpn
+func (b *Bitmask) fetchGateways() {
+ log.Println("Fetching gateways...")
+ _, err := b.bonafide.GetAllGateways(b.transport)
+ if err != nil {
+ log.Println("ERROR Cannot fetch gateways")
+ }
+}
+
// StopVPN or cancel
func (b *Bitmask) StopVPN() error {
err := b.launch.firewallStop()