def create_empty_bloomfilter(self): """Create an empty bloom filter with byte aligness.""" bf = BloomFilter(capacity=self.cache.quota, error_rate=self.error_rate) bs = bf.bitarray.tostring() bf.bitarray = bitarray() bf.bitarray.fromstring(bs) return bf
def graphene_handler(connection, graphene): logging.info("Graphene received!") b = bitarray() b.frombytes(graphene.bloom_filter[::-1]) b.reverse() bf = BloomFilter(capacity=graphene.bloom_filter_capacity, error_rate=graphene.fpr) bf.bitarray = b iblt = IBLT(m=graphene.iblt_m, k=3, key_size=32, value_size=0) iblt.T = graphene.iblt_T iblt2 = IBLT(m=graphene.iblt_m, k=3, key_size=32, value_size=0) found = 0 for tx in selected_txs: if tx['hash'] in bf: found += 1 # logging.info("%s present in the bloom filter!" % tx['hash']) iblt2.insert(tx['hash'], '') else: # logging.info("%s missing from bloom filter" % tx['hash']) pass logging.info("Found and inserted %d txs into the second IBLT" % found) unrecovered = reconcile_iblts(iblt, iblt2) with open('data/%s_results.txt' % block_height, 'a') as fout: graphene = (bf.num_bits + iblt.m * (4 + 32 + 10) * 8) / 8 cmpct = bytes_pushed['cmpct'] xthin = bf.num_bits / 8 + 8 * (len(selected_txs) + len(skipped_txs)) txs = sum(bytes_pushed['txs']) fout.write('%f,%d,%d,%d,%d,%d,%d,%d\n' % (MEMPOOL_PCT, txs, graphene, cmpct, xthin, len(unrecovered), bytes_pushed['n_txs'], len(skipped_txs))) logging.info("Number of bytes for graphene block: %d" % graphene) logging.info("Minimum number of bytes for compact block: %d" % cmpct) logging.info("Minimum number of bytes for xthin block: %d" % xthin) logging.info("Number of bytes for txs: %d" % txs) sys.exit(0)
def copy(self): """Return a copy of this bloom filter. """ new_filter = BloomFilter(self.capacity, self.error_rate) new_filter.bitarray = self.bitarray.copy() return new_filter
def _bloomfilter_deserialize(data): bf = BloomFilter(1) # Bogus instantiation, we will `_setup'. bf._setup(*unpack(BloomFilter.FILE_FMT, b64decode(data[0]))) bf.bitarray = _bitarray_deserialize(data[1]) return bf