7 "github.com/tendermint/go-crypto"
9 cfg "github.com/bytom/config"
10 "github.com/bytom/version"
13 const maxNodeInfoSize = 10240 // 10Kb
15 //NodeInfo peer node info
16 type NodeInfo struct {
17 PubKey crypto.PubKeyEd25519 `json:"pub_key"`
18 Moniker string `json:"moniker"`
19 Network string `json:"network"`
20 RemoteAddr string `json:"remote_addr"`
21 ListenAddr string `json:"listen_addr"`
22 Version string `json:"version"` // major.minor.revision
23 Other []string `json:"other"` // other application specific data
26 func NewNodeInfo(config *cfg.Config, pubkey crypto.PubKeyEd25519, listenAddr string) *NodeInfo {
29 Moniker: config.Moniker,
30 Network: config.ChainID,
31 ListenAddr: listenAddr,
32 Version: version.Version,
36 // CompatibleWith checks if two NodeInfo are compatible with eachother.
37 // CONTRACT: two nodes are compatible if the major version matches and network match
38 func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
39 compatible, err := version.CompatibleWith(other.Version)
44 return fmt.Errorf("Peer is on a different major version. Peer version: %v, node version: %v", other.Version, info.Version)
47 if info.Network != other.Network {
48 return fmt.Errorf("Peer is on a different network. Peer network: %v, node network: %v", other.Network, info.Network)
53 func (info *NodeInfo) getPubkey() crypto.PubKeyEd25519 {
57 //ListenHost peer listener ip address
58 func (info *NodeInfo) listenHost() string {
59 host, _, _ := net.SplitHostPort(info.ListenAddr)
63 //RemoteAddrHost peer external ip address
64 func (info *NodeInfo) remoteAddrHost() string {
65 host, _, _ := net.SplitHostPort(info.RemoteAddr)
69 //GetNetwork get node info network field
70 func (info *NodeInfo) GetNetwork() string {
74 //String representation
75 func (info NodeInfo) String() string {
76 return fmt.Sprintf("NodeInfo{pk: %v, moniker: %v, network: %v [listen %v], version: %v (%v)}", info.PubKey, info.Moniker, info.Network, info.ListenAddr, info.Version, info.Other)