X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=p2p%2Fnode_info.go;fp=p2p%2Fnode_info.go;h=0000000000000000000000000000000000000000;hp=61606b5f7467db3ac3094bc049a17523ebe64b38;hb=d09b7a78d44dc259725902b8141cdba0d716b121;hpb=ee01d543fdfe1fd0a4d548965c66f7923ea7b062 diff --git a/p2p/node_info.go b/p2p/node_info.go deleted file mode 100644 index 61606b5f..00000000 --- a/p2p/node_info.go +++ /dev/null @@ -1,68 +0,0 @@ -package p2p - -import ( - "fmt" - "net" - "strconv" - - crypto "github.com/tendermint/go-crypto" - - "github.com/vapor/version" -) - -const maxNodeInfoSize = 10240 // 10Kb - -//NodeInfo peer node info -type NodeInfo struct { - PubKey crypto.PubKeyEd25519 `json:"pub_key"` - Moniker string `json:"moniker"` - Network string `json:"network"` - RemoteAddr string `json:"remote_addr"` - ListenAddr string `json:"listen_addr"` - Version string `json:"version"` // major.minor.revision - Other []string `json:"other"` // other application specific data -} - -// CompatibleWith checks if two NodeInfo are compatible with eachother. -// CONTRACT: two nodes are compatible if the major version matches and network match -func (info *NodeInfo) CompatibleWith(other *NodeInfo) error { - compatible, err := version.CompatibleWith(other.Version) - if err != nil { - return err - } - if !compatible { - return fmt.Errorf("Peer is on a different major version. Peer version: %v, node version: %v", other.Version, info.Version) - } - - if info.Network != other.Network { - return fmt.Errorf("Peer is on a different network. Peer network: %v, node network: %v", other.Network, info.Network) - } - return nil -} - -//ListenHost peer listener ip address -func (info *NodeInfo) ListenHost() string { - host, _, _ := net.SplitHostPort(info.ListenAddr) - return host -} - -//ListenPort peer listener port -func (info *NodeInfo) ListenPort() int { - _, port, _ := net.SplitHostPort(info.ListenAddr) - portInt, err := strconv.Atoi(port) - if err != nil { - return -1 - } - return portInt -} - -//RemoteAddrHost peer external ip address -func (info *NodeInfo) RemoteAddrHost() string { - host, _, _ := net.SplitHostPort(info.RemoteAddr) - return host -} - -//String representation -func (info NodeInfo) String() string { - 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) -}