Bloom filtering: add a convenience BloomFilter.insert(ECKey) method.

This commit is contained in:
Mike Hearn 2014-09-17 13:53:46 +02:00
parent 843e785daf
commit 8d83f4d25b
2 changed files with 8 additions and 4 deletions

View File

@ -228,6 +228,12 @@ public class BloomFilter extends Message {
Utils.setBitLE(data, hash(i, object));
}
/** Inserts the given key and equivalent hashed form (for the address). */
public void insert(ECKey key) {
insert(key.getPubKey());
insert(key.getPubKeyHash());
}
/**
* Sets this filter to match all objects. A Bloom filter which matches everything may seem pointless, however,
* it is useful in order to reduce steady state bandwidth usage when you want full blocks. Instead of receiving

View File

@ -531,10 +531,8 @@ public class BasicKeyChain implements EncryptableKeyChain {
lock.lock();
try {
BloomFilter filter = new BloomFilter(size, falsePositiveRate, tweak);
for (ECKey key : hashToKeys.values()) {
filter.insert(key.getPubKey());
filter.insert(key.getPubKeyHash());
}
for (ECKey key : hashToKeys.values())
filter.insert(key);
return filter;
} finally {
lock.unlock();