[panic] fix ping message panic #617

Signed-off-by: Leo Chen <leo@harmony.one>
pull/618/head
Leo Chen 6 years ago
parent ccf0573523
commit 478a25533e
  1. 12
      api/proto/discovery/pingpong.go
  2. 4
      node/node_handler.go

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

@ -358,7 +358,7 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int {
ping, err := proto_discovery.GetPingMessage(msgPayload) ping, err := proto_discovery.GetPingMessage(msgPayload)
if err != nil { if err != nil {
utils.GetLogInstance().Error("Can't get Ping Message") utils.GetLogInstance().Error("Can't get Ping Message", "error", err)
return -1 return -1
} }
@ -448,7 +448,7 @@ func (node *Node) SendPongMessage() {
func (node *Node) pongMessageHandler(msgPayload []byte) int { func (node *Node) pongMessageHandler(msgPayload []byte) int {
pong, err := proto_discovery.GetPongMessage(msgPayload) pong, err := proto_discovery.GetPongMessage(msgPayload)
if err != nil { if err != nil {
utils.GetLogInstance().Error("Can't get Pong Message") utils.GetLogInstance().Error("Can't get Pong Message", "error", err)
return -1 return -1
} }

Loading…
Cancel
Save