diff options
| author | kali kaneko (leap communications) <kali@leap.se> | 2021-12-23 00:43:29 +0100 |
|---|---|---|
| committer | kali kaneko (leap communications) <kali@leap.se> | 2021-12-23 00:43:40 +0100 |
| commit | bddadc7323d6467f5233f26b97652fe671d77eed (patch) | |
| tree | 7f5aba2a33e852a2be04ff3e6bbd0383376d91f1 /pkg/backend | |
| parent | d83fd91d6293386867cc908f05b5f3f4d95a7053 (diff) | |
[ui] expose bonafide+snowflake bootstrap events
Diffstat (limited to 'pkg/backend')
| -rw-r--r-- | pkg/backend/api.go | 1 | ||||
| -rw-r--r-- | pkg/backend/status.go | 82 |
2 files changed, 52 insertions, 31 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go index ba07adf..02aa383 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -37,6 +37,7 @@ func Login(username, password string) { ctx.LoginDialog = true ctx.Errors = "bad_auth" } + // XXX shouldn't this be statusChanged? go ctx.updateStatus() } diff --git a/pkg/backend/status.go b/pkg/backend/status.go index de6364f..f6b195c 100644 --- a/pkg/backend/status.go +++ b/pkg/backend/status.go @@ -33,36 +33,38 @@ 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"` - Locations map[string]float64 `json:"locations"` - LocationLabels map[string][]string `json:"locationLabels"` - CurrentGateway string `json:"currentGateway"` - CurrentLocation string `json:"currentLocation"` - CurrentCountry string `json:"currentCountry"` - BestLocation string `json:"bestLocation"` - Transport string `json:"transport"` - UseUDP bool `json:"udp"` - OffersUDP bool `json:"offersUdp"` - ManualLocation bool `json:"manualLocation"` - IsReady bool `json:"isReady"` - CanUpgrade bool `json:"canUpgrade"` - Motd string `json:"motd"` - HasTor bool `json:"hasTor"` - UseSnowflake bool `json:"snowflake"` - bm bitmask.Bitmask - autostart bitmask.Autostart - cfg *config.Config + 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"` + LocationLabels map[string][]string `json:"locationLabels"` + CurrentGateway string `json:"currentGateway"` + CurrentLocation string `json:"currentLocation"` + CurrentCountry string `json:"currentCountry"` + BestLocation string `json:"bestLocation"` + Transport string `json:"transport"` + UseUDP bool `json:"udp"` + OffersUDP bool `json:"offersUdp"` + ManualLocation bool `json:"manualLocation"` + IsReady bool `json:"isReady"` + CanUpgrade bool `json:"canUpgrade"` + Motd string `json:"motd"` + HasTor bool `json:"hasTor"` + UseSnowflake bool `json:"snowflake"` + SnowflakeProgress int `json:"snowflakeProgress"` + SnowflakeTag string `json:"snowflakeTag"` + bm bitmask.Bitmask + autostart bitmask.Autostart + cfg *config.Config } func (c *connectionCtx) toJson() ([]byte, error) { @@ -78,7 +80,7 @@ func (c *connectionCtx) toJson() ([]byte, error) { c.Transport = transport c.UseUDP = c.cfg.UDP // TODO initialize bitmask param? c.OffersUDP = c.bm.OffersUDP() - c.UseSnowflake = c.cfg.Snowflake // TODO initialize bitmask param? + c.UseSnowflake = c.cfg.Snowflake // TODO initialize bitmask c.ManualLocation = c.bm.IsManualLocation() c.CanUpgrade = c.bm.CanUpgrade() c.Motd = c.bm.GetMotd() @@ -102,6 +104,16 @@ func (c connectionCtx) updateStatus() { setStatusFromStr(stStr) } + go func() { + snowflakeCh := c.bm.GetSnowflakeCh() + for { + select { + case event := <-snowflakeCh: + setSnowflakeStatus(event) + } + } + }() + statusCh := c.bm.GetStatusCh() for { select { @@ -111,6 +123,14 @@ func (c connectionCtx) updateStatus() { } } +func setSnowflakeStatus(event *snowflake.StatusEvent) { + statusMutex.Lock() + defer statusMutex.Unlock() + ctx.SnowflakeProgress = event.Progress + ctx.SnowflakeTag = event.Tag + go trigger(OnStatusChanged) +} + func setStatus(st status) { statusMutex.Lock() defer statusMutex.Unlock() |
