wire: Remove cftypes and getcftypes commands.

This commit is contained in:
Jim Posen 2018-01-18 18:00:42 -08:00 committed by Olaoluwa Osuntokun
parent 34d82682b0
commit 621f347929
8 changed files with 11 additions and 204 deletions

View file

@ -130,9 +130,6 @@ type MessageListeners struct {
// message.
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 func(p *Peer, msg *wire.MsgInv)
@ -162,10 +159,6 @@ type MessageListeners struct {
// bitcoin message.
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 func(p *Peer, msg *wire.MsgFeeFilter)
@ -1608,11 +1601,6 @@ out:
p.cfg.Listeners.OnGetCFHeaders(p, msg)
}
case *wire.MsgGetCFTypes:
if p.cfg.Listeners.OnGetCFTypes != nil {
p.cfg.Listeners.OnGetCFTypes(p, msg)
}
case *wire.MsgCFilter:
if p.cfg.Listeners.OnCFilter != nil {
p.cfg.Listeners.OnCFilter(p, msg)
@ -1623,11 +1611,6 @@ out:
p.cfg.Listeners.OnCFHeaders(p, msg)
}
case *wire.MsgCFTypes:
if p.cfg.Listeners.OnCFTypes != nil {
p.cfg.Listeners.OnCFTypes(p, msg)
}
case *wire.MsgFeeFilter:
if p.cfg.Listeners.OnFeeFilter != nil {
p.cfg.Listeners.OnFeeFilter(p, msg)

View file

@ -405,18 +405,12 @@ func TestPeerListeners(t *testing.T) {
OnGetCFHeaders: func(p *peer.Peer, msg *wire.MsgGetCFHeaders) {
ok <- msg
},
OnGetCFTypes: func(p *peer.Peer, msg *wire.MsgGetCFTypes) {
ok <- msg
},
OnCFilter: func(p *peer.Peer, msg *wire.MsgCFilter) {
ok <- msg
},
OnCFHeaders: func(p *peer.Peer, msg *wire.MsgCFHeaders) {
ok <- msg
},
OnCFTypes: func(p *peer.Peer, msg *wire.MsgCFTypes) {
ok <- msg
},
OnFeeFilter: func(p *peer.Peer, msg *wire.MsgFeeFilter) {
ok <- msg
},
@ -549,10 +543,6 @@ func TestPeerListeners(t *testing.T) {
"OnGetCFHeaders",
wire.NewMsgGetCFHeaders(),
},
{
"OnGetCFTypes",
wire.NewMsgGetCFTypes(),
},
{
"OnCFilter",
wire.NewMsgCFilter(&chainhash.Hash{},
@ -562,11 +552,6 @@ func TestPeerListeners(t *testing.T) {
"OnCFHeaders",
wire.NewMsgCFHeaders(),
},
{
"OnCFTypes",
wire.NewMsgCFTypes([]wire.FilterType{
wire.GCSFilterRegular, wire.GCSFilterExtended}),
},
{
"OnFeeFilter",
wire.NewMsgFeeFilter(15000),

View file

@ -877,21 +877,6 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
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
// 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,
@ -1741,7 +1726,6 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
OnGetHeaders: sp.OnGetHeaders,
OnGetCFilter: sp.OnGetCFilter,
OnGetCFHeaders: sp.OnGetCFHeaders,
OnGetCFTypes: sp.OnGetCFTypes,
OnFeeFilter: sp.OnFeeFilter,
OnFilterAdd: sp.OnFilterAdd,
OnFilterClear: sp.OnFilterClear,

View file

@ -53,10 +53,8 @@ const (
CmdFeeFilter = "feefilter"
CmdGetCFilter = "getcfilter"
CmdGetCFHeaders = "getcfheaders"
CmdGetCFTypes = "getcftypes"
CmdCFilter = "cfilter"
CmdCFHeaders = "cfheaders"
CmdCFTypes = "cftypes"
)
// MessageEncoding represents the wire message encoding format to be used.
@ -168,18 +166,12 @@ func makeEmptyMessage(command string) (Message, error) {
case CmdGetCFHeaders:
msg = &MsgGetCFHeaders{}
case CmdGetCFTypes:
msg = &MsgGetCFTypes{}
case CmdCFilter:
msg = &MsgCFilter{}
case CmdCFHeaders:
msg = &MsgCFHeaders{}
case CmdCFTypes:
msg = &MsgCFTypes{}
default:
return nil, fmt.Errorf("unhandled command [%s]", command)
}

View file

@ -71,11 +71,9 @@ func TestMessage(t *testing.T) {
msgReject := NewMsgReject("block", RejectDuplicate, "duplicate block")
msgGetCFilter := NewMsgGetCFilter(&chainhash.Hash{}, GCSFilterExtended)
msgGetCFHeaders := NewMsgGetCFHeaders()
msgGetCFTypes := NewMsgGetCFTypes()
msgCFilter := NewMsgCFilter(&chainhash.Hash{}, GCSFilterExtended,
[]byte("payload"))
msgCFHeaders := NewMsgCFHeaders()
msgCFTypes := NewMsgCFTypes([]FilterType{GCSFilterExtended})
tests := []struct {
in Message // Value to encode
@ -107,10 +105,8 @@ func TestMessage(t *testing.T) {
{msgReject, msgReject, pver, MainNet, 79},
{msgGetCFilter, msgGetCFilter, pver, MainNet, 57},
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 58},
{msgGetCFTypes, msgGetCFTypes, pver, MainNet, 24},
{msgCFilter, msgCFilter, pver, MainNet, 65},
{msgCFHeaders, msgCFHeaders, pver, MainNet, 58},
{msgCFTypes, msgCFTypes, pver, MainNet, 26},
}
t.Logf("Running %d tests", len(tests))

View file

@ -11,6 +11,17 @@ import (
"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 (
// MaxCFilterDataSize is the maximum byte size of a committed filter.
// The maximum size is currently defined as 256KiB.

View file

@ -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,
}
}

View file

@ -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{}
}