From 43bf8db793e5a97d69badab6e458d5659c80351a Mon Sep 17 00:00:00 2001 From: pedro martelletto Date: Thu, 12 Jan 2017 15:28:27 +0000 Subject: [PATCH] Look up filters from p2p GetCBF message --- blockchain/indexers/cbfindex.go | 11 +++++++++++ server.go | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/blockchain/indexers/cbfindex.go b/blockchain/indexers/cbfindex.go index 967ca762..178c8871 100644 --- a/blockchain/indexers/cbfindex.go +++ b/blockchain/indexers/cbfindex.go @@ -156,6 +156,17 @@ func (idx *CBFIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, vie return nil } +func (idx *CBFIndex) GetFilterByBlockHash(hash *chainhash.Hash) ([]byte, + error) { + var filterBytes []byte + err := idx.db.View(func(dbTx database.Tx) error { + var err error + filterBytes, err = dbFetchCBFIndexEntry(dbTx, hash) + return err + }) + return filterBytes, err +} + // NewCBFIndex returns a new instance of an indexer that is used to create a // mapping of the hashes of all blocks in the blockchain to their respective // committed bloom filters. diff --git a/server.go b/server.go index 6d8736b0..850ada52 100644 --- a/server.go +++ b/server.go @@ -746,8 +746,14 @@ func (sp *serverPeer) OnGetCBFilter(_ *peer.Peer, msg *wire.MsgGetCBFilter) { return } - // XXX work in progress - peerLog.Warnf("received OnGetCBFilter: not yet") + filterBytes, err := sp.server.cbfIndex.GetFilterByBlockHash(&msg.BlockHash) + + if len(filterBytes) > 0 { + peerLog.Infof("Obtained CB filter for %v", msg.BlockHash) + } else { + peerLog.Infof("Could not obtain CB filter for %v: %v", + msg.BlockHash, err) + } } // enforceNodeBloomFlag disconnects the peer if the server is not configured to