Browse Source

Handle obfuscation in CLevelDBIterator

0.13
James O'Beirne 9 years ago
parent
commit
0fdf8c80ee
  1. 15
      src/leveldbwrapper.h
  2. 6
      src/txdb.cpp

15
src/leveldbwrapper.h

@ -73,9 +73,16 @@ class CLevelDBIterator @@ -73,9 +73,16 @@ class CLevelDBIterator
{
private:
leveldb::Iterator *piter;
const std::vector<unsigned char> obfuscate_key;
public:
CLevelDBIterator(leveldb::Iterator *piterIn) : piter(piterIn) {}
/**
* @param[in] piterIn The original leveldb iterator.
* @param[in] obfuscate_key If passed, XOR data with this key.
*/
CLevelDBIterator(leveldb::Iterator *piterIn, const std::vector<unsigned char>& obfuscate_key) :
piter(piterIn), obfuscate_key(obfuscate_key) { };
~CLevelDBIterator();
bool Valid();
@ -113,7 +120,7 @@ public: @@ -113,7 +120,7 @@ public:
leveldb::Slice slValue = piter->value();
try {
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
ssValue.Xor(db.GetObfuscateKey());
ssValue.Xor(obfuscate_key);
ssValue >> value;
} catch(std::exception &e) {
return false;
@ -251,8 +258,8 @@ public: @@ -251,8 +258,8 @@ public:
CLevelDBIterator *NewIterator()
{
return new CLevelDBIterator(pdb->NewIterator(iteroptions));
{
return new CLevelDBIterator(pdb->NewIterator(iteroptions), obfuscate_key);
}
/**
* Return true if the database managed by this class contains no entries.

6
src/txdb.cpp

@ -98,7 +98,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const { @@ -98,7 +98,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
/* It seems that there are no "const iterators" for LevelDB. Since we
only need read operations on it, use a const-cast to get around
that restriction. */
boost::scoped_ptr<CLevelDBWrapper> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
boost::scoped_ptr<CLevelDBIterator> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
pcursor->Seek('c');
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
@ -177,9 +177,9 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) { @@ -177,9 +177,9 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
bool CBlockTreeDB::LoadBlockIndexGuts()
{
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
boost::scoped_ptr<CLevelDBIterator> pcursor(NewIterator());
pcursor->Seek(make_pair('b', uint256(0)));
pcursor->Seek(make_pair('b', uint256()));
// Load mapBlockIndex
while (pcursor->Valid()) {

Loading…
Cancel
Save