mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-18 21:32:30 +01:00
wire: update messages to conform to BIP and fix comments
This commit is contained in:
parent
89d6696560
commit
1aa7a6166d
@ -105,7 +105,7 @@ func TestMessage(t *testing.T) {
|
||||
{msgMerkleBlock, msgMerkleBlock, pver, MainNet, 110},
|
||||
{msgReject, msgReject, pver, MainNet, 79},
|
||||
{msgGetCFilter, msgGetCFilter, pver, MainNet, 57},
|
||||
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 62},
|
||||
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 58},
|
||||
{msgGetCFTypes, msgGetCFTypes, pver, MainNet, 24},
|
||||
{msgCFilter, msgCFilter, pver, MainNet, 65},
|
||||
{msgCFHeaders, msgCFHeaders, pver, MainNet, 58},
|
||||
|
@ -150,9 +150,10 @@ func (msg *MsgCFHeaders) Command() string {
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
||||
// receiver. This is part of the Message interface implementation.
|
||||
// receiver. This is part of the Message interface implementation.
|
||||
func (msg *MsgCFHeaders) MaxPayloadLength(pver uint32) uint32 {
|
||||
// Hash size + num headers (varInt) + (header size * max headers).
|
||||
// Hash size + filter type + num headers (varInt) +
|
||||
// (header size * max headers).
|
||||
return chainhash.HashSize + 1 + MaxVarIntPayload +
|
||||
(MaxCFHeaderPayload * MaxCFHeadersPerMsg)
|
||||
}
|
||||
|
@ -13,9 +13,13 @@ import (
|
||||
|
||||
const (
|
||||
// MaxCFilterDataSize is the maximum byte size of a committed filter.
|
||||
MaxCFilterDataSize = 262144
|
||||
// The maximum size is currently defined as 256KiB.
|
||||
MaxCFilterDataSize = 256 * 1024
|
||||
)
|
||||
|
||||
// MsgCFilter implements the Message interface and represents a bitcoin cfilter
|
||||
// message. It is used to deliver a committed filter in response to a
|
||||
// getcfilter (MsgGetCFilter) message.
|
||||
type MsgCFilter struct {
|
||||
BlockHash chainhash.Hash
|
||||
FilterType uint8
|
||||
@ -25,9 +29,8 @@ type MsgCFilter struct {
|
||||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgCFilter) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
||||
var err error
|
||||
// Read the hash of the filter's block
|
||||
err = readElement(r, &msg.BlockHash)
|
||||
err := readElement(r, &msg.BlockHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
// filter headers. It allows to set the FilterType field to get headers in the
|
||||
// chain of basic (0x00) or extended (0x01) headers.
|
||||
type MsgGetCFHeaders struct {
|
||||
ProtocolVersion uint32
|
||||
BlockLocatorHashes []*chainhash.Hash
|
||||
HashStop chainhash.Hash
|
||||
FilterType uint8
|
||||
@ -36,11 +35,6 @@ func (msg *MsgGetCFHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error {
|
||||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgGetCFHeaders) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
||||
err := readElement(r, &msg.ProtocolVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read num block locator hashes and limit to max.
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
@ -84,12 +78,7 @@ func (msg *MsgGetCFHeaders) BtcEncode(w io.Writer, pver uint32, _ MessageEncodin
|
||||
return messageError("MsgGetHeaders.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeElement(w, msg.ProtocolVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -118,9 +107,9 @@ func (msg *MsgGetCFHeaders) Command() string {
|
||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
||||
// receiver. This is part of the Message interface implementation.
|
||||
func (msg *MsgGetCFHeaders) MaxPayloadLength(pver uint32) uint32 {
|
||||
// Version 4 bytes + num block locator hashes (varInt) + max allowed
|
||||
// Num block locator hashes (varInt) + max allowed
|
||||
// block locators + hash stop + filter type 1 byte.
|
||||
return 4 + MaxVarIntPayload + (MaxBlockLocatorsPerMsg *
|
||||
return MaxVarIntPayload + (MaxBlockLocatorsPerMsg *
|
||||
chainhash.HashSize) + chainhash.HashSize + 1
|
||||
}
|
||||
|
||||
|
@ -10,11 +10,15 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
// MsgGetCFilter implements the Message interface and represents a bitcoin
|
||||
// getcfilter message. It is used to request a committed filter for a block.
|
||||
type MsgGetCFilter struct {
|
||||
BlockHash chainhash.Hash
|
||||
FilterType uint8
|
||||
}
|
||||
|
||||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgGetCFilter) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
||||
err := readElement(r, &msg.BlockHash)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user