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 is invoked when a peer receives a cfilter bitcoin message.
OnCFilter func(p *Peer, msg *wire.MsgCFilter) 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. // 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)
@ -155,10 +158,14 @@ type MessageListeners struct {
// message. // message.
OnGetCFilter func(p *Peer, msg *wire.MsgGetCFilter) 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. // 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)
@ -1601,6 +1608,11 @@ 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)
@ -1611,6 +1623,11 @@ 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)

View file

@ -405,12 +405,18 @@ 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
}, },
@ -542,6 +548,10 @@ func TestPeerListeners(t *testing.T) {
"OnGetCFHeaders", "OnGetCFHeaders",
wire.NewMsgGetCFHeaders(), wire.NewMsgGetCFHeaders(),
}, },
{
"OnGetCFTypes",
wire.NewMsgGetCFTypes(),
},
{ {
"OnCFilter", "OnCFilter",
wire.NewMsgCFilter(&chainhash.Hash{}, 1, wire.NewMsgCFilter(&chainhash.Hash{}, 1,
@ -551,6 +561,10 @@ func TestPeerListeners(t *testing.T) {
"OnCFHeaders", "OnCFHeaders",
wire.NewMsgCFHeaders(), wire.NewMsgCFHeaders(),
}, },
{
"OnCFTypes",
wire.NewMsgCFTypes([]uint8{0, 1}),
},
{ {
"OnFeeFilter", "OnFeeFilter",
wire.NewMsgFeeFilter(15000), wire.NewMsgFeeFilter(15000),