use in-repo log module for p2p

Signed-off-by: Leo Chen <leo@harmony.one>
pull/183/head
Leo Chen 6 years ago
parent 367589232d
commit 3356c61332
  1. 3
      node/node_handler.go
  2. 14
      p2p/helper.go

@ -208,14 +208,13 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}) {
}
for {
node.log.Debug("Start creating new block")
// threshold and firstTime are for the test-only built-in smart contract tx. TODO: remove in production
threshold := 1
if firstTime {
threshold = 2
firstTime = false
}
node.log.Debug("STARTING BLOCK", "threshold", threshold, "pendingTransactions", len(node.pendingTransactions))
if len(node.pendingTransactions) >= threshold {
// Normal tx block consensus
selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock)

@ -4,8 +4,8 @@ import (
"bufio"
"bytes"
"encoding/binary"
"github.com/harmony-one/harmony/log"
"io"
"log"
"time"
)
@ -38,12 +38,12 @@ func ReadMessageContent(s Stream) ([]byte, error) {
_, err := r.ReadByte()
switch err {
case io.EOF:
log.Printf("Error reading the p2p message type field: %s", err)
log.Error("Error reading the p2p message type field", "msg", err)
return contentBuf.Bytes(), err
case nil:
//log.Printf("Received p2p message type: %x\n", msgType)
default:
log.Printf("Error reading the p2p message type field: %s", err)
log.Error("Error reading the p2p message type field", "msg", err)
return contentBuf.Bytes(), err
}
// TODO: check on msgType and take actions accordingly
@ -51,10 +51,10 @@ func ReadMessageContent(s Stream) ([]byte, error) {
fourBytes := make([]byte, 4)
n, err := r.Read(fourBytes)
if err != nil {
log.Printf("Error reading the p2p message size field")
log.Error("Error reading the p2p message size field")
return contentBuf.Bytes(), err
} else if n < len(fourBytes) {
log.Printf("Failed reading the p2p message size field: only read %d bytes", n)
log.Error("Failed reading the p2p message size field: only read", "Num of bytes", n)
return contentBuf.Bytes(), err
}
//log.Print(fourBytes)
@ -76,7 +76,7 @@ ILOOP:
switch err {
case io.EOF:
// TODO: should we return error here, or just ignore it?
log.Printf("EOF reached while reading p2p message")
log.Error("EOF reached while reading p2p message")
break ILOOP
case nil:
bytesToRead -= uint32(n) // TODO: think about avoid the casting in every loop
@ -84,7 +84,7 @@ ILOOP:
break ILOOP
}
default:
log.Printf("Error reading p2p message")
log.Error("Error reading p2p message")
return []byte{}, err
}
}

Loading…
Cancel
Save