rippled
Loading...
Searching...
No Matches
HashRouter.cpp
1#include <xrpl/core/HashRouter.h>
2
3namespace xrpl {
4
5auto
7{
8 auto iter = suppressionMap_.find(key);
9
10 if (iter != suppressionMap_.end())
11 {
12 suppressionMap_.touch(iter);
13 return std::make_pair(std::ref(iter->second), false);
14 }
15
16 // See if any suppressions need to be expired
17 expire(suppressionMap_, setup_.holdTime);
18
19 return std::make_pair(std::ref(suppressionMap_.emplace(key, Entry()).first->second), true);
20}
21
22void
24{
26
27 emplace(key);
28}
29
30bool
32{
33 return addSuppressionPeerWithStatus(key, peer).first;
34}
35
38{
40
41 auto result = emplace(key);
42 result.first.addPeer(peer);
43 return {result.second, result.first.relayed()};
44}
45
46bool
48{
50
51 auto [s, created] = emplace(key);
52 s.addPeer(peer);
53 flags = s.getFlags();
54 return created;
55}
56
57bool
59 uint256 const& key,
60 PeerShortID peer,
61 HashRouterFlags& flags,
62 std::chrono::seconds tx_interval)
63{
65
66 auto result = emplace(key);
67 auto& s = result.first;
68 s.addPeer(peer);
69 flags = s.getFlags();
70 return s.shouldProcess(suppressionMap_.clock().now(), tx_interval);
71}
72
75{
77
78 return emplace(key).first.getFlags();
79}
80
81bool
83{
84 XRPL_ASSERT(static_cast<bool>(flags), "xrpl::HashRouter::setFlags : valid input");
85
87
88 auto& s = emplace(key).first;
89
90 if ((s.getFlags() & flags) == flags)
91 return false;
92
93 s.setFlags(flags);
94 return true;
95}
96
97auto
99{
100 std::lock_guard lock(mutex_);
101
102 auto& s = emplace(key).first;
103
104 if (!s.shouldRelay(suppressionMap_.clock().now(), setup_.relayTime))
105 return {};
106
107 return s.releasePeerSet();
108}
109
110} // namespace xrpl
An entry in the routing table.
Definition HashRouter.h:110
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
HashRouterFlags getFlags(uint256 const &key)
bool addSuppressionPeer(uint256 const &key, PeerShortID peer)
std::mutex mutex_
Definition HashRouter.h:245
bool setFlags(uint256 const &key, HashRouterFlags flags)
Set the flags on a hash.
std::pair< bool, std::optional< Stopwatch::time_point > > addSuppressionPeerWithStatus(uint256 const &key, PeerShortID peer)
Add a suppression peer and get message's relay status.
std::pair< Entry &, bool > emplace(uint256 const &)
Definition HashRouter.cpp:6
beast::aged_unordered_map< uint256, Entry, Stopwatch::clock_type, hardened_hash< strong_hash > > suppressionMap_
Definition HashRouter.h:251
void addSuppression(uint256 const &key)
bool shouldProcess(uint256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds tx_interval)
T make_pair(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
HashRouterFlags
Definition HashRouter.h:14
T ref(T... args)