mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
PeerGroup, FilterMerger: deprecate setting false-positive rate
In the bitcoinj code itself, the false-positive rate is never changed after constructing a `PeerGroup` or a `FilterMerger`. * Deprecate methods for setting Bloom Filter FP rate in both methods * Add constructor params to `PeerGroup` so they can be set at construction time, if non-default values are needed
This commit is contained in:
parent
5955eee4c8
commit
81b78292e2
3 changed files with 20 additions and 4 deletions
|
@ -417,7 +417,19 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||||
* @param connectionManager used to create new connections and keep track of existing ones.
|
* @param connectionManager used to create new connections and keep track of existing ones.
|
||||||
*/
|
*/
|
||||||
protected PeerGroup(Network network, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
protected PeerGroup(Network network, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
||||||
this(NetworkParameters.of(Objects.requireNonNull(network)), chain, connectionManager);
|
this(NetworkParameters.of(Objects.requireNonNull(network)), chain, connectionManager, DEFAULT_BLOOM_FILTER_FP_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a PeerGroup for the given network, chain and connection manager.
|
||||||
|
* @param network the P2P network to connect to
|
||||||
|
* @param chain used to process blocks
|
||||||
|
* @param connectionManager used to create new connections and keep track of existing ones.
|
||||||
|
* @param bloomFilterFpRate false positive rate for bloom filters
|
||||||
|
*/
|
||||||
|
protected PeerGroup(Network network, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager, double bloomFilterFpRate) {
|
||||||
|
this(NetworkParameters.of(Objects.requireNonNull(network)), chain, connectionManager, bloomFilterFpRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,9 +437,10 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||||
* @param params the P2P network to connect to
|
* @param params the P2P network to connect to
|
||||||
* @param chain used to process blocks
|
* @param chain used to process blocks
|
||||||
* @param connectionManager used to create new connections and keep track of existing ones.
|
* @param connectionManager used to create new connections and keep track of existing ones.
|
||||||
|
* @param bloomFilterFpRate false positive rate for bloom filters
|
||||||
*/
|
*/
|
||||||
// For testing only
|
// For testing only
|
||||||
protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager, double bloomFilterFpRate) {
|
||||||
Objects.requireNonNull(params);
|
Objects.requireNonNull(params);
|
||||||
Context.getOrCreate(); // create a context for convenience
|
Context.getOrCreate(); // create a context for convenience
|
||||||
this.params = params;
|
this.params = params;
|
||||||
|
@ -473,7 +486,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||||
channels = connectionManager;
|
channels = connectionManager;
|
||||||
peerDiscoverers = new CopyOnWriteArraySet<>();
|
peerDiscoverers = new CopyOnWriteArraySet<>();
|
||||||
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
|
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
|
||||||
bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
|
bloomFilterMerger = new FilterMerger(bloomFilterFpRate);
|
||||||
vMinRequiredProtocolVersion = ProtocolVersion.BLOOM_FILTER.intValue();
|
vMinRequiredProtocolVersion = ProtocolVersion.BLOOM_FILTER.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1430,6 +1443,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||||
* <p>See the docs for {@link BloomFilter#BloomFilter(int, double, int, BloomFilter.BloomUpdate)} for a brief
|
* <p>See the docs for {@link BloomFilter#BloomFilter(int, double, int, BloomFilter.BloomUpdate)} for a brief
|
||||||
* explanation of anonymity when using bloom filters.</p>
|
* explanation of anonymity when using bloom filters.</p>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) {
|
public void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class FilterMerger {
|
||||||
// We use a constant tweak to avoid giving up privacy when we regenerate our filter with new keys
|
// We use a constant tweak to avoid giving up privacy when we regenerate our filter with new keys
|
||||||
private final int bloomFilterTweak = new Random().nextInt();
|
private final int bloomFilterTweak = new Random().nextInt();
|
||||||
|
|
||||||
|
// TODO: Make final after deprecated setBloomFilterFPRate() method is removed
|
||||||
private volatile double vBloomFilterFPRate;
|
private volatile double vBloomFilterFPRate;
|
||||||
private int lastBloomFilterElementCount;
|
private int lastBloomFilterElementCount;
|
||||||
private BloomFilter lastFilter;
|
private BloomFilter lastFilter;
|
||||||
|
@ -108,6 +109,7 @@ public class FilterMerger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setBloomFilterFPRate(double bloomFilterFPRate) {
|
public void setBloomFilterFPRate(double bloomFilterFPRate) {
|
||||||
this.vBloomFilterFPRate = bloomFilterFPRate;
|
this.vBloomFilterFPRate = bloomFilterFPRate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class TestWithPeerGroup extends TestWithNetworkConnections {
|
||||||
protected final Semaphore jobBlocks = new Semaphore(0);
|
protected final Semaphore jobBlocks = new Semaphore(0);
|
||||||
|
|
||||||
private PeerGroup createPeerGroup(final ClientConnectionManager manager) {
|
private PeerGroup createPeerGroup(final ClientConnectionManager manager) {
|
||||||
return new PeerGroup(UNITTEST, blockChain, manager) {
|
return new PeerGroup(UNITTEST, blockChain, manager, PeerGroup.DEFAULT_BLOOM_FILTER_FP_RATE) {
|
||||||
@Override
|
@Override
|
||||||
protected ListeningScheduledExecutorService createPrivateExecutor() {
|
protected ListeningScheduledExecutorService createPrivateExecutor() {
|
||||||
return MoreExecutors.listeningDecorator(new ScheduledThreadPoolExecutor(1, new ContextPropagatingThreadFactory("PeerGroup test thread")) {
|
return MoreExecutors.listeningDecorator(new ScheduledThreadPoolExecutor(1, new ContextPropagatingThreadFactory("PeerGroup test thread")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue