4 gover "github.com/hashicorp/go-version"
5 log "github.com/sirupsen/logrus"
6 "gopkg.in/fatih/set.v0"
11 noUpdate uint16 = iota
17 // The full version string
19 // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
26 Version += "-" + GitCommit[:8]
28 Status = &UpdateStatus{
30 versionStatus: noUpdate,
35 type UpdateStatus struct {
42 func (s *UpdateStatus) AddSeed(seedAddr string) {
45 s.seedSet.Add(seedAddr)
48 // CheckUpdate checks whether there is a newer version to update.
49 // If there is, it set the "Status" variable to a proper value.
51 // localVerStr: the version of the node itself
52 // remoteVerStr: the version received from a seed node.
53 // remoteAddr: the version received from a seed node.
55 // 1. small update: seed version is higher than the node itself
56 // 2. significant update: seed mojor version is higher than the node itself
57 func (s *UpdateStatus) CheckUpdate(localVerStr string, remoteVerStr string, remoteAddr string) error {
61 if s.notified || !s.seedSet.Has(remoteAddr) {
65 localVersion, err := gover.NewVersion(localVerStr)
69 remoteVersion, err := gover.NewVersion(remoteVerStr)
73 if remoteVersion.GreaterThan(localVersion) {
74 s.versionStatus = hasUpdate
76 if remoteVersion.Segments()[0] > localVersion.Segments()[0] {
77 s.versionStatus = hasMUpdate
79 if s.versionStatus != noUpdate {
80 log.WithFields(log.Fields{
81 "Current version": localVerStr,
82 "Newer version": remoteVerStr,
84 }).Warn("Please update your bytomd via https://github.com/Bytom/bytom/releases/ or http://bytom.io/wallet/")
90 func (s *UpdateStatus) VersionStatus() uint16 {
93 return s.versionStatus
96 // CompatibleWith checks whether the remote peer version is compatible with the
101 // | 1.0.3 | same major&moinor version. |
102 // | 1.0.4 | same major version. |
103 func CompatibleWith(remoteVerStr string) (bool, error) {
104 localVersion, err := gover.NewVersion(Version)
108 remoteVersion, err := gover.NewVersion(remoteVerStr)
112 return (localVersion.Segments()[0] == remoteVersion.Segments()[0]), nil