9 crypto "github.com/tendermint/go-crypto"
12 const maxNodeInfoSize = 10240 // 10Kb
14 //NodeInfo peer node info
15 type NodeInfo struct {
16 PubKey crypto.PubKeyEd25519 `json:"pub_key"`
17 Moniker string `json:"moniker"`
18 Network string `json:"network"`
19 RemoteAddr string `json:"remote_addr"`
20 ListenAddr string `json:"listen_addr"`
21 Version string `json:"version"` // major.minor.revision
22 Other []string `json:"other"` // other application specific data
25 // CompatibleWith checks if two NodeInfo are compatible with eachother.
26 // CONTRACT: two nodes are compatible if the major version matches and network match
27 // and they have at least one channel in common.
28 func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
29 iMajor, _, _, err := splitVersion(info.Version)
33 oMajor, _, _, err := splitVersion(other.Version)
38 return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oMajor, iMajor)
41 if info.Network != other.Network {
42 return fmt.Errorf("Peer is on a different network. Got %v, expected %v", other.Network, info.Network)
47 //ListenHost peer listener ip address
48 func (info *NodeInfo) ListenHost() string {
49 host, _, _ := net.SplitHostPort(info.ListenAddr)
53 //ListenPort peer listener port
54 func (info *NodeInfo) ListenPort() int {
55 _, port, _ := net.SplitHostPort(info.ListenAddr)
56 portInt, err := strconv.Atoi(port)
63 //RemoteAddrHost peer external ip address
64 func (info *NodeInfo) RemoteAddrHost() string {
65 host, _, _ := net.SplitHostPort(info.RemoteAddr)
69 //String representation
70 func (info NodeInfo) String() string {
71 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)
74 func splitVersion(version string) (string, string, string, error) {
75 spl := strings.Split(version, ".")
77 return "", "", "", fmt.Errorf("Invalid version format %v", version)
79 return spl[0], spl[1], spl[2], nil