8 crypto "github.com/tendermint/go-crypto"
10 "github.com/vapor/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 // CompatibleWith checks if two NodeInfo are compatible with eachother.
27 // CONTRACT: two nodes are compatible if the major version matches and network match
28 func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
29 compatible, err := version.CompatibleWith(other.Version)
34 return fmt.Errorf("Peer is on a different major version. Peer version: %v, node version: %v", other.Version, info.Version)
37 if info.Network != other.Network {
38 return fmt.Errorf("Peer is on a different network. Peer network: %v, node network: %v", other.Network, info.Network)
43 //ListenHost peer listener ip address
44 func (info *NodeInfo) ListenHost() string {
45 host, _, _ := net.SplitHostPort(info.ListenAddr)
49 //ListenPort peer listener port
50 func (info *NodeInfo) ListenPort() int {
51 _, port, _ := net.SplitHostPort(info.ListenAddr)
52 portInt, err := strconv.Atoi(port)
59 //RemoteAddrHost peer external ip address
60 func (info *NodeInfo) RemoteAddrHost() string {
61 host, _, _ := net.SplitHostPort(info.RemoteAddr)
65 //String representation
66 func (info NodeInfo) String() string {
67 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)