rippled
Loading...
Searching...
No Matches
RippleLineCache.h
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#ifndef RIPPLE_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
21#define RIPPLE_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/paths/TrustLine.h>
25#include <xrpl/basics/CountedObject.h>
26#include <xrpl/basics/hardened_hash.h>
27
28#include <cstddef>
29#include <mutex>
30#include <vector>
31
32namespace ripple {
33
34// Used by Pathfinder
35class RippleLineCache final : public CountedObject<RippleLineCache>
36{
37public:
38 explicit RippleLineCache(
42
44 getLedger() const
45 {
46 return ledger_;
47 }
48
62 getRippleLines(AccountID const& accountID, LineDirection direction);
63
64private:
66
69
71
72 struct AccountKey final : public CountedObject<AccountKey>
73 {
77
79 AccountID const& account,
80 LineDirection direction,
81 std::size_t hash)
82 : account_(account), direction_(direction), hash_value_(hash)
83 {
84 }
85
86 AccountKey(AccountKey const& other) = default;
87
89 operator=(AccountKey const& other) = default;
90
91 bool
92 operator==(AccountKey const& lhs) const
93 {
94 return hash_value_ == lhs.hash_value_ && account_ == lhs.account_ &&
96 }
97
99 get_hash() const
100 {
101 return hash_value_;
102 }
103
104 struct Hash
105 {
106 explicit Hash() = default;
107
109 operator()(AccountKey const& key) const noexcept
110 {
111 return key.get_hash();
112 }
113 };
114 };
115
116 // Use a shared_ptr so entries can be removed from the map safely.
117 // Even though a shared_ptr to a vector will take more memory just a vector,
118 // most accounts are not going to have any entries (estimated over 90%), so
119 // vectors will not need to be created for them. This should lead to far
120 // less memory usage overall.
121 hash_map<
122 AccountKey,
124 AccountKey::Hash>
127};
128
129} // namespace ripple
130
131#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Tracks the number of instances of an object.
std::shared_ptr< ReadView const > ledger_
std::shared_ptr< ReadView const > const & getLedger() const
ripple::hardened_hash hasher_
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
Seed functor once per construction.
Definition: hardened_hash.h:97
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition: TrustLine.h:41
std::size_t operator()(AccountKey const &key) const noexcept
AccountKey(AccountKey const &other)=default
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)
AccountKey & operator=(AccountKey const &other)=default
bool operator==(AccountKey const &lhs) const