mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-10 16:16:47 +00:00
p2p needs a new message to return committed filters
This commit is contained in:
parent
71c421db66
commit
cdb3d44fa8
@ -755,6 +755,9 @@ func (sp *serverPeer) OnGetCFilter(_ *peer.Peer, msg *wire.MsgGetCFilter) {
|
|||||||
peerLog.Infof("Could not obtain CB filter for %v: %v",
|
peerLog.Infof("Could not obtain CB filter for %v: %v",
|
||||||
msg.BlockHash, err)
|
msg.BlockHash, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filterMsg := wire.NewMsgCFilter(filterBytes)
|
||||||
|
sp.QueueMessage(filterMsg, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// enforceNodeBloomFlag disconnects the peer if the server is not configured to
|
// enforceNodeBloomFlag disconnects the peer if the server is not configured to
|
||||||
|
@ -52,6 +52,7 @@ const (
|
|||||||
CmdSendHeaders = "sendheaders"
|
CmdSendHeaders = "sendheaders"
|
||||||
CmdFeeFilter = "feefilter"
|
CmdFeeFilter = "feefilter"
|
||||||
CmdGetCFilter = "getcfilter"
|
CmdGetCFilter = "getcfilter"
|
||||||
|
CmdCFilter = "cfilter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageEncoding represents the wire message encoding format to be used.
|
// MessageEncoding represents the wire message encoding format to be used.
|
||||||
@ -160,6 +161,9 @@ func makeEmptyMessage(command string) (Message, error) {
|
|||||||
case CmdGetCFilter:
|
case CmdGetCFilter:
|
||||||
msg = &MsgGetCFilter{}
|
msg = &MsgGetCFilter{}
|
||||||
|
|
||||||
|
case CmdCFilter:
|
||||||
|
msg = &MsgCFilter{}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unhandled command [%s]", command)
|
return nil, fmt.Errorf("unhandled command [%s]", command)
|
||||||
}
|
}
|
||||||
|
61
wire/msgcfilter.go
Normal file
61
wire/msgcfilter.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) 2017 The btcsuite developers
|
||||||
|
// Use of this source code is governed by an ISC
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package wire
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MaxCFilterDataSize is the maximum byte size of a committed filter.
|
||||||
|
MaxCFilterDataSize = 65536
|
||||||
|
)
|
||||||
|
type MsgCFilter struct {
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) error {
|
||||||
|
var err error
|
||||||
|
msg.Data, err = ReadVarBytes(r, pver, MaxCFilterDataSize,
|
||||||
|
"cfilter data")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
||||||
|
// This is part of the Message interface implementation.
|
||||||
|
func (msg *MsgCFilter) BtcEncode(w io.Writer, pver uint32) error {
|
||||||
|
size := len(msg.Data)
|
||||||
|
if size > MaxCFilterDataSize {
|
||||||
|
str := fmt.Sprintf("cfilter size too large for message "+
|
||||||
|
"[size %v, max %v]", size, MaxCFilterDataSize)
|
||||||
|
return messageError("MsgCFilter.BtcEncode", str)
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteVarBytes(w, pver, msg.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command returns the protocol command string for the message. This is part
|
||||||
|
// of the Message interface implementation.
|
||||||
|
func (msg *MsgCFilter) Command() string {
|
||||||
|
return CmdCFilter
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaxPayloadLength returns the maximum length the payload can be for the
|
||||||
|
// receiver. This is part of the Message interface implementation.
|
||||||
|
func (msg *MsgCFilter) MaxPayloadLength(pver uint32) uint32 {
|
||||||
|
return uint32(VarIntSerializeSize(MaxCFilterDataSize)) +
|
||||||
|
MaxCFilterDataSize
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMsgFilterAdd returns a new bitcoin filteradd message that conforms to the
|
||||||
|
// Message interface. See MsgCFilter for details.
|
||||||
|
func NewMsgCFilter(data []byte) *MsgCFilter {
|
||||||
|
return &MsgCFilter{
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2013-2016 The btcsuite developers
|
// Copyright (c) 2017 The btcsuite developers
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user