Ejemplo n.º 1
0
InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq)
{
    assert (hash.isNonZero ());
    boost::mutex::scoped_lock sl (mLock);
    InboundLedger::pointer& ptr = mLedgers[hash];

    if (ptr)
    {
        ptr->touch ();
        return ptr;
    }

    ptr = boost::make_shared<InboundLedger> (hash, seq);

    if (!ptr->isDone ())
    {
        ptr->addPeers ();
        ptr->setTimer (); // Cannot call in constructor
    }
    else
    {
        Ledger::pointer ledger = ptr->getLedger ();
        ledger->setClosed ();
        ledger->setImmutable ();
        theApp->getLedgerMaster ().storeLedger (ledger);
        WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have: " << hash;
    }

    return ptr;
}
InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq)
{
    assert (hash.isNonZero ());
    InboundLedger::pointer ret;

    {
        boost::mutex::scoped_lock sl (mLock);

        boost::unordered_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 = boost::make_shared<InboundLedger> (hash, seq);
            assert (ret);
            mLedgers.insert (std::make_pair (hash, ret));

            if (!ret->tryLocal())
            {
                ret->addPeers ();
                ret->setTimer (); // Cannot call in constructor
            }
            else if (!ret->isFailed ())
            {
                WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have locally: " << hash;
                Ledger::pointer ledger = ret->getLedger ();
                ledger->setClosed ();
                ledger->setImmutable ();
                getApp().getLedgerMaster ().storeLedger (ledger);
            }
        }
    }

    return ret;
}