當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。