OSDN Git Service

fix log (#388)
[bytom/vapor.git] / p2p / peer.go
index 11641b8..856d1e9 100644 (file)
@@ -9,7 +9,6 @@ import (
        "github.com/btcsuite/go-socks/socks"
        "github.com/pkg/errors"
        log "github.com/sirupsen/logrus"
-       "github.com/tendermint/go-crypto"
        "github.com/tendermint/go-wire"
        cmn "github.com/tendermint/tmlibs/common"
        "github.com/tendermint/tmlibs/flowrate"
@@ -17,6 +16,7 @@ import (
        cfg "github.com/vapor/config"
        "github.com/vapor/consensus"
        "github.com/vapor/p2p/connection"
+       "github.com/vapor/p2p/signlib"
 )
 
 // peerConn contains the raw connection and its config.
@@ -44,7 +44,7 @@ func DefaultPeerConfig(config *cfg.P2PConfig) *PeerConfig {
                ProxyAddress:     config.ProxyAddress,
                ProxyUsername:    config.ProxyUsername,
                ProxyPassword:    config.ProxyPassword,
-               MConfig:          connection.DefaultMConnConfig(),
+               MConfig:          connection.DefaultMConnConfig(config.Compression),
        }
 }
 
@@ -76,7 +76,7 @@ func newPeer(pc *peerConn, nodeInfo *NodeInfo, reactorsByCh map[byte]Reactor, ch
        p := &Peer{
                peerConn: pc,
                NodeInfo: nodeInfo,
-               Key:      nodeInfo.PubKey.KeyString(),
+               Key:      nodeInfo.PubKey,
                isLAN:    isLAN,
        }
        p.mconn = createMConnection(pc.conn, p, reactorsByCh, chDescs, onPeerError, pc.config.MConfig)
@@ -84,7 +84,7 @@ func newPeer(pc *peerConn, nodeInfo *NodeInfo, reactorsByCh map[byte]Reactor, ch
        return p
 }
 
-func newOutboundPeerConn(addr *NetAddress, ourNodePrivKey crypto.PrivKeyEd25519, config *PeerConfig) (*peerConn, error) {
+func newOutboundPeerConn(addr *NetAddress, ourNodePrivKey signlib.PrivKey, config *PeerConfig) (*peerConn, error) {
        conn, err := dial(addr, config)
        if err != nil {
                return nil, errors.Wrap(err, "Error dial peer")
@@ -98,11 +98,11 @@ func newOutboundPeerConn(addr *NetAddress, ourNodePrivKey crypto.PrivKeyEd25519,
        return pc, nil
 }
 
-func newInboundPeerConn(conn net.Conn, ourNodePrivKey crypto.PrivKeyEd25519, config *cfg.P2PConfig) (*peerConn, error) {
+func newInboundPeerConn(conn net.Conn, ourNodePrivKey signlib.PrivKey, config *cfg.P2PConfig) (*peerConn, error) {
        return newPeerConn(conn, false, ourNodePrivKey, DefaultPeerConfig(config))
 }
 
-func newPeerConn(rawConn net.Conn, outbound bool, ourNodePrivKey crypto.PrivKeyEd25519, config *PeerConfig) (*peerConn, error) {
+func newPeerConn(rawConn net.Conn, outbound bool, ourNodePrivKey signlib.PrivKey, config *PeerConfig) (*peerConn, error) {
        rawConn.SetDeadline(time.Now().Add(config.HandshakeTimeout))
        conn, err := connection.MakeSecretConnection(rawConn, ourNodePrivKey)
        if err != nil {
@@ -195,8 +195,8 @@ func (p *Peer) IsLAN() bool {
 }
 
 // PubKey returns peer's public key.
-func (p *Peer) PubKey() crypto.PubKeyEd25519 {
-       return p.conn.(*connection.SecretConnection).RemotePubKey()
+func (p *Peer) PubKey() string {
+       return p.conn.(*connection.SecretConnection).RemotePubKey().String()
 }
 
 // Send msg to the channel identified by chID byte. Returns false if the send
@@ -239,7 +239,7 @@ func (p *Peer) TrySend(chID byte, msg interface{}) bool {
                "peer":   p.Addr(),
                "msg":    msg,
                "type":   reflect.TypeOf(msg),
-       }).Info("send message to peer")
+       }).Debug("send message to peer")
        return p.mconn.TrySend(chID, msg)
 }