From 9ff55ac02c9498f265591fcc78f282f4e264459c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 24 Oct 2019 13:10:10 +0300 Subject: [PATCH] network: move inventory semantic check into common code As per @volekerb suggestion. --- pkg/network/server.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index b164a3e79..f5efc4fac 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -279,18 +279,12 @@ func (s *Server) handleBlockCmd(p Peer, block *core.Block) error { // handleInvCmd processes the received inventory. func (s *Server) handleInvCmd(p Peer, inv *payload.Inventory) error { - if !inv.Type.Valid() || len(inv.Hashes) == 0 { - return errInvalidInvType - } payload := payload.NewInventory(inv.Type, inv.Hashes) return p.WriteMsg(NewMessage(s.Net, CMDGetData, payload)) } // handleInvCmd processes the received inventory. func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error { - if !inv.Type.Valid() || len(inv.Hashes) == 0 { - return errInvalidInvType - } switch inv.Type { case payload.TXType: for _, hash := range inv.Hashes { @@ -383,6 +377,11 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error { } if peer.Handshaked() { + if inv, ok := msg.Payload.(*payload.Inventory); ok { + if !inv.Type.Valid() || len(inv.Hashes) == 0 { + return errInvalidInvType + } + } switch msg.CommandType() { case CMDAddr: addrs := msg.Payload.(*payload.AddressList)