mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
parent
f46ed798f0
commit
db5b42b601
4 changed files with 15 additions and 7 deletions
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type=CommandType
|
//go:generate stringer -type=CommandType -output=message_string.go
|
||||||
|
|
||||||
// CompressionMinSize is the lower bound to apply compression.
|
// CompressionMinSize is the lower bound to apply compression.
|
||||||
const CompressionMinSize = 1024
|
const CompressionMinSize = 1024
|
||||||
|
@ -68,7 +68,7 @@ const (
|
||||||
CMDInv CommandType = 0x27
|
CMDInv CommandType = 0x27
|
||||||
CMDGetData CommandType = 0x28
|
CMDGetData CommandType = 0x28
|
||||||
CMDGetBlockData CommandType = 0x29
|
CMDGetBlockData CommandType = 0x29
|
||||||
CMDUnknown CommandType = 0x2a
|
CMDNotFound CommandType = 0x2a
|
||||||
CMDTX = CommandType(payload.TXType)
|
CMDTX = CommandType(payload.TXType)
|
||||||
CMDBlock = CommandType(payload.BlockType)
|
CMDBlock = CommandType(payload.BlockType)
|
||||||
CMDConsensus = CommandType(payload.ConsensusType)
|
CMDConsensus = CommandType(payload.ConsensusType)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Code generated by "stringer -type=CommandType"; DO NOT EDIT.
|
// Code generated by "stringer -type=CommandType -output=message_string.go"; DO NOT EDIT.
|
||||||
|
|
||||||
package network
|
package network
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func _() {
|
||||||
_ = x[CMDInv-39]
|
_ = x[CMDInv-39]
|
||||||
_ = x[CMDGetData-40]
|
_ = x[CMDGetData-40]
|
||||||
_ = x[CMDGetBlockData-41]
|
_ = x[CMDGetBlockData-41]
|
||||||
_ = x[CMDUnknown-42]
|
_ = x[CMDNotFound-42]
|
||||||
_ = x[CMDTX-43]
|
_ = x[CMDTX-43]
|
||||||
_ = x[CMDBlock-44]
|
_ = x[CMDBlock-44]
|
||||||
_ = x[CMDConsensus-45]
|
_ = x[CMDConsensus-45]
|
||||||
|
@ -39,7 +39,7 @@ const (
|
||||||
_CommandType_name_2 = "CMDPingCMDPong"
|
_CommandType_name_2 = "CMDPingCMDPong"
|
||||||
_CommandType_name_3 = "CMDGetHeadersCMDHeaders"
|
_CommandType_name_3 = "CMDGetHeadersCMDHeaders"
|
||||||
_CommandType_name_4 = "CMDGetBlocksCMDMempool"
|
_CommandType_name_4 = "CMDGetBlocksCMDMempool"
|
||||||
_CommandType_name_5 = "CMDInvCMDGetDataCMDGetBlockDataCMDUnknownCMDTXCMDBlockCMDConsensus"
|
_CommandType_name_5 = "CMDInvCMDGetDataCMDGetBlockDataCMDNotFoundCMDTXCMDBlockCMDConsensus"
|
||||||
_CommandType_name_6 = "CMDRejectCMDFilterLoadCMDFilterAddCMDFilterClear"
|
_CommandType_name_6 = "CMDRejectCMDFilterLoadCMDFilterAddCMDFilterClear"
|
||||||
_CommandType_name_7 = "CMDMerkleBlock"
|
_CommandType_name_7 = "CMDMerkleBlock"
|
||||||
_CommandType_name_8 = "CMDAlert"
|
_CommandType_name_8 = "CMDAlert"
|
||||||
|
@ -51,7 +51,7 @@ var (
|
||||||
_CommandType_index_2 = [...]uint8{0, 7, 14}
|
_CommandType_index_2 = [...]uint8{0, 7, 14}
|
||||||
_CommandType_index_3 = [...]uint8{0, 13, 23}
|
_CommandType_index_3 = [...]uint8{0, 13, 23}
|
||||||
_CommandType_index_4 = [...]uint8{0, 12, 22}
|
_CommandType_index_4 = [...]uint8{0, 12, 22}
|
||||||
_CommandType_index_5 = [...]uint8{0, 6, 16, 31, 41, 46, 54, 66}
|
_CommandType_index_5 = [...]uint8{0, 6, 16, 31, 42, 47, 55, 67}
|
||||||
_CommandType_index_6 = [...]uint8{0, 9, 22, 34, 48}
|
_CommandType_index_6 = [...]uint8{0, 9, 22, 34, 48}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ func NewInventory(typ InventoryType, hashes []util.Uint256) *Inventory {
|
||||||
// DecodeBinary implements Serializable interface.
|
// DecodeBinary implements Serializable interface.
|
||||||
func (p *Inventory) DecodeBinary(br *io.BinReader) {
|
func (p *Inventory) DecodeBinary(br *io.BinReader) {
|
||||||
p.Type = InventoryType(br.ReadB())
|
p.Type = InventoryType(br.ReadB())
|
||||||
br.ReadArray(&p.Hashes)
|
br.ReadArray(&p.Hashes, MaxHashesCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeBinary implements Serializable interface.
|
// EncodeBinary implements Serializable interface.
|
||||||
|
|
|
@ -538,6 +538,7 @@ func (s *Server) handleMempoolCmd(p Peer) error {
|
||||||
|
|
||||||
// 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 {
|
||||||
|
var notFound []util.Uint256
|
||||||
for _, hash := range inv.Hashes {
|
for _, hash := range inv.Hashes {
|
||||||
var msg *Message
|
var msg *Message
|
||||||
|
|
||||||
|
@ -546,11 +547,15 @@ func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
|
||||||
tx, _, err := s.chain.GetTransaction(hash)
|
tx, _, err := s.chain.GetTransaction(hash)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
msg = NewMessage(CMDTX, tx)
|
msg = NewMessage(CMDTX, tx)
|
||||||
|
} else {
|
||||||
|
notFound = append(notFound, hash)
|
||||||
}
|
}
|
||||||
case payload.BlockType:
|
case payload.BlockType:
|
||||||
b, err := s.chain.GetBlock(hash)
|
b, err := s.chain.GetBlock(hash)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
msg = NewMessage(CMDBlock, b)
|
msg = NewMessage(CMDBlock, b)
|
||||||
|
} else {
|
||||||
|
notFound = append(notFound, hash)
|
||||||
}
|
}
|
||||||
case payload.ConsensusType:
|
case payload.ConsensusType:
|
||||||
if cp := s.consensus.GetPayload(hash); cp != nil {
|
if cp := s.consensus.GetPayload(hash); cp != nil {
|
||||||
|
@ -571,6 +576,9 @@ func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(notFound) != 0 {
|
||||||
|
return p.EnqueueP2PMessage(NewMessage(CMDNotFound, payload.NewInventory(inv.Type, notFound)))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue