From 591c6fbece9a8beca1cbd397d047570f537137d5 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 26 Aug 2019 00:58:49 -0700 Subject: [PATCH] [ping] display blskey in ping message Signed-off-by: Leo Chen --- api/service/discovery/service.go | 2 -- node/node_handler.go | 33 +++++++++++++++----------------- p2p/host/hostv2/hostv2.go | 1 + p2p/p2pimpl/p2pimpl.go | 1 + 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/api/service/discovery/service.go b/api/service/discovery/service.go index 4b460931d..5ad433bc3 100644 --- a/api/service/discovery/service.go +++ b/api/service/discovery/service.go @@ -85,7 +85,6 @@ func (s *Service) contactP2pPeers() { msgBuf := host.ConstructP2pMessage(byte(0), pingMsg.ConstructPingMessage()) s.sentPingMessage(s.config.ShardGroupID, msgBuf) - utils.Logger().Info().Interface("[PING]", pingMsg).Msg("Sent Ping Message") for { select { @@ -106,7 +105,6 @@ func (s *Service) contactP2pPeers() { } s.sentPingMessage(s.config.ShardGroupID, msgBuf) - utils.Logger().Info().Interface("[PING]", pingMsg).Msg("Sent Ping Message") // the longest sleep is 3600 seconds if pingInterval >= 3600 { diff --git a/node/node_handler.go b/node/node_handler.go index 152e5808c..b3e878ae0 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -724,20 +724,6 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender libp2p_peer.ID) i peer.PeerID = ping.Node.PeerID peer.ConsensusPubKey = nil - utils.Logger().Info(). - Str("Peer Version", ping.NodeVer). - Interface("PeerID", peer). - Msg("[PING] received ping message") - - senderStr := string(sender) - if senderStr != "" { - _, ok := node.duplicatedPing.LoadOrStore(senderStr, true) - if ok { - // duplicated ping message return - return 0 - } - } - if ping.Node.PubKey != nil { peer.ConsensusPubKey = &bls.PublicKey{} if err := peer.ConsensusPubKey.Deserialize(ping.Node.PubKey[:]); err != nil { @@ -748,10 +734,21 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender libp2p_peer.ID) i } } - var k types.BlsPublicKey - if err := k.FromLibBLSPublicKey(peer.ConsensusPubKey); err != nil { - err = ctxerror.New("cannot convert BLS public key").WithCause(err) - ctxerror.Log15(utils.GetLogger().Warn, err) + utils.Logger().Info(). + Str("Version", ping.NodeVer). + Str("BlsKey", peer.ConsensusPubKey.SerializeToHexStr()). + Str("IP", peer.IP). + Str("Port", peer.Port). + Interface("PeerID", peer.PeerID). + Msg("[PING] PeerInfo") + + senderStr := string(sender) + if senderStr != "" { + _, ok := node.duplicatedPing.LoadOrStore(senderStr, true) + if ok { + // duplicated ping message return + return 0 + } } // add to incoming peer list diff --git a/p2p/host/hostv2/hostv2.go b/p2p/host/hostv2/hostv2.go index a69338261..9b67bf718 100644 --- a/p2p/host/hostv2/hostv2.go +++ b/p2p/host/hostv2/hostv2.go @@ -189,6 +189,7 @@ func New(self *p2p.Peer, priKey libp2p_crypto.PrivKey) *HostV2 { Str("port", self.Port). Str("id", p2pHost.ID().Pretty()). Str("addr", listenAddr.String()). + Str("PubKey", self.ConsensusPubKey.SerializeToHexStr()). Msg("HostV2 is up!") return h diff --git a/p2p/p2pimpl/p2pimpl.go b/p2p/p2pimpl/p2pimpl.go index 5ac784db4..5ab300ef2 100644 --- a/p2p/p2pimpl/p2pimpl.go +++ b/p2p/p2pimpl/p2pimpl.go @@ -19,6 +19,7 @@ func NewHost(self *p2p.Peer, key libp2p_crypto.PrivKey) (p2p.Host, error) { utils.Logger().Info(). Str("self", net.JoinHostPort(self.IP, self.Port)). Interface("PeerID", self.PeerID). + Str("PubKey", self.ConsensusPubKey.SerializeToHexStr()). Msg("NewHost") return h, nil