Skip to content

Commit dcd8e27

Browse files
committed
Refer to obfuscate_key via pointer in peripheral CLevelDB classes
cc @sipa
1 parent 1488506 commit dcd8e27

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/leveldbwrapper.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class CLevelDBBatch
3232

3333
private:
3434
leveldb::WriteBatch batch;
35-
const std::vector<unsigned char> obfuscate_key;
35+
const std::vector<unsigned char> *obfuscate_key;
3636

3737
public:
3838
/**
3939
* @param[in] obfuscate_key If passed, XOR data with this key.
4040
*/
41-
CLevelDBBatch(const std::vector<unsigned char>& obfuscate_key) : obfuscate_key(obfuscate_key) { };
41+
CLevelDBBatch(const std::vector<unsigned char> *obfuscate_key) : obfuscate_key(obfuscate_key) { };
4242

4343
template <typename K, typename V>
4444
void Write(const K& key, const V& value)
@@ -51,7 +51,7 @@ class CLevelDBBatch
5151
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
5252
ssValue.reserve(ssValue.GetSerializeSize(value));
5353
ssValue << value;
54-
ssValue.Xor(obfuscate_key);
54+
ssValue.Xor(*obfuscate_key);
5555
leveldb::Slice slValue(&ssValue[0], ssValue.size());
5656

5757
batch.Put(slKey, slValue);
@@ -73,15 +73,15 @@ class CLevelDBIterator
7373
{
7474
private:
7575
leveldb::Iterator *piter;
76-
const std::vector<unsigned char> obfuscate_key;
76+
const std::vector<unsigned char> *obfuscate_key;
7777

7878
public:
7979

8080
/**
8181
* @param[in] piterIn The original leveldb iterator.
8282
* @param[in] obfuscate_key If passed, XOR data with this key.
8383
*/
84-
CLevelDBIterator(leveldb::Iterator *piterIn, const std::vector<unsigned char>& obfuscate_key) :
84+
CLevelDBIterator(leveldb::Iterator *piterIn, const std::vector<unsigned char>* obfuscate_key) :
8585
piter(piterIn), obfuscate_key(obfuscate_key) { };
8686
~CLevelDBIterator();
8787

@@ -120,7 +120,7 @@ class CLevelDBIterator
120120
leveldb::Slice slValue = piter->value();
121121
try {
122122
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
123-
ssValue.Xor(obfuscate_key);
123+
ssValue.Xor(*obfuscate_key);
124124
ssValue >> value;
125125
} catch(std::exception &e) {
126126
return false;
@@ -210,7 +210,7 @@ class CLevelDBWrapper
210210
template <typename K, typename V>
211211
bool Write(const K& key, const V& value, bool fSync = false) throw(leveldb_error)
212212
{
213-
CLevelDBBatch batch(obfuscate_key);
213+
CLevelDBBatch batch(&obfuscate_key);
214214
batch.Write(key, value);
215215
return WriteBatch(batch, fSync);
216216
}
@@ -237,7 +237,7 @@ class CLevelDBWrapper
237237
template <typename K>
238238
bool Erase(const K& key, bool fSync = false) throw(leveldb_error)
239239
{
240-
CLevelDBBatch batch(obfuscate_key);
240+
CLevelDBBatch batch(&obfuscate_key);
241241
batch.Erase(key);
242242
return WriteBatch(batch, fSync);
243243
}
@@ -252,13 +252,13 @@ class CLevelDBWrapper
252252

253253
bool Sync() throw(leveldb_error)
254254
{
255-
CLevelDBBatch batch(obfuscate_key);
255+
CLevelDBBatch batch(&obfuscate_key);
256256
return WriteBatch(batch, true);
257257
}
258258

259259
CLevelDBIterator *NewIterator()
260260
{
261-
return new CLevelDBIterator(pdb->NewIterator(iteroptions), obfuscate_key);
261+
return new CLevelDBIterator(pdb->NewIterator(iteroptions), &obfuscate_key);
262262
}
263263

264264
/**

src/test/leveldbwrapper_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
6464
uint256 in3 = GetRandHash();
6565

6666
uint256 res;
67-
CLevelDBBatch batch(dbw.GetObfuscateKey());
67+
CLevelDBBatch batch(&dbw.GetObfuscateKey());
6868

6969
batch.Write(key, in);
7070
batch.Write(key2, in2);

src/txdb.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ uint256 CCoinsViewDB::GetBestBlock() const {
4949
}
5050

5151
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
52-
CLevelDBBatch batch(db.GetObfuscateKey());
52+
CLevelDBBatch batch(&db.GetObfuscateKey());
5353
size_t count = 0;
5454
size_t changed = 0;
5555
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
@@ -141,7 +141,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
141141
}
142142

143143
bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
144-
CLevelDBBatch batch(GetObfuscateKey());
144+
CLevelDBBatch batch(&GetObfuscateKey());
145145
for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
146146
batch.Write(make_pair(DB_BLOCK_FILES, it->first), *it->second);
147147
}
@@ -157,7 +157,7 @@ bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
157157
}
158158

159159
bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
160-
CLevelDBBatch batch(GetObfuscateKey());
160+
CLevelDBBatch batch(&GetObfuscateKey());
161161
for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
162162
batch.Write(make_pair(DB_TXINDEX, it->first), it->second);
163163
return WriteBatch(batch);

0 commit comments

Comments
 (0)