peer: Implement feefilter p2p message (bip0133)

This commit is contained in:
David Hill 2016-08-25 15:08:32 -04:00
parent 9935fe5dba
commit d009185a56
2 changed files with 17 additions and 1 deletions

View file

@ -27,7 +27,7 @@ import (
const ( const (
// MaxProtocolVersion is the max protocol version the peer supports. // MaxProtocolVersion is the max protocol version the peer supports.
MaxProtocolVersion = wire.SendHeadersVersion MaxProtocolVersion = wire.FeeFilterVersion
// outputBufferSize is the number of elements the output channels use. // outputBufferSize is the number of elements the output channels use.
outputBufferSize = 50 outputBufferSize = 50
@ -140,6 +140,9 @@ type MessageListeners struct {
// message. // message.
OnGetHeaders func(p *Peer, msg *wire.MsgGetHeaders) OnGetHeaders func(p *Peer, msg *wire.MsgGetHeaders)
// OnFeeFilter is invoked when a peer receives a feefilter bitcoin message.
OnFeeFilter func(p *Peer, msg *wire.MsgFeeFilter)
// OnFilterAdd is invoked when a peer receives a filteradd bitcoin message. // OnFilterAdd is invoked when a peer receives a filteradd bitcoin message.
OnFilterAdd func(p *Peer, msg *wire.MsgFilterAdd) OnFilterAdd func(p *Peer, msg *wire.MsgFilterAdd)
@ -1500,6 +1503,11 @@ out:
p.cfg.Listeners.OnGetHeaders(p, msg) p.cfg.Listeners.OnGetHeaders(p, msg)
} }
case *wire.MsgFeeFilter:
if p.cfg.Listeners.OnFeeFilter != nil {
p.cfg.Listeners.OnFeeFilter(p, msg)
}
case *wire.MsgFilterAdd: case *wire.MsgFilterAdd:
if p.cfg.Listeners.OnFilterAdd != nil { if p.cfg.Listeners.OnFilterAdd != nil {
p.cfg.Listeners.OnFilterAdd(p, msg) p.cfg.Listeners.OnFilterAdd(p, msg)

View file

@ -359,6 +359,9 @@ func TestPeerListeners(t *testing.T) {
OnGetHeaders: func(p *peer.Peer, msg *wire.MsgGetHeaders) { OnGetHeaders: func(p *peer.Peer, msg *wire.MsgGetHeaders) {
ok <- msg ok <- msg
}, },
OnFeeFilter: func(p *peer.Peer, msg *wire.MsgFeeFilter) {
ok <- msg
},
OnFilterAdd: func(p *peer.Peer, msg *wire.MsgFilterAdd) { OnFilterAdd: func(p *peer.Peer, msg *wire.MsgFilterAdd) {
ok <- msg ok <- msg
}, },
@ -477,6 +480,10 @@ func TestPeerListeners(t *testing.T) {
"OnGetHeaders", "OnGetHeaders",
wire.NewMsgGetHeaders(), wire.NewMsgGetHeaders(),
}, },
{
"OnFeeFilter",
wire.NewMsgFeeFilter(15000),
},
{ {
"OnFilterAdd", "OnFilterAdd",
wire.NewMsgFilterAdd([]byte{0x01}), wire.NewMsgFilterAdd([]byte{0x01}),
@ -656,6 +663,7 @@ func TestOutboundPeer(t *testing.T) {
p2.QueueMessage(wire.NewMsgMemPool(), nil) p2.QueueMessage(wire.NewMsgMemPool(), nil)
p2.QueueMessage(wire.NewMsgGetData(), nil) p2.QueueMessage(wire.NewMsgGetData(), nil)
p2.QueueMessage(wire.NewMsgGetHeaders(), nil) p2.QueueMessage(wire.NewMsgGetHeaders(), nil)
p2.QueueMessage(wire.NewMsgFeeFilter(20000), nil)
p2.Disconnect() p2.Disconnect()
} }