Skip to content

Commit 8587b23

Browse files
committed
leveldbwrapper symbol rename: Remove "Level" from class, etc. names
1 parent 6ec4b7e commit 8587b23

File tree

5 files changed

+65
-65
lines changed

5 files changed

+65
-65
lines changed

src/leveldbwrapper.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
#include <memenv.h>
1616
#include <stdint.h>
1717

18-
void HandleError(const leveldb::Status& status) throw(leveldb_error)
18+
void HandleError(const leveldb::Status& status) throw(dbwrapper_error)
1919
{
2020
if (status.ok())
2121
return;
2222
LogPrintf("%s\n", status.ToString());
2323
if (status.IsCorruption())
24-
throw leveldb_error("Database corrupted");
24+
throw dbwrapper_error("Database corrupted");
2525
if (status.IsIOError())
26-
throw leveldb_error("Database I/O error");
26+
throw dbwrapper_error("Database I/O error");
2727
if (status.IsNotFound())
28-
throw leveldb_error("Database entry missing");
29-
throw leveldb_error("Unknown database error");
28+
throw dbwrapper_error("Database entry missing");
29+
throw dbwrapper_error("Unknown database error");
3030
}
3131

3232
static leveldb::Options GetOptions(size_t nCacheSize)
@@ -45,7 +45,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
4545
return options;
4646
}
4747

48-
CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
48+
CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
4949
{
5050
penv = NULL;
5151
readoptions.verify_checksums = true;
@@ -90,7 +90,7 @@ CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCa
9090
LogPrintf("Using obfuscation key for %s: %s\n", path.string(), GetObfuscateKeyHex());
9191
}
9292

93-
CLevelDBWrapper::~CLevelDBWrapper()
93+
CDBWrapper::~CDBWrapper()
9494
{
9595
delete pdb;
9696
pdb = NULL;
@@ -102,7 +102,7 @@ CLevelDBWrapper::~CLevelDBWrapper()
102102
options.env = NULL;
103103
}
104104

105-
bool CLevelDBWrapper::WriteBatch(CLevelDBBatch& batch, bool fSync) throw(leveldb_error)
105+
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) throw(dbwrapper_error)
106106
{
107107
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
108108
HandleError(status);
@@ -113,40 +113,40 @@ bool CLevelDBWrapper::WriteBatch(CLevelDBBatch& batch, bool fSync) throw(leveldb
113113
//
114114
// We must use a string constructor which specifies length so that we copy
115115
// past the null-terminator.
116-
const std::string CLevelDBWrapper::OBFUSCATE_KEY_KEY("\000obfuscate_key", 14);
116+
const std::string CDBWrapper::OBFUSCATE_KEY_KEY("\000obfuscate_key", 14);
117117

118-
const unsigned int CLevelDBWrapper::OBFUSCATE_KEY_NUM_BYTES = 8;
118+
const unsigned int CDBWrapper::OBFUSCATE_KEY_NUM_BYTES = 8;
119119

120120
/**
121121
* Returns a string (consisting of 8 random bytes) suitable for use as an
122122
* obfuscating XOR key.
123123
*/
124-
std::vector<unsigned char> CLevelDBWrapper::CreateObfuscateKey() const
124+
std::vector<unsigned char> CDBWrapper::CreateObfuscateKey() const
125125
{
126126
unsigned char buff[OBFUSCATE_KEY_NUM_BYTES];
127127
GetRandBytes(buff, OBFUSCATE_KEY_NUM_BYTES);
128128
return std::vector<unsigned char>(&buff[0], &buff[OBFUSCATE_KEY_NUM_BYTES]);
129129

130130
}
131131

132-
bool CLevelDBWrapper::IsEmpty()
132+
bool CDBWrapper::IsEmpty()
133133
{
134-
boost::scoped_ptr<CLevelDBIterator> it(NewIterator());
134+
boost::scoped_ptr<CDBIterator> it(NewIterator());
135135
it->SeekToFirst();
136136
return !(it->Valid());
137137
}
138138

139-
const std::vector<unsigned char>& CLevelDBWrapper::GetObfuscateKey() const
139+
const std::vector<unsigned char>& CDBWrapper::GetObfuscateKey() const
140140
{
141141
return obfuscate_key;
142142
}
143143

144-
std::string CLevelDBWrapper::GetObfuscateKeyHex() const
144+
std::string CDBWrapper::GetObfuscateKeyHex() const
145145
{
146146
return HexStr(obfuscate_key);
147147
}
148148

149-
CLevelDBIterator::~CLevelDBIterator() { delete piter; }
150-
bool CLevelDBIterator::Valid() { return piter->Valid(); }
151-
void CLevelDBIterator::SeekToFirst() { piter->SeekToFirst(); }
152-
void CLevelDBIterator::Next() { piter->Next(); }
149+
CDBIterator::~CDBIterator() { delete piter; }
150+
bool CDBIterator::Valid() { return piter->Valid(); }
151+
void CDBIterator::SeekToFirst() { piter->SeekToFirst(); }
152+
void CDBIterator::Next() { piter->Next(); }

src/leveldbwrapper.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
#include <leveldb/db.h>
1818
#include <leveldb/write_batch.h>
1919

20-
class leveldb_error : public std::runtime_error
20+
class dbwrapper_error : public std::runtime_error
2121
{
2222
public:
23-
leveldb_error(const std::string& msg) : std::runtime_error(msg) {}
23+
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
2424
};
2525

26-
void HandleError(const leveldb::Status& status) throw(leveldb_error);
26+
void HandleError(const leveldb::Status& status) throw(dbwrapper_error);
2727

28-
/** Batch of changes queued to be written to a CLevelDBWrapper */
29-
class CLevelDBBatch
28+
/** Batch of changes queued to be written to a CDBWrapper */
29+
class CDBBatch
3030
{
31-
friend class CLevelDBWrapper;
31+
friend class CDBWrapper;
3232

3333
private:
3434
leveldb::WriteBatch batch;
@@ -38,7 +38,7 @@ class CLevelDBBatch
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+
CDBBatch(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)
@@ -69,7 +69,7 @@ class CLevelDBBatch
6969
}
7070
};
7171

72-
class CLevelDBIterator
72+
class CDBIterator
7373
{
7474
private:
7575
leveldb::Iterator *piter;
@@ -81,9 +81,9 @@ class CLevelDBIterator
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+
CDBIterator(leveldb::Iterator *piterIn, const std::vector<unsigned char>* obfuscate_key) :
8585
piter(piterIn), obfuscate_key(obfuscate_key) { };
86-
~CLevelDBIterator();
86+
~CDBIterator();
8787

8888
bool Valid();
8989

@@ -132,7 +132,7 @@ class CLevelDBIterator
132132

133133
};
134134

135-
class CLevelDBWrapper
135+
class CDBWrapper
136136
{
137137
private:
138138
//! custom environment this database is using (may be NULL in case of default environment)
@@ -176,11 +176,11 @@ class CLevelDBWrapper
176176
* @param[in] obfuscate If true, store data obfuscated via simple XOR. If false, XOR
177177
* with a zero'd byte array.
178178
*/
179-
CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
180-
~CLevelDBWrapper();
179+
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
180+
~CDBWrapper();
181181

182182
template <typename K, typename V>
183-
bool Read(const K& key, V& value) const throw(leveldb_error)
183+
bool Read(const K& key, V& value) const throw(dbwrapper_error)
184184
{
185185
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
186186
ssKey.reserve(ssKey.GetSerializeSize(key));
@@ -206,15 +206,15 @@ class CLevelDBWrapper
206206
}
207207

208208
template <typename K, typename V>
209-
bool Write(const K& key, const V& value, bool fSync = false) throw(leveldb_error)
209+
bool Write(const K& key, const V& value, bool fSync = false) throw(dbwrapper_error)
210210
{
211-
CLevelDBBatch batch(&obfuscate_key);
211+
CDBBatch batch(&obfuscate_key);
212212
batch.Write(key, value);
213213
return WriteBatch(batch, fSync);
214214
}
215215

216216
template <typename K>
217-
bool Exists(const K& key) const throw(leveldb_error)
217+
bool Exists(const K& key) const throw(dbwrapper_error)
218218
{
219219
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
220220
ssKey.reserve(ssKey.GetSerializeSize(key));
@@ -233,30 +233,30 @@ class CLevelDBWrapper
233233
}
234234

235235
template <typename K>
236-
bool Erase(const K& key, bool fSync = false) throw(leveldb_error)
236+
bool Erase(const K& key, bool fSync = false) throw(dbwrapper_error)
237237
{
238-
CLevelDBBatch batch(&obfuscate_key);
238+
CDBBatch batch(&obfuscate_key);
239239
batch.Erase(key);
240240
return WriteBatch(batch, fSync);
241241
}
242242

243-
bool WriteBatch(CLevelDBBatch& batch, bool fSync = false) throw(leveldb_error);
243+
bool WriteBatch(CDBBatch& batch, bool fSync = false) throw(dbwrapper_error);
244244

245245
// not available for LevelDB; provide for compatibility with BDB
246246
bool Flush()
247247
{
248248
return true;
249249
}
250250

251-
bool Sync() throw(leveldb_error)
251+
bool Sync() throw(dbwrapper_error)
252252
{
253-
CLevelDBBatch batch(&obfuscate_key);
253+
CDBBatch batch(&obfuscate_key);
254254
return WriteBatch(batch, true);
255255
}
256256

257-
CLevelDBIterator *NewIterator()
257+
CDBIterator *NewIterator()
258258
{
259-
return new CLevelDBIterator(pdb->NewIterator(iteroptions), &obfuscate_key);
259+
return new CDBIterator(pdb->NewIterator(iteroptions), &obfuscate_key);
260260
}
261261

262262
/**

src/test/leveldbwrapper_tests.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ bool is_null_key(const vector<unsigned char>& key) {
2525
return isnull;
2626
}
2727

28-
BOOST_FIXTURE_TEST_SUITE(leveldbwrapper_tests, BasicTestingSetup)
28+
BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup)
2929

30-
BOOST_AUTO_TEST_CASE(leveldbwrapper)
30+
BOOST_AUTO_TEST_CASE(dbwrapper)
3131
{
3232
// Perform tests both obfuscated and non-obfuscated.
3333
for (int i = 0; i < 2; i++) {
3434
bool obfuscate = (bool)i;
3535
path ph = temp_directory_path() / unique_path();
36-
CLevelDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
36+
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
3737
char key = 'k';
3838
uint256 in = GetRandHash();
3939
uint256 res;
@@ -48,13 +48,13 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper)
4848
}
4949

5050
// Test batch operations
51-
BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
51+
BOOST_AUTO_TEST_CASE(dbwrapper_batch)
5252
{
5353
// Perform tests both obfuscated and non-obfuscated.
5454
for (int i = 0; i < 2; i++) {
5555
bool obfuscate = (bool)i;
5656
path ph = temp_directory_path() / unique_path();
57-
CLevelDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
57+
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
5858

5959
char key = 'i';
6060
uint256 in = GetRandHash();
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
6464
uint256 in3 = GetRandHash();
6565

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

6969
batch.Write(key, in);
7070
batch.Write(key2, in2);
@@ -85,13 +85,13 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
8585
}
8686
}
8787

88-
BOOST_AUTO_TEST_CASE(leveldbwrapper_iterator)
88+
BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
8989
{
9090
// Perform tests both obfuscated and non-obfuscated.
9191
for (int i = 0; i < 2; i++) {
9292
bool obfuscate = (bool)i;
9393
path ph = temp_directory_path() / unique_path();
94-
CLevelDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
94+
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
9595

9696
// The two keys are intentionally chosen for ordering
9797
char key = 'j';
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_iterator)
101101
uint256 in2 = GetRandHash();
102102
BOOST_CHECK(dbw.Write(key2, in2));
103103

104-
boost::scoped_ptr<CLevelDBIterator> it(const_cast<CLevelDBWrapper*>(&dbw)->NewIterator());
104+
boost::scoped_ptr<CDBIterator> it(const_cast<CDBWrapper*>(&dbw)->NewIterator());
105105

106106
// Be sure to seek past the obfuscation key (if it exists)
107107
it->Seek(key);
@@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
134134
create_directories(ph);
135135

136136
// Set up a non-obfuscated wrapper to write some initial data.
137-
CLevelDBWrapper* dbw = new CLevelDBWrapper(ph, (1 << 10), false, false, false);
137+
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
138138
char key = 'k';
139139
uint256 in = GetRandHash();
140140
uint256 res;
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
147147
delete dbw;
148148

149149
// Now, set up another wrapper that wants to obfuscate the same directory
150-
CLevelDBWrapper odbw(ph, (1 << 10), false, false, true);
150+
CDBWrapper odbw(ph, (1 << 10), false, false, true);
151151

152152
// Check that the key/val we wrote with unobfuscated wrapper exists and
153153
// is readable.
@@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
175175
create_directories(ph);
176176

177177
// Set up a non-obfuscated wrapper to write some initial data.
178-
CLevelDBWrapper* dbw = new CLevelDBWrapper(ph, (1 << 10), false, false, false);
178+
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
179179
char key = 'k';
180180
uint256 in = GetRandHash();
181181
uint256 res;
@@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
188188
delete dbw;
189189

190190
// Simulate a -reindex by wiping the existing data store
191-
CLevelDBWrapper odbw(ph, (1 << 10), false, true, true);
191+
CDBWrapper odbw(ph, (1 << 10), false, true, true);
192192

193193
// Check that the key/val we wrote with unobfuscated wrapper doesn't exist
194194
uint256 res2;

src/txdb.cpp

Lines changed: 6 additions & 6 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+
CDBBatch batch(&db.GetObfuscateKey());
5353
size_t count = 0;
5454
size_t changed = 0;
5555
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
@@ -71,7 +71,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
7171
return db.WriteBatch(batch);
7272
}
7373

74-
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
74+
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
7575
}
7676

7777
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
@@ -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<CLevelDBIterator> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
101+
boost::scoped_ptr<CDBIterator> pcursor(const_cast<CDBWrapper*>(&db)->NewIterator());
102102
pcursor->Seek(DB_COINS);
103103

104104
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
@@ -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+
CDBBatch 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+
CDBBatch 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);
@@ -177,7 +177,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
177177

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

182182
pcursor->Seek(make_pair(DB_BLOCK_INDEX, uint256()));
183183

0 commit comments

Comments
 (0)