X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=p2p%2Fnode_info.go;h=d0c52a9de7dba7636fb23ac4ed45ab3bb9318127;hb=1362b9a101258e2f2a59f79877231ac6b256f932;hp=5caed49dd64475f5958c4e0528f68796db695f94;hpb=627c2746596ce7cf687cc6afd7c93754510eea63;p=bytom%2Fvapor.git diff --git a/p2p/node_info.go b/p2p/node_info.go index 5caed49d..d0c52a9d 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -4,11 +4,10 @@ import ( "fmt" "net" - "github.com/tendermint/go-crypto" - cfg "github.com/vapor/config" "github.com/vapor/consensus" "github.com/vapor/errors" + "github.com/vapor/p2p/signlib" "github.com/vapor/version" ) @@ -22,9 +21,9 @@ var ( //NodeInfo peer node info type NodeInfo struct { - PubKey crypto.PubKeyEd25519 `json:"pub_key"` - Moniker string `json:"moniker"` - Network string `json:"network"` + PubKey string `json:"pub_key"` + Moniker string `json:"moniker"` + Network string `json:"network"` //NetworkID used to isolate subnets with same network name NetworkID uint64 `json:"network_id"` RemoteAddr string `json:"remote_addr"` @@ -35,9 +34,9 @@ type NodeInfo struct { Other []string `json:"other"` } -func NewNodeInfo(config *cfg.Config, pubkey crypto.PubKeyEd25519, listenAddr string, netID uint64) *NodeInfo { +func NewNodeInfo(config *cfg.Config, pubkey signlib.PubKey, listenAddr string, netID uint64) *NodeInfo { return &NodeInfo{ - PubKey: pubkey, + PubKey: pubkey.String(), Moniker: config.Moniker, Network: config.ChainID, NetworkID: netID, @@ -72,6 +71,14 @@ func (info *NodeInfo) compatibleWith(other *NodeInfo, versionCompatibleWith Vers return nil } +func (info NodeInfo) DoFilter(ip string, pubKey string) error { + if info.PubKey == pubKey { + return ErrConnectSelf + } + + return nil +} + //listenHost peer listener ip address func (info NodeInfo) listenHost() string { host, _, _ := net.SplitHostPort(info.ListenAddr) @@ -79,7 +86,7 @@ func (info NodeInfo) listenHost() string { } //remoteAddrHost peer external ip address -func (info NodeInfo) remoteAddrHost() string { +func (info NodeInfo) RemoteAddrHost() string { host, _, _ := net.SplitHostPort(info.RemoteAddr) return host }