peer: add OnCFTypes and OnGetCFTypes callbacks

This commit is contained in:
Alex 2017-10-10 21:24:31 -06:00 committed by Olaoluwa Osuntokun
parent 5c93ca639a
commit 2b7ebfd698
2 changed files with 33 additions and 2 deletions

View file

@ -126,10 +126,13 @@ type MessageListeners struct {
// OnCFilter is invoked when a peer receives a cfilter bitcoin message.
OnCFilter func(p *Peer, msg *wire.MsgCFilter)
// OnCFHeaders is invoked when a peer receives a cfheader bitcoin
// OnCFHeaders is invoked when a peer receives a cfheaders bitcoin
// 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)
@ -155,10 +158,14 @@ type MessageListeners struct {
// message.
OnGetCFilter func(p *Peer, msg *wire.MsgGetCFilter)
// OnGetCFHeaders is invoked when a peer receives a getcfheader
// OnGetCFHeaders is invoked when a peer receives a getcfheaders
// 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)
@ -1601,6 +1608,11 @@ 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)
@ -1611,6 +1623,11 @@ 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,12 +405,18 @@ 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
},
@ -542,6 +548,10 @@ func TestPeerListeners(t *testing.T) {
"OnGetCFHeaders",
wire.NewMsgGetCFHeaders(),
},
{
"OnGetCFTypes",
wire.NewMsgGetCFTypes(),
},
{
"OnCFilter",
wire.NewMsgCFilter(&chainhash.Hash{}, 1,
@ -551,6 +561,10 @@ func TestPeerListeners(t *testing.T) {
"OnCFHeaders",
wire.NewMsgCFHeaders(),
},
{
"OnCFTypes",
wire.NewMsgCFTypes([]uint8{0, 1}),
},
{
"OnFeeFilter",
wire.NewMsgFeeFilter(15000),