rippled
RippleLineCache.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/paths/RippleLineCache.h>
21 #include <ripple/app/paths/TrustLine.h>
22 #include <ripple/ledger/OpenView.h>
23 
24 namespace ripple {
25 
27  std::shared_ptr<ReadView const> const& ledger,
29  : journal_(j)
30 {
31  mLedger = ledger;
32 
33  JLOG(journal_.debug()) << "RippleLineCache created for ledger "
34  << mLedger->info().seq;
35 }
36 
38 {
39  JLOG(journal_.debug()) << "~RippleLineCache destroyed for ledger "
40  << mLedger->info().seq << " with " << lines_.size()
41  << " accounts";
42 }
43 
46 {
47  AccountKey key(accountID, hasher_(accountID));
48 
50 
51  auto [it, inserted] = lines_.emplace(key, std::vector<PathFindTrustLine>());
52 
53  if (inserted)
54  it->second = PathFindTrustLine::getItems(accountID, *mLedger);
55 
56  JLOG(journal_.debug()) << "RippleLineCache getRippleLines for ledger "
57  << mLedger->info().seq << " found "
58  << it->second.size() << " lines for "
59  << (inserted ? "new " : "existing ") << accountID
60  << " out of a total of " << lines_.size()
61  << " accounts";
62 
63  return it->second;
64 }
65 
66 } // namespace ripple
ripple::RippleLineCache::mLedger
std::shared_ptr< ReadView const > mLedger
Definition: RippleLineCache.h:57
std::shared_ptr
STL class.
ripple::RippleLineCache::mLock
std::mutex mLock
Definition: RippleLineCache.h:54
std::vector
STL class.
std::lock_guard
STL class.
ripple::RippleLineCache::AccountKey
Definition: RippleLineCache.h:61
ripple::base_uint< 160, detail::AccountIDTag >
ripple::PathFindTrustLine::getItems
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition: TrustLine.cpp:81
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::RippleLineCache::getRippleLines
std::vector< PathFindTrustLine > const & getRippleLines(AccountID const &accountID)
Definition: RippleLineCache.cpp:45
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RippleLineCache::~RippleLineCache
~RippleLineCache()
Definition: RippleLineCache.cpp:37
ripple::RippleLineCache::RippleLineCache
RippleLineCache(std::shared_ptr< ReadView const > const &l, beast::Journal j)
Definition: RippleLineCache.cpp:26
ripple::RippleLineCache::hasher_
ripple::hardened_hash hasher_
Definition: RippleLineCache.h:56
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::RippleLineCache::lines_
hash_map< AccountKey, std::vector< PathFindTrustLine >, AccountKey::Hash > lines_
Definition: RippleLineCache.h:101
ripple::RippleLineCache::journal_
beast::Journal journal_
Definition: RippleLineCache.h:59