peer: Implement feefilter p2p message (bip0133)
This commit is contained in:
parent
9935fe5dba
commit
d009185a56
2 changed files with 17 additions and 1 deletions
10
peer/peer.go
10
peer/peer.go
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
const (
|
||||
// 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 = 50
|
||||
|
@ -140,6 +140,9 @@ type MessageListeners struct {
|
|||
// message.
|
||||
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 func(p *Peer, msg *wire.MsgFilterAdd)
|
||||
|
||||
|
@ -1500,6 +1503,11 @@ out:
|
|||
p.cfg.Listeners.OnGetHeaders(p, msg)
|
||||
}
|
||||
|
||||
case *wire.MsgFeeFilter:
|
||||
if p.cfg.Listeners.OnFeeFilter != nil {
|
||||
p.cfg.Listeners.OnFeeFilter(p, msg)
|
||||
}
|
||||
|
||||
case *wire.MsgFilterAdd:
|
||||
if p.cfg.Listeners.OnFilterAdd != nil {
|
||||
p.cfg.Listeners.OnFilterAdd(p, msg)
|
||||
|
|
|
@ -359,6 +359,9 @@ func TestPeerListeners(t *testing.T) {
|
|||
OnGetHeaders: func(p *peer.Peer, msg *wire.MsgGetHeaders) {
|
||||
ok <- msg
|
||||
},
|
||||
OnFeeFilter: func(p *peer.Peer, msg *wire.MsgFeeFilter) {
|
||||
ok <- msg
|
||||
},
|
||||
OnFilterAdd: func(p *peer.Peer, msg *wire.MsgFilterAdd) {
|
||||
ok <- msg
|
||||
},
|
||||
|
@ -477,6 +480,10 @@ func TestPeerListeners(t *testing.T) {
|
|||
"OnGetHeaders",
|
||||
wire.NewMsgGetHeaders(),
|
||||
},
|
||||
{
|
||||
"OnFeeFilter",
|
||||
wire.NewMsgFeeFilter(15000),
|
||||
},
|
||||
{
|
||||
"OnFilterAdd",
|
||||
wire.NewMsgFilterAdd([]byte{0x01}),
|
||||
|
@ -656,6 +663,7 @@ func TestOutboundPeer(t *testing.T) {
|
|||
p2.QueueMessage(wire.NewMsgMemPool(), nil)
|
||||
p2.QueueMessage(wire.NewMsgGetData(), nil)
|
||||
p2.QueueMessage(wire.NewMsgGetHeaders(), nil)
|
||||
p2.QueueMessage(wire.NewMsgFeeFilter(20000), nil)
|
||||
|
||||
p2.Disconnect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue