OSDN Git Service

rename (#465)
[bytom/vapor.git] / p2p / node_info.go
index 5caed49..be26e6d 100644 (file)
@@ -4,12 +4,11 @@ import (
        "fmt"
        "net"
 
-       "github.com/tendermint/go-crypto"
-
-       cfg "github.com/vapor/config"
-       "github.com/vapor/consensus"
-       "github.com/vapor/errors"
-       "github.com/vapor/version"
+       cfg "github.com/bytom/vapor/config"
+       "github.com/bytom/vapor/consensus"
+       "github.com/bytom/vapor/errors"
+       "github.com/bytom/vapor/p2p/signlib"
+       "github.com/bytom/vapor/version"
 )
 
 const maxNodeInfoSize = 10240 // 10Kb
@@ -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
 }