OSDN Git Service

Merge pull request #1832 from Bytom/prod
[bytom/bytom.git] / api / nodeinfo.go
index ccf4c8f..42852e8 100644 (file)
@@ -4,34 +4,44 @@ import (
        "context"
        "net"
 
-       "github.com/bytom/errors"
-       "github.com/bytom/netsync"
-       "github.com/bytom/p2p"
-       "github.com/bytom/version"
+       "github.com/bytom/bytom/errors"
+       "github.com/bytom/bytom/netsync"
+       "github.com/bytom/bytom/p2p"
+       "github.com/bytom/bytom/version"
 )
 
+type VersionInfo struct {
+       Version string `json:"version"`
+       Update  uint16 `json:"update"` // 0: no update; 1: small update; 2: significant update
+       NewVer  string `json:"new_version"`
+}
+
 // NetInfo indicate net information
 type NetInfo struct {
-       Listening    bool   `json:"listening"`
-       Syncing      bool   `json:"syncing"`
-       Mining       bool   `json:"mining"`
-       PeerCount    int    `json:"peer_count"`
-       CurrentBlock uint64 `json:"current_block"`
-       HighestBlock uint64 `json:"highest_block"`
-       NetWorkID    string `json:"network_id"`
-       Version      string `json:"version"`
+       Listening    bool         `json:"listening"`
+       Syncing      bool         `json:"syncing"`
+       Mining       bool         `json:"mining"`
+       PeerCount    int          `json:"peer_count"`
+       CurrentBlock uint64       `json:"current_block"`
+       HighestBlock uint64       `json:"highest_block"`
+       NetWorkID    string       `json:"network_id"`
+       Version      *VersionInfo `json:"version_info"`
 }
 
 // GetNodeInfo return net information
 func (a *API) GetNodeInfo() *NetInfo {
        info := &NetInfo{
-               Listening:    a.sync.Switch().IsListening(),
+               Listening:    a.sync.IsListening(),
                Syncing:      !a.sync.IsCaughtUp(),
                Mining:       a.cpuMiner.IsMining(),
-               PeerCount:    len(a.sync.Switch().Peers().List()),
+               PeerCount:    a.sync.PeerCount(),
                CurrentBlock: a.chain.BestBlockHeight(),
-               NetWorkID:    a.sync.NodeInfo().Network,
-               Version:      version.Version,
+               NetWorkID:    a.sync.GetNetwork(),
+               Version: &VersionInfo{
+                       Version: version.Version,
+                       Update:  version.Status.VersionStatus(),
+                       NewVer:  version.Status.MaxVerSeen(),
+               },
        }
        if bestPeer := a.sync.BestPeer(); bestPeer != nil {
                info.HighestBlock = bestPeer.Height
@@ -66,9 +76,8 @@ func (a *API) connectPeerByIpAndPort(ip string, port uint16) (*netsync.PeerInfo,
        }
 
        addr := p2p.NewNetAddressIPPort(netIp, port)
-       sw := a.sync.Switch()
 
-       if err := sw.DialPeerWithAddress(addr); err != nil {
+       if err := a.sync.DialPeerWithAddress(addr); err != nil {
                return nil, errors.Wrap(err, "can not connect to the address")
        }
        peer := a.getPeerInfoByAddr(addr.String())