forked from TrueCloudLab/neoneo-go
network: move inventory semantic check into common code
As per @volekerb suggestion.
This commit is contained in:
parent
45cac07643
commit
9ff55ac02c
1 changed files with 5 additions and 6 deletions
|
@ -279,18 +279,12 @@ func (s *Server) handleBlockCmd(p Peer, block *core.Block) error {
|
||||||
|
|
||||||
// handleInvCmd processes the received inventory.
|
// handleInvCmd processes the received inventory.
|
||||||
func (s *Server) handleInvCmd(p Peer, inv *payload.Inventory) error {
|
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)
|
payload := payload.NewInventory(inv.Type, inv.Hashes)
|
||||||
return p.WriteMsg(NewMessage(s.Net, CMDGetData, payload))
|
return p.WriteMsg(NewMessage(s.Net, CMDGetData, payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleInvCmd processes the received inventory.
|
// handleInvCmd processes the received inventory.
|
||||||
func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
|
func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
|
||||||
if !inv.Type.Valid() || len(inv.Hashes) == 0 {
|
|
||||||
return errInvalidInvType
|
|
||||||
}
|
|
||||||
switch inv.Type {
|
switch inv.Type {
|
||||||
case payload.TXType:
|
case payload.TXType:
|
||||||
for _, hash := range inv.Hashes {
|
for _, hash := range inv.Hashes {
|
||||||
|
@ -383,6 +377,11 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if peer.Handshaked() {
|
if peer.Handshaked() {
|
||||||
|
if inv, ok := msg.Payload.(*payload.Inventory); ok {
|
||||||
|
if !inv.Type.Valid() || len(inv.Hashes) == 0 {
|
||||||
|
return errInvalidInvType
|
||||||
|
}
|
||||||
|
}
|
||||||
switch msg.CommandType() {
|
switch msg.CommandType() {
|
||||||
case CMDAddr:
|
case CMDAddr:
|
||||||
addrs := msg.Payload.(*payload.AddressList)
|
addrs := msg.Payload.(*payload.AddressList)
|
||||||
|
|
Loading…
Reference in a new issue