forked from TrueCloudLab/neoneo-go
network: rename GetBlockData command
GetBlockData -> GetBlockByIndex
This commit is contained in:
parent
7c6cdcbcc9
commit
737ba700e9
5 changed files with 35 additions and 35 deletions
|
@ -61,18 +61,18 @@ const (
|
||||||
CMDPong CommandType = 0x19
|
CMDPong CommandType = 0x19
|
||||||
|
|
||||||
// synchronization
|
// synchronization
|
||||||
CMDGetHeaders CommandType = 0x20
|
CMDGetHeaders CommandType = 0x20
|
||||||
CMDHeaders CommandType = 0x21
|
CMDHeaders CommandType = 0x21
|
||||||
CMDGetBlocks CommandType = 0x24
|
CMDGetBlocks CommandType = 0x24
|
||||||
CMDMempool CommandType = 0x25
|
CMDMempool CommandType = 0x25
|
||||||
CMDInv CommandType = 0x27
|
CMDInv CommandType = 0x27
|
||||||
CMDGetData CommandType = 0x28
|
CMDGetData CommandType = 0x28
|
||||||
CMDGetBlockData CommandType = 0x29
|
CMDGetBlockByIndex CommandType = 0x29
|
||||||
CMDNotFound 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)
|
||||||
CMDReject CommandType = 0x2f
|
CMDReject CommandType = 0x2f
|
||||||
|
|
||||||
// SPV protocol
|
// SPV protocol
|
||||||
CMDFilterLoad CommandType = 0x30
|
CMDFilterLoad CommandType = 0x30
|
||||||
|
@ -149,8 +149,8 @@ func (m *Message) decodePayload() error {
|
||||||
fallthrough
|
fallthrough
|
||||||
case CMDGetHeaders:
|
case CMDGetHeaders:
|
||||||
p = &payload.GetBlocks{}
|
p = &payload.GetBlocks{}
|
||||||
case CMDGetBlockData:
|
case CMDGetBlockByIndex:
|
||||||
p = &payload.GetBlockData{}
|
p = &payload.GetBlockByIndex{}
|
||||||
case CMDHeaders:
|
case CMDHeaders:
|
||||||
p = &payload.Headers{Network: m.Network}
|
p = &payload.Headers{Network: m.Network}
|
||||||
case CMDTX:
|
case CMDTX:
|
||||||
|
|
|
@ -20,7 +20,7 @@ func _() {
|
||||||
_ = x[CMDMempool-37]
|
_ = x[CMDMempool-37]
|
||||||
_ = x[CMDInv-39]
|
_ = x[CMDInv-39]
|
||||||
_ = x[CMDGetData-40]
|
_ = x[CMDGetData-40]
|
||||||
_ = x[CMDGetBlockData-41]
|
_ = x[CMDGetBlockByIndex-41]
|
||||||
_ = x[CMDNotFound-42]
|
_ = x[CMDNotFound-42]
|
||||||
_ = x[CMDTX-43]
|
_ = x[CMDTX-43]
|
||||||
_ = x[CMDBlock-44]
|
_ = x[CMDBlock-44]
|
||||||
|
@ -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 = "CMDInvCMDGetDataCMDGetBlockDataCMDNotFoundCMDTXCMDBlockCMDConsensus"
|
_CommandType_name_5 = "CMDInvCMDGetDataCMDGetBlockByIndexCMDNotFoundCMDTXCMDBlockCMDConsensus"
|
||||||
_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, 42, 47, 55, 67}
|
_CommandType_index_5 = [...]uint8{0, 6, 16, 34, 45, 50, 58, 70}
|
||||||
_CommandType_index_6 = [...]uint8{0, 9, 22, 34, 48}
|
_CommandType_index_6 = [...]uint8{0, 9, 22, 34, 48}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,22 +9,22 @@ import (
|
||||||
// maximum number of blocks to query about
|
// maximum number of blocks to query about
|
||||||
const maxBlockCount = 500
|
const maxBlockCount = 500
|
||||||
|
|
||||||
// GetBlockData payload
|
// GetBlockByIndex payload
|
||||||
type GetBlockData struct {
|
type GetBlockByIndex struct {
|
||||||
IndexStart uint32
|
IndexStart uint32
|
||||||
Count uint16
|
Count uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGetBlockData returns GetBlockData payload with specified start index and count
|
// NewGetBlockByIndex returns GetBlockByIndex payload with specified start index and count
|
||||||
func NewGetBlockData(indexStart uint32, count uint16) *GetBlockData {
|
func NewGetBlockByIndex(indexStart uint32, count uint16) *GetBlockByIndex {
|
||||||
return &GetBlockData{
|
return &GetBlockByIndex{
|
||||||
IndexStart: indexStart,
|
IndexStart: indexStart,
|
||||||
Count: count,
|
Count: count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeBinary implements Serializable interface.
|
// DecodeBinary implements Serializable interface.
|
||||||
func (d *GetBlockData) DecodeBinary(br *io.BinReader) {
|
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
|
||||||
d.IndexStart = br.ReadU32LE()
|
d.IndexStart = br.ReadU32LE()
|
||||||
d.Count = br.ReadU16LE()
|
d.Count = br.ReadU16LE()
|
||||||
if d.Count == 0 || d.Count > maxBlockCount {
|
if d.Count == 0 || d.Count > maxBlockCount {
|
||||||
|
@ -33,7 +33,7 @@ func (d *GetBlockData) DecodeBinary(br *io.BinReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeBinary implements Serializable interface.
|
// EncodeBinary implements Serializable interface.
|
||||||
func (d *GetBlockData) EncodeBinary(bw *io.BinWriter) {
|
func (d *GetBlockByIndex) EncodeBinary(bw *io.BinWriter) {
|
||||||
bw.WriteU32LE(d.IndexStart)
|
bw.WriteU32LE(d.IndexStart)
|
||||||
bw.WriteU16LE(d.Count)
|
bw.WriteU16LE(d.Count)
|
||||||
}
|
}
|
|
@ -8,18 +8,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetBlockDataEncodeDecode(t *testing.T) {
|
func TestGetBlockDataEncodeDecode(t *testing.T) {
|
||||||
d := NewGetBlockData(123, 100)
|
d := NewGetBlockByIndex(123, 100)
|
||||||
testserdes.EncodeDecodeBinary(t, d, new(GetBlockData))
|
testserdes.EncodeDecodeBinary(t, d, new(GetBlockByIndex))
|
||||||
|
|
||||||
// invalid block count
|
// invalid block count
|
||||||
d = NewGetBlockData(5, 0)
|
d = NewGetBlockByIndex(5, 0)
|
||||||
data, err := testserdes.EncodeBinary(d)
|
data, err := testserdes.EncodeBinary(d)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockData)))
|
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||||
|
|
||||||
// invalid block count
|
// invalid block count
|
||||||
d = NewGetBlockData(5, maxBlockCount+1)
|
d = NewGetBlockByIndex(5, maxBlockCount+1)
|
||||||
data, err = testserdes.EncodeBinary(d)
|
data, err = testserdes.EncodeBinary(d)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockData)))
|
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||||
}
|
}
|
|
@ -609,8 +609,8 @@ func (s *Server) handleGetBlocksCmd(p Peer, gb *payload.GetBlocks) error {
|
||||||
return p.EnqueueP2PMessage(msg)
|
return p.EnqueueP2PMessage(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleGetBlockDataCmd processes the getblockdata request.
|
// handleGetBlockByIndexCmd processes the getblockbyindex request.
|
||||||
func (s *Server) handleGetBlockDataCmd(p Peer, gbd *payload.GetBlockData) error {
|
func (s *Server) handleGetBlockByIndexCmd(p Peer, gbd *payload.GetBlockByIndex) error {
|
||||||
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(gbd.Count); i++ {
|
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(gbd.Count); i++ {
|
||||||
b, err := s.chain.GetBlock(s.chain.GetHeaderHash(int(i)))
|
b, err := s.chain.GetBlock(s.chain.GetHeaderHash(int(i)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -750,9 +750,9 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error {
|
||||||
case CMDGetBlocks:
|
case CMDGetBlocks:
|
||||||
gb := msg.Payload.(*payload.GetBlocks)
|
gb := msg.Payload.(*payload.GetBlocks)
|
||||||
return s.handleGetBlocksCmd(peer, gb)
|
return s.handleGetBlocksCmd(peer, gb)
|
||||||
case CMDGetBlockData:
|
case CMDGetBlockByIndex:
|
||||||
gbd := msg.Payload.(*payload.GetBlockData)
|
gbd := msg.Payload.(*payload.GetBlockByIndex)
|
||||||
return s.handleGetBlockDataCmd(peer, gbd)
|
return s.handleGetBlockByIndexCmd(peer, gbd)
|
||||||
case CMDGetData:
|
case CMDGetData:
|
||||||
inv := msg.Payload.(*payload.Inventory)
|
inv := msg.Payload.(*payload.Inventory)
|
||||||
return s.handleGetDataCmd(peer, inv)
|
return s.handleGetDataCmd(peer, inv)
|
||||||
|
|
Loading…
Reference in a new issue