Skip to content

Commit

Permalink
Merge pull request #80 from mysteriumnetwork/fix/node-native-updates
Browse files Browse the repository at this point in the history
Fix/node native updates
  • Loading branch information
Zensey committed Dec 1, 2022
2 parents fff34f0 + 05c5247 commit 4e8ac46
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -29,7 +29,6 @@ jobs:
run: |
go run cmd/resource/resource.go
go build -v -trimpath -ldflags "-s -w -H windowsgui" -o bin/myst-launcher-amd64.exe github.com/mysteriumnetwork/myst-launcher/cmd/app
go build -v -trimpath -ldflags "-s -w -H windowsgui" -o bin/myst-launcher-updater.exe github.com/mysteriumnetwork/myst-launcher/cmd/updater
env:
GOARCH: amd64
GOOS: windows
Expand Down Expand Up @@ -69,7 +68,6 @@ jobs:
with:
prerelease: true
files: |
bin/myst-launcher-updater.exe
installer/myst-launcher-x64.msi
env:
Expand Down
4 changes: 2 additions & 2 deletions cmd/resource/resource.go
Expand Up @@ -19,9 +19,9 @@ import (

var (
// fixed non-string version. used for launcher version checks
intVersion = [4]uint16{1, 0, 37, 0}
intVersion = [4]uint16{1, 0, 38, 0}
// display version
strVersion = "1.0.37"
strVersion = "1.0.38"
)

func getIcon(path string) *winres.Icon {
Expand Down
49 changes: 24 additions & 25 deletions controller/native/install.go
Expand Up @@ -52,67 +52,65 @@ func (c *Controller) CheckAndUpgradeNodeExe(forceUpgrade bool) bool {
cfg.NodeExeVersion = ""
cfg.Save()
}

log.Println("CheckAndUpgradeNodeExe>", cfg, forceUpgrade)
log.Println("CheckAndUpgradeNodeExe >", cfg, cfg.NodeExeVersion, cfg.NeedToCheckUpgrade(), forceUpgrade)

if cfg.NodeExeVersion == "" || cfg.NeedToCheckUpgrade() || forceUpgrade {
ctx := context.Background()
release, err := updates.FetchLatestRelease(ctx, org, repo)
if err != nil {
log.Println("FetchLatestRelease>", err)
return false
log.Println("FetchLatestRelease>", err)
return false
}
tagLatest := release.TagName

mdl.ImageInfo.VersionLatest = tagLatest
mdl.ImageInfo.VersionCurrent = cfg.NodeExeVersion
mdl.ImageInfo.HasUpdate = tagLatest != cfg.NodeExeVersion


cfg.NodeLatestTag = tagLatest

defer func() {
cfg.NodeLatestTag = tagLatest
cfg.NodeExeVersion = tagLatest

cfg.RefreshLastUpgradeCheck()
cfg.Save()
}()

if cfg.NodeExeVersion != tagLatest {
c.lg.Println("Mysterium Node is not up to date")

fullpath := path.Join(c.runner.binpath, exename)
fullpath = utils.MakeCanonicalPath(fullpath)
p, err := utils.IsProcessRunningExt(exename, fullpath)
if err != nil {
// c.lg.Println("IsRunningOrTryStart >", err)
}
p, _ := utils.IsProcessRunningExt(exename, fullpath)
if p != 0 {
utils.TerminateProcess(p, 0)
}

if cfg.AutoUpgrade || sha256 == "" {
c.tryInstall()
err := c.tryInstall(release)
if err != nil {
c.lg.Println("tryInstall >", err)
return false
}

sha256, _ := checksum.SHA256sum(fullpath)
cfg.NodeExeDigest = sha256
cfg.NodeExeVersion = tagLatest
cfg.NodeExeDigest = sha256
}

return true
}

return false
}

return false
}

// returns: will exit
func (c *Controller) tryInstall() bool {
func (c *Controller) tryInstall(release updates.Release) error {
log.Println("tryInstall >")

model := c.a.GetModel()
model.SetStateContainer(model_.RunnableStateInstalling)

ctx := context.Background()
release, _ := updates.FetchLatestRelease(ctx, org, repo)
log.Println("tryInstall >", release)

asset := getAssetName()
for _, v := range release.Assets {
if v.Name != asset {
Expand All @@ -127,18 +125,19 @@ func (c *Controller) tryInstall() bool {
}
})
if err != nil {
c.lg.Println("err>", err)
c.lg.Println("download>", err)
return err
}
if err = extractNodeBinary(fullPath, c.runner.binpath); err != nil {
c.lg.Println(err)
c.lg.Println("extractNodeBinary", err)
return err
}
break
}

ui := c.a.GetUI()
tryInstallFirewallRules(ui)

return false
return nil
}

var once sync.Once
Expand Down
26 changes: 19 additions & 7 deletions model/state.go
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"time"

"github.com/blang/semver/v4"
_const "github.com/mysteriumnetwork/myst-launcher/const"
"github.com/mysteriumnetwork/myst-launcher/utils"
)
Expand Down Expand Up @@ -41,13 +42,13 @@ type Config struct {
InitialState InitialState `json:"state"`

// autoupgrade node
AutoUpgrade bool `json:"auto_upgrade"`
NodeExeDigest string `json:"node_exe_digest"`
NodeExeVersion string `json:"node_exe_version"`
NodeLatestTag string `json:"node_latest_tag"` // cache latest tag
// the last time we checked for upgrade of Myst / Exe, Unix timestamp, [second]
LastUpgradeCheck int64 `json:"last_upgrade_check"` // once a day
Backend string `json:"backend"` // runner: docker | native
AutoUpgrade bool `json:"auto_upgrade"`
NodeExeDigest string `json:"node_exe_digest"`
NodeExeVersion string `json:"node_exe_version"`
NodeLatestTag string `json:"node_latest_tag"` // cache latest tag
LastUpgradeCheck int64 `json:"last_upgrade_check"` // node exe last check, once a day

Backend string `json:"backend"` // runner: docker | native

// Networking mode
EnablePortForwarding bool `json:"enable_port_forwarding"`
Expand Down Expand Up @@ -121,6 +122,17 @@ func (c *Config) getDefaultValues(isNewFile bool) {
}
}
if c.LauncherVersion != prodVersion {

v, _ := semver.Parse(c.LauncherVersion)
v38, _ := semver.Parse("1.0.38")
if v38.Compare(v) > 0 {
// trigger refresh node exe, if previous version was <1.0.38
// there was a node update bug
c.LastUpgradeCheck = 0
c.NodeLatestTag = ""
c.NodeExeVersion = ""
}

c.LauncherVersion = prodVersion
c.Save()
}
Expand Down

0 comments on commit 4e8ac46

Please sign in to comment.