Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions p2p/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rlp"
)
Expand Down Expand Up @@ -64,9 +65,11 @@ func (msg Msg) String() string {
}

// Discard reads any remaining payload data into a black hole.
func (msg Msg) Discard() error {
func (msg Msg) Discard() {
_, err := io.Copy(io.Discard, msg.Payload)
return err
if err != nil {
log.Error("[p2p] discard msg", "code", msg.Code, "size", msg.Size, "err", err)
}
}

func (msg Msg) Time() time.Time {
Expand Down Expand Up @@ -233,7 +236,8 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error {
return fmt.Errorf("message code mismatch: got %d, expected %d", msg.Code, code)
}
if content == nil {
return msg.Discard()
msg.Discard()
return nil
}
contentEnc, err := rlp.EncodeToBytes(content)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ func (p *Peer) handle(msg Msg) error {
return decodeDisconnectMessage(msg.Payload)
case msg.Code < baseProtocolLength:
// ignore other base protocol messages
return msg.Discard()
msg.Discard()
return nil
default:
// it's a subprotocol message
proto, err := p.getProto(msg.Code)
Expand Down
4 changes: 1 addition & 3 deletions p2p/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ var discard = Protocol{
return err
}
fmt.Printf("discarding %d\n", msg.Code)
if err = msg.Discard(); err != nil {
return err
}
msg.Discard()
}
},
}
Expand Down
Loading