Skip to content

Commit 0fdf8c8

Browse files
committed
Handle obfuscation in CLevelDBIterator
1 parent 3499ce1 commit 0fdf8c8

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/leveldbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ std::string CLevelDBWrapper::GetObfuscateKeyHex() const
145145
{
146146
return HexStr(obfuscate_key);
147147
}
148-
148+
149149
CLevelDBIterator::~CLevelDBIterator() { delete piter; }
150150
bool CLevelDBIterator::Valid() { return piter->Valid(); }
151151
void CLevelDBIterator::SeekToFirst() { piter->SeekToFirst(); }

src/leveldbwrapper.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,16 @@ class CLevelDBIterator
7373
{
7474
private:
7575
leveldb::Iterator *piter;
76+
const std::vector<unsigned char> obfuscate_key;
7677

7778
public:
78-
CLevelDBIterator(leveldb::Iterator *piterIn) : piter(piterIn) {}
79+
80+
/**
81+
* @param[in] piterIn The original leveldb iterator.
82+
* @param[in] obfuscate_key If passed, XOR data with this key.
83+
*/
84+
CLevelDBIterator(leveldb::Iterator *piterIn, const std::vector<unsigned char>& obfuscate_key) :
85+
piter(piterIn), obfuscate_key(obfuscate_key) { };
7986
~CLevelDBIterator();
8087

8188
bool Valid();
@@ -113,7 +120,7 @@ class CLevelDBIterator
113120
leveldb::Slice slValue = piter->value();
114121
try {
115122
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
116-
ssValue.Xor(db.GetObfuscateKey());
123+
ssValue.Xor(obfuscate_key);
117124
ssValue >> value;
118125
} catch(std::exception &e) {
119126
return false;
@@ -251,8 +258,8 @@ class CLevelDBWrapper
251258

252259
CLevelDBIterator *NewIterator()
253260
{
254-
return new CLevelDBIterator(pdb->NewIterator(iteroptions));
255-
{
261+
return new CLevelDBIterator(pdb->NewIterator(iteroptions), obfuscate_key);
262+
}
256263

257264
/**
258265
* Return true if the database managed by this class contains no entries.

src/txdb.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
9898
/* It seems that there are no "const iterators" for LevelDB. Since we
9999
only need read operations on it, use a const-cast to get around
100100
that restriction. */
101-
boost::scoped_ptr<CLevelDBWrapper> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
101+
boost::scoped_ptr<CLevelDBIterator> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
102102
pcursor->Seek('c');
103103

104104
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
@@ -177,9 +177,9 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
177177

178178
bool CBlockTreeDB::LoadBlockIndexGuts()
179179
{
180-
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
180+
boost::scoped_ptr<CLevelDBIterator> pcursor(NewIterator());
181181

182-
pcursor->Seek(make_pair('b', uint256(0)));
182+
pcursor->Seek(make_pair('b', uint256()));
183183

184184
// Load mapBlockIndex
185185
while (pcursor->Valid()) {

0 commit comments

Comments
 (0)