当前位置: 首页>>代码示例>>Java>>正文


Java FilterMerger类代码示例

本文整理汇总了Java中org.bitcoinj.net.FilterMerger的典型用法代码示例。如果您正苦于以下问题:Java FilterMerger类的具体用法?Java FilterMerger怎么用?Java FilterMerger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FilterMerger类属于org.bitcoinj.net包,在下文中一共展示了FilterMerger类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recalculateFastCatchupAndFilter

import org.bitcoinj.net.FilterMerger; //导入依赖的package包/类
/**
 * Recalculates the bloom filter given to peers as well as the timestamp after which full blocks are downloaded
 * (instead of only headers).
 *
 * @param mode In what situations to send the filter to connected peers.
 */
public void recalculateFastCatchupAndFilter(FilterRecalculateMode mode) {
    lock.lock();
    try {
        // Fully verifying mode doesn't use this optimization (it can't as it needs to see all transactions).
        if (chain != null && chain.shouldVerifyTransactions())
            return;
        FilterMerger.Result result = bloomFilterMerger.calculate(ImmutableList.copyOf(peerFilterProviders));
        boolean send;
        switch (mode) {
            case SEND_IF_CHANGED: send = result.changed; break;
            case DONT_SEND: send = false; break;
            case FORCE_SEND_FOR_REFRESH: send = true; break;
            default: throw new UnsupportedOperationException();
        }
        if (send) {
            for (Peer peer : peers) {
                // Only query the mempool if this recalculation request is not in order to lower the observed FP
                // rate. There's no point querying the mempool when doing this because the FP rate can only go
                // down, and we will have seen all the relevant txns before: it's pointless to ask for them again.
                peer.setBloomFilter(result.filter, mode != FilterRecalculateMode.FORCE_SEND_FOR_REFRESH);
            }
            // Reset the false positive estimate so that we don't send a flood of filter updates
            // if the estimate temporarily overshoots our threshold.
            if (chain != null)
                chain.resetFalsePositiveEstimate();
        }
        // Do this last so that bloomFilter is already set when it gets called.
        setFastCatchupTimeSecs(result.earliestKeyTimeSecs);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:39,代码来源:PeerGroup.java

示例2: PeerGroup

import org.bitcoinj.net.FilterMerger; //导入依赖的package包/类
/**
 * Creates a new PeerGroup allowing you to specify the {@link ClientConnectionManager} which is used to create new
 * connections and keep track of existing ones.
 */
private PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager, @Nullable TorClient torClient) {
    this.params = checkNotNull(params);
    this.chain = chain;
    fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
    wallets = new CopyOnWriteArrayList<Wallet>();
    peerFilterProviders = new CopyOnWriteArrayList<PeerFilterProvider>();
    this.torClient = torClient;

    // This default sentinel value will be overridden by one of two actions:
    //   - adding a peer discovery source sets it to the default
    //   - using connectTo() will increment it by one
    maxConnections = 0;

    int height = chain == null ? 0 : chain.getBestChainHeight();
    versionMessage = new VersionMessage(params, height);
    // We never request that the remote node wait for a bloom filter yet, as we have no wallets
    versionMessage.relayTxesBeforeFilter = true;

    downloadTxDependencies = true;

    memoryPool = new MemoryPool();

    inactives = new PriorityQueue<PeerAddress>(1, new Comparator<PeerAddress>() {
        @Override
        public int compare(PeerAddress a, PeerAddress b) {
            int result = backoffMap.get(a).compareTo(backoffMap.get(b));
            // Sort by port if otherwise equals - for testing
            if (result == 0)
                result = Ints.compare(a.getPort(), b.getPort());
            return result;
        }
    });
    backoffMap = new HashMap<PeerAddress, ExponentialBackoff>();
    peers = new CopyOnWriteArrayList<Peer>();
    pendingPeers = new CopyOnWriteArrayList<Peer>();
    channels = connectionManager;
    peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>();
    peerEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerEventListener>>();
    runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
    bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:46,代码来源:PeerGroup.java


注:本文中的org.bitcoinj.net.FilterMerger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。