wire: Remove cftypes and getcftypes commands.
This commit is contained in:
parent
34d82682b0
commit
621f347929
8 changed files with 11 additions and 204 deletions
17
peer/peer.go
17
peer/peer.go
|
@ -130,9 +130,6 @@ type MessageListeners struct {
|
||||||
// message.
|
// message.
|
||||||
OnCFHeaders func(p *Peer, msg *wire.MsgCFHeaders)
|
OnCFHeaders func(p *Peer, msg *wire.MsgCFHeaders)
|
||||||
|
|
||||||
// OnCFTypes is invoked when a peer receives a cftypes bitcoin message.
|
|
||||||
OnCFTypes func(p *Peer, msg *wire.MsgCFTypes)
|
|
||||||
|
|
||||||
// OnInv is invoked when a peer receives an inv bitcoin message.
|
// OnInv is invoked when a peer receives an inv bitcoin message.
|
||||||
OnInv func(p *Peer, msg *wire.MsgInv)
|
OnInv func(p *Peer, msg *wire.MsgInv)
|
||||||
|
|
||||||
|
@ -162,10 +159,6 @@ type MessageListeners struct {
|
||||||
// bitcoin message.
|
// bitcoin message.
|
||||||
OnGetCFHeaders func(p *Peer, msg *wire.MsgGetCFHeaders)
|
OnGetCFHeaders func(p *Peer, msg *wire.MsgGetCFHeaders)
|
||||||
|
|
||||||
// OnGetCFTypes is invoked when a peer receives a getcftypes bitcoin
|
|
||||||
// message.
|
|
||||||
OnGetCFTypes func(p *Peer, msg *wire.MsgGetCFTypes)
|
|
||||||
|
|
||||||
// OnFeeFilter is invoked when a peer receives a feefilter bitcoin message.
|
// OnFeeFilter is invoked when a peer receives a feefilter bitcoin message.
|
||||||
OnFeeFilter func(p *Peer, msg *wire.MsgFeeFilter)
|
OnFeeFilter func(p *Peer, msg *wire.MsgFeeFilter)
|
||||||
|
|
||||||
|
@ -1608,11 +1601,6 @@ out:
|
||||||
p.cfg.Listeners.OnGetCFHeaders(p, msg)
|
p.cfg.Listeners.OnGetCFHeaders(p, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *wire.MsgGetCFTypes:
|
|
||||||
if p.cfg.Listeners.OnGetCFTypes != nil {
|
|
||||||
p.cfg.Listeners.OnGetCFTypes(p, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
case *wire.MsgCFilter:
|
case *wire.MsgCFilter:
|
||||||
if p.cfg.Listeners.OnCFilter != nil {
|
if p.cfg.Listeners.OnCFilter != nil {
|
||||||
p.cfg.Listeners.OnCFilter(p, msg)
|
p.cfg.Listeners.OnCFilter(p, msg)
|
||||||
|
@ -1623,11 +1611,6 @@ out:
|
||||||
p.cfg.Listeners.OnCFHeaders(p, msg)
|
p.cfg.Listeners.OnCFHeaders(p, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *wire.MsgCFTypes:
|
|
||||||
if p.cfg.Listeners.OnCFTypes != nil {
|
|
||||||
p.cfg.Listeners.OnCFTypes(p, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
case *wire.MsgFeeFilter:
|
case *wire.MsgFeeFilter:
|
||||||
if p.cfg.Listeners.OnFeeFilter != nil {
|
if p.cfg.Listeners.OnFeeFilter != nil {
|
||||||
p.cfg.Listeners.OnFeeFilter(p, msg)
|
p.cfg.Listeners.OnFeeFilter(p, msg)
|
||||||
|
|
|
@ -405,18 +405,12 @@ func TestPeerListeners(t *testing.T) {
|
||||||
OnGetCFHeaders: func(p *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
OnGetCFHeaders: func(p *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
OnGetCFTypes: func(p *peer.Peer, msg *wire.MsgGetCFTypes) {
|
|
||||||
ok <- msg
|
|
||||||
},
|
|
||||||
OnCFilter: func(p *peer.Peer, msg *wire.MsgCFilter) {
|
OnCFilter: func(p *peer.Peer, msg *wire.MsgCFilter) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
OnCFHeaders: func(p *peer.Peer, msg *wire.MsgCFHeaders) {
|
OnCFHeaders: func(p *peer.Peer, msg *wire.MsgCFHeaders) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
OnCFTypes: func(p *peer.Peer, msg *wire.MsgCFTypes) {
|
|
||||||
ok <- msg
|
|
||||||
},
|
|
||||||
OnFeeFilter: func(p *peer.Peer, msg *wire.MsgFeeFilter) {
|
OnFeeFilter: func(p *peer.Peer, msg *wire.MsgFeeFilter) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
|
@ -549,10 +543,6 @@ func TestPeerListeners(t *testing.T) {
|
||||||
"OnGetCFHeaders",
|
"OnGetCFHeaders",
|
||||||
wire.NewMsgGetCFHeaders(),
|
wire.NewMsgGetCFHeaders(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"OnGetCFTypes",
|
|
||||||
wire.NewMsgGetCFTypes(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"OnCFilter",
|
"OnCFilter",
|
||||||
wire.NewMsgCFilter(&chainhash.Hash{},
|
wire.NewMsgCFilter(&chainhash.Hash{},
|
||||||
|
@ -562,11 +552,6 @@ func TestPeerListeners(t *testing.T) {
|
||||||
"OnCFHeaders",
|
"OnCFHeaders",
|
||||||
wire.NewMsgCFHeaders(),
|
wire.NewMsgCFHeaders(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"OnCFTypes",
|
|
||||||
wire.NewMsgCFTypes([]wire.FilterType{
|
|
||||||
wire.GCSFilterRegular, wire.GCSFilterExtended}),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"OnFeeFilter",
|
"OnFeeFilter",
|
||||||
wire.NewMsgFeeFilter(15000),
|
wire.NewMsgFeeFilter(15000),
|
||||||
|
|
16
server.go
16
server.go
|
@ -877,21 +877,6 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||||
sp.QueueMessage(headersMsg, nil)
|
sp.QueueMessage(headersMsg, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnGetCFTypes is invoked when a peer receives a getcftypes bitcoin message.
|
|
||||||
func (sp *serverPeer) OnGetCFTypes(_ *peer.Peer, msg *wire.MsgGetCFTypes) {
|
|
||||||
// Ignore getcftypes requests if cfg.NoCFilters is set or we're not in
|
|
||||||
// sync.
|
|
||||||
if cfg.NoCFilters || !sp.server.syncManager.IsCurrent() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: update to query blockchain indexes and/or config for supported
|
|
||||||
// filter types.
|
|
||||||
cfTypesMsg := wire.NewMsgCFTypes([]wire.FilterType{
|
|
||||||
wire.GCSFilterRegular, wire.GCSFilterExtended})
|
|
||||||
sp.QueueMessage(cfTypesMsg, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// enforceNodeBloomFlag disconnects the peer if the server is not configured to
|
// enforceNodeBloomFlag disconnects the peer if the server is not configured to
|
||||||
// allow bloom filters. Additionally, if the peer has negotiated to a protocol
|
// allow bloom filters. Additionally, if the peer has negotiated to a protocol
|
||||||
// version that is high enough to observe the bloom filter service support bit,
|
// version that is high enough to observe the bloom filter service support bit,
|
||||||
|
@ -1741,7 +1726,6 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
|
||||||
OnGetHeaders: sp.OnGetHeaders,
|
OnGetHeaders: sp.OnGetHeaders,
|
||||||
OnGetCFilter: sp.OnGetCFilter,
|
OnGetCFilter: sp.OnGetCFilter,
|
||||||
OnGetCFHeaders: sp.OnGetCFHeaders,
|
OnGetCFHeaders: sp.OnGetCFHeaders,
|
||||||
OnGetCFTypes: sp.OnGetCFTypes,
|
|
||||||
OnFeeFilter: sp.OnFeeFilter,
|
OnFeeFilter: sp.OnFeeFilter,
|
||||||
OnFilterAdd: sp.OnFilterAdd,
|
OnFilterAdd: sp.OnFilterAdd,
|
||||||
OnFilterClear: sp.OnFilterClear,
|
OnFilterClear: sp.OnFilterClear,
|
||||||
|
|
|
@ -53,10 +53,8 @@ const (
|
||||||
CmdFeeFilter = "feefilter"
|
CmdFeeFilter = "feefilter"
|
||||||
CmdGetCFilter = "getcfilter"
|
CmdGetCFilter = "getcfilter"
|
||||||
CmdGetCFHeaders = "getcfheaders"
|
CmdGetCFHeaders = "getcfheaders"
|
||||||
CmdGetCFTypes = "getcftypes"
|
|
||||||
CmdCFilter = "cfilter"
|
CmdCFilter = "cfilter"
|
||||||
CmdCFHeaders = "cfheaders"
|
CmdCFHeaders = "cfheaders"
|
||||||
CmdCFTypes = "cftypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageEncoding represents the wire message encoding format to be used.
|
// MessageEncoding represents the wire message encoding format to be used.
|
||||||
|
@ -168,18 +166,12 @@ func makeEmptyMessage(command string) (Message, error) {
|
||||||
case CmdGetCFHeaders:
|
case CmdGetCFHeaders:
|
||||||
msg = &MsgGetCFHeaders{}
|
msg = &MsgGetCFHeaders{}
|
||||||
|
|
||||||
case CmdGetCFTypes:
|
|
||||||
msg = &MsgGetCFTypes{}
|
|
||||||
|
|
||||||
case CmdCFilter:
|
case CmdCFilter:
|
||||||
msg = &MsgCFilter{}
|
msg = &MsgCFilter{}
|
||||||
|
|
||||||
case CmdCFHeaders:
|
case CmdCFHeaders:
|
||||||
msg = &MsgCFHeaders{}
|
msg = &MsgCFHeaders{}
|
||||||
|
|
||||||
case CmdCFTypes:
|
|
||||||
msg = &MsgCFTypes{}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unhandled command [%s]", command)
|
return nil, fmt.Errorf("unhandled command [%s]", command)
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,9 @@ func TestMessage(t *testing.T) {
|
||||||
msgReject := NewMsgReject("block", RejectDuplicate, "duplicate block")
|
msgReject := NewMsgReject("block", RejectDuplicate, "duplicate block")
|
||||||
msgGetCFilter := NewMsgGetCFilter(&chainhash.Hash{}, GCSFilterExtended)
|
msgGetCFilter := NewMsgGetCFilter(&chainhash.Hash{}, GCSFilterExtended)
|
||||||
msgGetCFHeaders := NewMsgGetCFHeaders()
|
msgGetCFHeaders := NewMsgGetCFHeaders()
|
||||||
msgGetCFTypes := NewMsgGetCFTypes()
|
|
||||||
msgCFilter := NewMsgCFilter(&chainhash.Hash{}, GCSFilterExtended,
|
msgCFilter := NewMsgCFilter(&chainhash.Hash{}, GCSFilterExtended,
|
||||||
[]byte("payload"))
|
[]byte("payload"))
|
||||||
msgCFHeaders := NewMsgCFHeaders()
|
msgCFHeaders := NewMsgCFHeaders()
|
||||||
msgCFTypes := NewMsgCFTypes([]FilterType{GCSFilterExtended})
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
in Message // Value to encode
|
in Message // Value to encode
|
||||||
|
@ -107,10 +105,8 @@ func TestMessage(t *testing.T) {
|
||||||
{msgReject, msgReject, pver, MainNet, 79},
|
{msgReject, msgReject, pver, MainNet, 79},
|
||||||
{msgGetCFilter, msgGetCFilter, pver, MainNet, 57},
|
{msgGetCFilter, msgGetCFilter, pver, MainNet, 57},
|
||||||
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 58},
|
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 58},
|
||||||
{msgGetCFTypes, msgGetCFTypes, pver, MainNet, 24},
|
|
||||||
{msgCFilter, msgCFilter, pver, MainNet, 65},
|
{msgCFilter, msgCFilter, pver, MainNet, 65},
|
||||||
{msgCFHeaders, msgCFHeaders, pver, MainNet, 58},
|
{msgCFHeaders, msgCFHeaders, pver, MainNet, 58},
|
||||||
{msgCFTypes, msgCFTypes, pver, MainNet, 26},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
|
|
|
@ -11,6 +11,17 @@ import (
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FilterType is used to represent a filter type.
|
||||||
|
type FilterType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// GCSFilterRegular is the regular filter type.
|
||||||
|
GCSFilterRegular FilterType = iota
|
||||||
|
|
||||||
|
// GCSFilterExtended is the extended filter type.
|
||||||
|
GCSFilterExtended
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// MaxCFilterDataSize is the maximum byte size of a committed filter.
|
// MaxCFilterDataSize is the maximum byte size of a committed filter.
|
||||||
// The maximum size is currently defined as 256KiB.
|
// The maximum size is currently defined as 256KiB.
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
// 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 "io"
|
|
||||||
|
|
||||||
// FilterType is used to represent a filter type.
|
|
||||||
type FilterType uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
// GCSFilterRegular is the regular filter type.
|
|
||||||
GCSFilterRegular FilterType = iota
|
|
||||||
|
|
||||||
// GCSFilterExtended is the extended filter type.
|
|
||||||
GCSFilterExtended
|
|
||||||
)
|
|
||||||
|
|
||||||
// MsgCFTypes is the cftypes message.
|
|
||||||
type MsgCFTypes struct {
|
|
||||||
SupportedFilters []FilterType
|
|
||||||
}
|
|
||||||
|
|
||||||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
|
||||||
// This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgCFTypes) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
|
||||||
// Read the number of filter types supported.
|
|
||||||
count, err := ReadVarInt(r, pver)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read each filter type.
|
|
||||||
msg.SupportedFilters = make([]FilterType, count)
|
|
||||||
for i := uint64(0); i < count; i++ {
|
|
||||||
var filterType uint8
|
|
||||||
err = readElement(r, &filterType)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
msg.SupportedFilters[i] = FilterType(filterType)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
|
||||||
// This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgCFTypes) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) error {
|
|
||||||
// Write length of supported filters slice. We assume it's deduplicated.
|
|
||||||
err := WriteVarInt(w, pver, uint64(len(msg.SupportedFilters)))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range msg.SupportedFilters {
|
|
||||||
err = writeElement(w, msg.SupportedFilters[i])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserialize decodes a filter from r into the receiver using a format that is
|
|
||||||
// suitable for long-term storage such as a database. This function differs
|
|
||||||
// from BtcDecode in that BtcDecode decodes from the bitcoin wire protocol as
|
|
||||||
// it was sent across the network. The wire encoding can technically differ
|
|
||||||
// depending on the protocol version and doesn't even really need to match the
|
|
||||||
// format of a stored filter at all. As of the time this comment was written,
|
|
||||||
// the encoded filter is the same in both instances, but there is a distinct
|
|
||||||
// difference and separating the two allows the API to be flexible enough to
|
|
||||||
// deal with changes.
|
|
||||||
func (msg *MsgCFTypes) Deserialize(r io.Reader) error {
|
|
||||||
// At the current time, there is no difference between the wire encoding
|
|
||||||
// and the stable long-term storage format. As a result, make use of
|
|
||||||
// BtcDecode.
|
|
||||||
return msg.BtcDecode(r, 0, BaseEncoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message. This is part
|
|
||||||
// of the Message interface implementation.
|
|
||||||
func (msg *MsgCFTypes) Command() string {
|
|
||||||
return CmdCFTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
|
||||||
// receiver. This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgCFTypes) MaxPayloadLength(pver uint32) uint32 {
|
|
||||||
// 2 bytes for filter count, and 1 byte for up to 256 filter types.
|
|
||||||
return 258
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgCFTypes returns a new bitcoin cftypes message that conforms to the
|
|
||||||
// Message interface. See MsgCFTypes for details.
|
|
||||||
func NewMsgCFTypes(filterTypes []FilterType) *MsgCFTypes {
|
|
||||||
return &MsgCFTypes{
|
|
||||||
SupportedFilters: filterTypes,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
// 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 "io"
|
|
||||||
|
|
||||||
// MsgGetCFTypes is the getcftypes message.
|
|
||||||
type MsgGetCFTypes struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// BtcDecode decodes the receiver from w using the bitcoin protocol encoding.
|
|
||||||
// This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgGetCFTypes) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
|
||||||
// This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgGetCFTypes) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message. This is part
|
|
||||||
// of the Message interface implementation.
|
|
||||||
func (msg *MsgGetCFTypes) Command() string {
|
|
||||||
return CmdGetCFTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
|
||||||
// receiver. This is part of the Message interface implementation.
|
|
||||||
func (msg *MsgGetCFTypes) MaxPayloadLength(pver uint32) uint32 {
|
|
||||||
// Empty message.
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgGetCFTypes returns a new bitcoin getcftypes message that conforms to
|
|
||||||
// the Message interface.
|
|
||||||
func NewMsgGetCFTypes() *MsgGetCFTypes {
|
|
||||||
return &MsgGetCFTypes{}
|
|
||||||
}
|
|
Loading…
Reference in a new issue