From 2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 11 Aug 2014 16:23:17 +0200 Subject: Added bloom filter & block filter methods --- ethchain/bloom.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ethchain/bloom.go (limited to 'ethchain/bloom.go') diff --git a/ethchain/bloom.go b/ethchain/bloom.go new file mode 100644 index 000000000..320ce73fc --- /dev/null +++ b/ethchain/bloom.go @@ -0,0 +1,47 @@ +package ethchain + +type BloomFilter struct { + bin []byte +} + +func NewBloomFilter(bin []byte) *BloomFilter { + if bin == nil { + bin = make([]byte, 255) + } + + return &BloomFilter{ + bin: bin, + } +} + +func (self *BloomFilter) Set(addr []byte) { + if len(addr) < 8 { + chainlogger.Warnf("err: bloom set to small: %x\n", addr) + + return + } + + for _, i := range addr[len(addr)-8:] { + self.bin[i] = 1 + } +} + +func (self *BloomFilter) Search(addr []byte) bool { + if len(addr) < 8 { + chainlogger.Warnf("err: bloom search to small: %x\n", addr) + + return false + } + + for _, i := range addr[len(addr)-8:] { + if self.bin[i] == 0 { + return false + } + } + + return true +} + +func (self *BloomFilter) Bin() []byte { + return self.bin +} -- cgit From fa881220aedb638f9ee35337b2ca1817c2a8482f Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 13 Aug 2014 10:52:50 +0200 Subject: Updated lookup method to include CNAME's as well as A records --- ethchain/bloom.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/bloom.go') diff --git a/ethchain/bloom.go b/ethchain/bloom.go index 320ce73fc..5317ca0b1 100644 --- a/ethchain/bloom.go +++ b/ethchain/bloom.go @@ -6,7 +6,7 @@ type BloomFilter struct { func NewBloomFilter(bin []byte) *BloomFilter { if bin == nil { - bin = make([]byte, 255) + bin = make([]byte, 256) } return &BloomFilter{ -- cgit