Skip to content

Commit 58547f6

Browse files
HowardHinnantvinniefalco
authored andcommitted
Tidy up hardened containers (RIPD-380):
* Rename hardened containers for clarity * Fixes https://ripplelabs.atlassian.net/browse/RIPD-380
1 parent e6f4eed commit 58547f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+179
-170
lines changed

src/ripple/basics/containers/SyncUnorderedMap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SyncUnorderedMapType : public SyncUnorderedMap
4343
public:
4444
typedef c_Key key_type;
4545
typedef c_Data data_type;
46-
typedef ripple::unordered_map<c_Key, c_Data, c_Hash> map_type;
46+
typedef hash_map<c_Key, c_Data, c_Hash> map_type;
4747

4848
class iterator
4949
{

src/ripple/basics/log/Log.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef RIPPLE_BASICS_LOG_H_INCLUDED
2121
#define RIPPLE_BASICS_LOG_H_INCLUDED
2222

23+
#include <ripple/common/UnorderedContainers.h>
2324
#include <beast/utility/Journal.h>
2425
#include <beast/utility/noexcept.h>
2526
#include <boost/filesystem.hpp>
@@ -139,7 +140,7 @@ class Logs
139140
};
140141

141142
std::mutex mutable mutex_;
142-
std::unordered_map <std::string, Sink> sinks_;
143+
hardened_hash_map <std::string, Sink> sinks_;
143144
beast::Journal::Severity level_;
144145
File file_;
145146

src/ripple/common/KeyCache.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define RIPPLE_KEYCACHE_H_INCLUDED
2222

2323
#include <mutex>
24-
#include <unordered_map>
2524

2625
#include <beast/chrono/abstract_clock.h>
2726
#include <beast/chrono/chrono_io.h>
@@ -40,7 +39,7 @@ namespace ripple {
4039
// VFALCO TODO Figure out how to pass through the allocator
4140
template <
4241
class Key,
43-
class Hash = beast::hardened_hash <Key>,
42+
class Hash = beast::hardened_hash <>,
4443
class KeyEqual = std::equal_to <Key>,
4544
//class Allocator = std::allocator <std::pair <Key const, Entry>>,
4645
class Mutex = std::mutex
@@ -82,7 +81,7 @@ class KeyCache
8281
clock_type::time_point last_access;
8382
};
8483

85-
typedef ripple::unordered_map <key_type, Entry, Hash, KeyEqual> map_type;
84+
typedef hardened_hash_map <key_type, Entry, Hash, KeyEqual> map_type;
8685
typedef typename map_type::iterator iterator;
8786
typedef std::lock_guard <Mutex> lock_guard;
8887

src/ripple/common/TaggedCache.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <beast/container/hardened_hash.h>
2828
#include <functional>
2929
#include <mutex>
30-
#include <unordered_map>
3130
#include <vector>
3231

3332
namespace ripple {
@@ -51,7 +50,7 @@ struct TaggedCacheLog;
5150
template <
5251
class Key,
5352
class T,
54-
class Hash = beast::hardened_hash <Key>,
53+
class Hash = beast::hardened_hash <>,
5554
class KeyEqual = std::equal_to <Key>,
5655
//class Allocator = std::allocator <std::pair <Key const, Entry>>,
5756
class Mutex = std::recursive_mutex
@@ -528,7 +527,7 @@ class TaggedCache
528527
};
529528

530529
typedef std::pair <key_type, Entry> cache_pair;
531-
typedef ripple::unordered_map <key_type, Entry, Hash, KeyEqual> cache_type;
530+
typedef hardened_hash_map <key_type, Entry, Hash, KeyEqual> cache_type;
532531
typedef typename cache_type::iterator cache_iterator;
533532

534533
beast::Journal m_journal;

src/ripple/common/UnorderedContainers.h

+48-2
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,69 @@
2020
#ifndef RIPPLE_UNORDERED_CONTAINERS_H
2121
#define RIPPLE_UNORDERED_CONTAINERS_H
2222

23+
#include <beast/container/hardened_hash.h>
2324
#include <beast/container/hash_append.h>
2425

2526
#include <unordered_map>
2627
#include <unordered_set>
2728

29+
/**
30+
* Use hash_* containers for keys that do not need a cryptographically secure
31+
* hashing algorithm.
32+
*
33+
* Use hardened_hash_* containers for keys that do need a secure hashing algorithm.
34+
*
35+
* The cryptographic security of containers where a hash function is used as a
36+
* template parameter depends entirely on that hash function and not at all on
37+
* what container it is.
38+
*/
39+
2840
namespace ripple
2941
{
3042

43+
// hash containers
44+
45+
template <class Key, class Value, class Hash = beast::uhash<>,
46+
class Pred = std::equal_to<Key>,
47+
class Allocator = std::allocator<std::pair<Key const, Value>>>
48+
using hash_map = std::unordered_map <Key, Value, Hash, Pred, Allocator>;
49+
3150
template <class Key, class Value, class Hash = beast::uhash<>,
3251
class Pred = std::equal_to<Key>,
3352
class Allocator = std::allocator<std::pair<Key const, Value>>>
34-
using unordered_map = std::unordered_map <Key, Value, Hash, Pred, Allocator>;
53+
using hash_multimap = std::unordered_multimap <Key, Value, Hash, Pred, Allocator>;
54+
55+
template <class Value, class Hash = beast::uhash<>,
56+
class Pred = std::equal_to<Value>,
57+
class Allocator = std::allocator<Value>>
58+
using hash_set = std::unordered_set <Value, Hash, Pred, Allocator>;
3559

3660
template <class Value, class Hash = beast::uhash<>,
3761
class Pred = std::equal_to<Value>,
3862
class Allocator = std::allocator<Value>>
39-
using unordered_set = std::unordered_set <Value, Hash, Pred, Allocator>;
63+
using hash_multiset = std::unordered_multiset <Value, Hash, Pred, Allocator>;
64+
65+
// hardened_hash containers
66+
67+
template <class Key, class Value, class Hash = beast::hardened_hash<>,
68+
class Pred = std::equal_to<Key>,
69+
class Allocator = std::allocator<std::pair<Key const, Value>>>
70+
using hardened_hash_map = std::unordered_map <Key, Value, Hash, Pred, Allocator>;
71+
72+
template <class Key, class Value, class Hash = beast::hardened_hash<>,
73+
class Pred = std::equal_to<Key>,
74+
class Allocator = std::allocator<std::pair<Key const, Value>>>
75+
using hardened_hash_multimap = std::unordered_multimap <Key, Value, Hash, Pred, Allocator>;
76+
77+
template <class Value, class Hash = beast::hardened_hash<>,
78+
class Pred = std::equal_to<Value>,
79+
class Allocator = std::allocator<Value>>
80+
using hardened_hash_set = std::unordered_set <Value, Hash, Pred, Allocator>;
81+
82+
template <class Value, class Hash = beast::hardened_hash<>,
83+
class Pred = std::equal_to<Value>,
84+
class Allocator = std::allocator<Value>>
85+
using hardened_hash_multiset = std::unordered_multiset <Value, Hash, Pred, Allocator>;
4086

4187
} // ripple
4288

src/ripple/module/app/consensus/DisputedTx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DisputedTx
7979
bool mOurVote;
8080
Serializer transaction;
8181

82-
ripple::unordered_map <NodeID, bool> mVotes;
82+
hash_map <NodeID, bool> mVotes;
8383
};
8484

8585
// How many total extra passes we make

src/ripple/module/app/consensus/LedgerConsensus.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ class LedgerConsensusImp
475475

476476
// Get validators that are on our ledger, or "close" to being on
477477
// our ledger.
478-
ripple::unordered_map<uint256, ValidationCounter> vals =
478+
hash_map<uint256, ValidationCounter> vals =
479479
getApp().getValidations ().getCurrentValidations
480480
(favoredLedger, priorLedger);
481481

@@ -1687,7 +1687,7 @@ class LedgerConsensusImp
16871687
}
16881688

16891689
// if any peers have taken a contrary position, process disputes
1690-
ripple::unordered_set<uint256> found;
1690+
hash_set<uint256> found;
16911691

16921692
for (auto& it : mPeerPositions)
16931693
{
@@ -2093,19 +2093,18 @@ class LedgerConsensusImp
20932093
int mPreviousMSeconds;
20942094

20952095
// Convergence tracking, trusted peers indexed by hash of public key
2096-
ripple::unordered_map<NodeID, LedgerProposal::pointer> mPeerPositions;
2096+
hash_map<NodeID, LedgerProposal::pointer> mPeerPositions;
20972097

20982098
// Transaction Sets, indexed by hash of transaction tree
2099-
ripple::unordered_map<uint256, SHAMap::pointer> mAcquired;
2100-
ripple::unordered_map<uint256, TransactionAcquire::pointer> mAcquiring;
2099+
hash_map<uint256, SHAMap::pointer> mAcquired;
2100+
hash_map<uint256, TransactionAcquire::pointer> mAcquiring;
21012101

21022102
// Peer sets
2103-
ripple::unordered_map<uint256
2104-
, std::vector< std::weak_ptr<Peer> > > mPeerData;
2103+
hash_map<uint256, std::vector< std::weak_ptr<Peer> > > mPeerData;
21052104

21062105
// Disputed transactions
2107-
ripple::unordered_map<uint256, DisputedTx::pointer> mDisputes;
2108-
ripple::unordered_set<uint256> mCompares;
2106+
hash_map<uint256, DisputedTx::pointer> mDisputes;
2107+
hash_set<uint256> mCompares;
21092108

21102109
// Close time estimates
21112110
std::map<std::uint32_t, int> mCloseTimes;

src/ripple/module/app/ledger/BookListeners.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BookListeners
3939
typedef std::lock_guard <LockType> ScopedLockType;
4040
LockType mLock;
4141

42-
ripple::unordered_map<std::uint64_t, InfoSub::wptr> mListeners;
42+
hash_map<std::uint64_t, InfoSub::wptr> mListeners;
4343
};
4444

4545
} // ripple

src/ripple/module/app/ledger/InboundLedgers.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class InboundLedgersImp
5959
{
6060
if (mConsensusLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mConsensusLedger))
6161
{
62-
ripple::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mConsensusLedger);
62+
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mConsensusLedger);
6363
if (it != mLedgers.end ())
6464
{
6565
oldLedger = it->second;
@@ -72,7 +72,7 @@ class InboundLedgersImp
7272
{
7373
if (mValidationLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mValidationLedger))
7474
{
75-
ripple::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mValidationLedger);
75+
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mValidationLedger);
7676
if (it != mLedgers.end ())
7777
{
7878
oldLedger = it->second;
@@ -82,7 +82,7 @@ class InboundLedgersImp
8282
mValidationLedger = hash;
8383
}
8484

85-
ripple::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
85+
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
8686
if (it != mLedgers.end ())
8787
{
8888
ret = it->second;
@@ -111,7 +111,7 @@ class InboundLedgersImp
111111
{
112112
ScopedLockType sl (mLock);
113113

114-
ripple::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
114+
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
115115
if (it != mLedgers.end ())
116116
{
117117
ret = it->second;
@@ -376,7 +376,7 @@ class InboundLedgersImp
376376
private:
377377
clock_type& m_clock;
378378

379-
typedef ripple::unordered_map <uint256, InboundLedger::pointer> MapType;
379+
typedef hash_map <uint256, InboundLedger::pointer> MapType;
380380

381381
typedef RippleRecursiveMutex LockType;
382382
typedef std::unique_lock <LockType> ScopedLockType;

src/ripple/module/app/ledger/LedgerEntrySet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class LedgerEntrySet
292292
Ledger::pointer mLedger;
293293
std::map<uint256, LedgerEntrySetEntry> mEntries; // cannot be unordered!
294294

295-
typedef ripple::unordered_map<uint256, SLE::pointer> NodeToLedgerEntry;
295+
typedef hash_map<uint256, SLE::pointer> NodeToLedgerEntry;
296296

297297
TransactionMetaSet mSet;
298298
TransactionEngineParams mParams;

src/ripple/module/app/ledger/LedgerMaster.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ class LedgerMasterImp
818818
};
819819

820820
// Count the number of current, trusted validations
821-
ripple::unordered_map <uint256, valSeq> count;
821+
hash_map <uint256, valSeq> count;
822822
for (auto const& v : val)
823823
{
824824
valSeq& vs = count[v->getLedgerHash()];

src/ripple/module/app/ledger/OrderBookDB.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ void OrderBookDB::setup (Ledger::ref ledger)
6262
}
6363

6464
static void updateHelper (SLE::ref entry,
65-
ripple::unordered_set< uint256 >& seen,
65+
hash_set< uint256 >& seen,
6666
OrderBookDB::IssueToOrderBook& destMap,
6767
OrderBookDB::IssueToOrderBook& sourceMap,
68-
ripple::unordered_set< Issue >& XRPBooks,
68+
hash_set< Issue >& XRPBooks,
6969
int& books)
7070
{
7171
if (entry->getType () == ltDIR_NODE &&
@@ -93,10 +93,10 @@ static void updateHelper (SLE::ref entry,
9393

9494
void OrderBookDB::update (Ledger::pointer ledger)
9595
{
96-
ripple::unordered_set< uint256 > seen;
96+
hash_set< uint256 > seen;
9797
OrderBookDB::IssueToOrderBook destMap;
9898
OrderBookDB::IssueToOrderBook sourceMap;
99-
ripple::unordered_set< Issue > XRPBooks;
99+
hash_set< Issue > XRPBooks;
100100

101101
WriteLog (lsDEBUG, OrderBookDB) << "OrderBookDB::update>";
102102

src/ripple/module/app/ledger/OrderBookDB.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class OrderBookDB
5151
Ledger::ref ledger, const AcceptedLedgerTx& alTx,
5252
Json::Value const& jvObj);
5353

54-
typedef ripple::unordered_map <Issue, OrderBook::List> IssueToOrderBook;
54+
typedef hash_map <Issue, OrderBook::List> IssueToOrderBook;
5555

5656
private:
5757
void rawAddBook(Book const&);
@@ -63,13 +63,13 @@ class OrderBookDB
6363
IssueToOrderBook mDestMap;
6464

6565
// does an order book to XRP exist
66-
ripple::unordered_set <Issue> mXRPBooks;
66+
hash_set <Issue> mXRPBooks;
6767

6868
typedef RippleRecursiveMutex LockType;
6969
typedef std::lock_guard <LockType> ScopedLockType;
7070
LockType mLock;
7171

72-
typedef ripple::unordered_map <Book, BookListeners::pointer>
72+
typedef hash_map <Book, BookListeners::pointer>
7373
BookToListenersMap;
7474

7575
BookToListenersMap mListeners;

src/ripple/module/app/misc/AmendmentTable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AmendmentSet
3030
public:
3131
std::uint32_t mCloseTime;
3232
int mTrustedValidations; // number of trusted validations
33-
ripple::unordered_map<uint256, int> mVotes; // yes votes by amendment
33+
hash_map<uint256, int> mVotes; // yes votes by amendment
3434

3535
AmendmentSet (std::uint32_t ct) : mCloseTime (ct), mTrustedValidations (0)
3636
{

src/ripple/module/app/misc/AmendmentTableImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace ripple {
2929
{
3030
protected:
3131

32-
typedef ripple::unordered_map<uint256, AmendmentState> amendmentMap_t;
32+
typedef hash_map<uint256, AmendmentState> amendmentMap_t;
3333
typedef std::pair<const uint256, AmendmentState> amendmentIt_t;
34-
typedef ripple::unordered_set<uint256> amendmentList_t;
34+
typedef hash_set<uint256> amendmentList_t;
3535

3636
typedef RippleMutex LockType;
3737
typedef std::lock_guard <LockType> ScopedLockType;

src/ripple/module/app/misc/HashRouter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class HashRouter : public IHashRouter
107107
LockType mLock;
108108

109109
// Stores all suppressed hashes and their expiration time
110-
ripple::unordered_map <uint256, Entry> mSuppressionMap;
110+
hash_map <uint256, Entry> mSuppressionMap;
111111

112112
// Stores all expiration times and the hashes indexed for them
113113
std::map< int, std::list<uint256> > mSuppressionTimes;
@@ -119,7 +119,7 @@ class HashRouter : public IHashRouter
119119

120120
HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& created)
121121
{
122-
ripple::unordered_map<uint256, Entry>::iterator fit = mSuppressionMap.find (index);
122+
hash_map<uint256, Entry>::iterator fit = mSuppressionMap.find (index);
123123

124124
if (fit != mSuppressionMap.end ())
125125
{

0 commit comments

Comments
 (0)