[panic] fix ping message panic #617
pull/614/head
Leo Chen 6 years ago committed by GitHub
commit d515b94d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      api/proto/discovery/pingpong.go
  2. 6
      node/node_handler.go

@ -14,11 +14,11 @@ import (
"bytes"
"encoding/gob"
"fmt"
"log"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/proto"
"github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
)
@ -107,7 +107,8 @@ func GetPingMessage(payload []byte) (*PingMessageType, error) {
err := decoder.Decode(ping)
if err != nil {
log.Panic("Can't deserialize Ping message")
utils.GetLogInstance().Error("[GetPingMessage] Decode", "error", err)
return nil, fmt.Errorf("Decode Ping Error")
}
return ping, nil
@ -124,7 +125,8 @@ func GetPongMessage(payload []byte) (*PongMessageType, error) {
err := decoder.Decode(pong)
if err != nil {
log.Panic("Can't deserialize Pong message")
utils.GetLogInstance().Error("[GetPongMessage] Decode", "error", err)
return nil, fmt.Errorf("Decode Pong Error")
}
return pong, nil
@ -138,7 +140,7 @@ func (p PingMessageType) ConstructPingMessage() []byte {
encoder := gob.NewEncoder(byteBuffer)
err := encoder.Encode(p)
if err != nil {
log.Panic("Can't serialize Ping message", "error:", err)
utils.GetLogInstance().Error("[ConstructPingMessage] Encode", "error", err)
return nil
}
return byteBuffer.Bytes()
@ -152,7 +154,7 @@ func (p PongMessageType) ConstructPongMessage() []byte {
encoder := gob.NewEncoder(byteBuffer)
err := encoder.Encode(p)
if err != nil {
log.Panic("Can't serialize Pong message", "error:", err)
utils.GetLogInstance().Error("[ConstructPongMessage] Encode", "error", err)
return nil
}
return byteBuffer.Bytes()

@ -358,7 +358,7 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int {
ping, err := proto_discovery.GetPingMessage(msgPayload)
if err != nil {
utils.GetLogInstance().Error("Can't get Ping Message")
utils.GetLogInstance().Error("Can't get Ping Message", "error", err)
return -1
}
@ -429,7 +429,7 @@ func (node *Node) SendPongMessage() {
utils.GetLogInstance().Error("[PONG] failed to send pong message", "group", node.NodeConfig.GetShardGroupID())
continue
} else {
utils.GetLogInstance().Info("[PONG] sent pong message to", "group", node.NodeConfig.GetShardGroupID())
utils.GetLogInstance().Info("[PONG] sent pong message to", "group", node.NodeConfig.GetShardGroupID(), "# nodes", numPeersNow)
}
sentMessage = true
// stop sending ping message
@ -448,7 +448,7 @@ func (node *Node) SendPongMessage() {
func (node *Node) pongMessageHandler(msgPayload []byte) int {
pong, err := proto_discovery.GetPongMessage(msgPayload)
if err != nil {
utils.GetLogInstance().Error("Can't get Pong Message")
utils.GetLogInstance().Error("Can't get Pong Message", "error", err)
return -1
}

Loading…
Cancel
Save