예제 #1
0
    Ledger::pointer acquire (uint256 const& hash, std::uint32_t seq, InboundLedger::fcReason reason)
    {
        assert (hash.isNonZero ());
        InboundLedger::pointer inbound;
        {
            ScopedLockType sl (mLock);

            if (! isStopping ())
            {
                auto it = mLedgers.find (hash);
                if (it != mLedgers.end ())
                {
                    inbound = it->second;

                    // If the acquisition failed, don't mark the item as
                    // recently accessed so that it can expire.
                    if (! inbound->isFailed ())
                        inbound->update (seq);
                }
                else
                {
                    inbound = std::make_shared <InboundLedger> (
                        hash, seq, reason, std::ref (m_clock));
                    mLedgers.emplace (hash, inbound);
                    inbound->init (sl);
                    ++mCounter;
                }
            }
        }
        if (inbound && inbound->isComplete ())
            return inbound->getLedger();
        return {};
    }
예제 #2
0
    // VFALCO TODO Should this be called findOrAdd ?
    //
    InboundLedger::pointer findCreate (uint256 const& hash, std::uint32_t seq, InboundLedger::fcReason reason)
    {
        assert (hash.isNonZero ());
        InboundLedger::pointer ret;

        // Ensure that any previous IL is destroyed outside the lock
        InboundLedger::pointer oldLedger;

        {
            ScopedLockType sl (mLock);

            if (! isStopping ())
            {

                if (reason == InboundLedger::fcCONSENSUS)
                {
                    if (mConsensusLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mConsensusLedger))
                    {
                        hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mConsensusLedger);
                        if (it != mLedgers.end ())
                        {
                            oldLedger = it->second;
                            mLedgers.erase (it);
                        }
                    }
                    mConsensusLedger = hash;
                }
                else if (reason == InboundLedger::fcVALIDATION)
                {
                    if (mValidationLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mValidationLedger))
                    {
                        hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mValidationLedger);
                        if (it != mLedgers.end ())
                        {
                            oldLedger = it->second;
                            mLedgers.erase (it);
                       }
                    }
                    mValidationLedger = hash;
                }

                hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
                if (it != mLedgers.end ())
                {
                    ret = it->second;
                    // FIXME: Should set the sequence if it's not set
                }
                else
                {
                    ret = std::make_shared <InboundLedger> (hash, seq, reason, std::ref (m_clock));
                    assert (ret);
                    mLedgers.insert (std::make_pair (hash, ret));
                    ret->init (sl);
                    ++mCounter;
                }
            }
        }

        return ret;
    }