Unverified Commit 9f1807c2 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[bug] populate gateways early on

- Closes: #511
parent 514a6a8a
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)
}
......@@ -35,6 +35,7 @@ func initializeContext(opts *InitOpts) {
go checkErrors(errCh)
initializeBitmask(errCh, opts)
go trigger(OnStatusChanged)
ctx.delayCheckForGateways()
}
func checkErrors(errCh chan string) {
......
......@@ -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
}
......
......@@ -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()
......
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