From 2b7ebfd69804b349e9557f1e4b292dfb2fab0a5d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 Oct 2017 21:24:31 -0600 Subject: [PATCH] peer: add OnCFTypes and OnGetCFTypes callbacks --- peer/peer.go | 21 +++++++++++++++++++-- peer/peer_test.go | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/peer/peer.go b/peer/peer.go index ec84a0a0..b6a5da5e 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -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) diff --git a/peer/peer_test.go b/peer/peer_test.go index 701df744..89d114b1 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -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),