Skip to content

Commit 46f7437

Browse files
committed
Merge pull request #6873
2 parents c719cef + 3795e81 commit 46f7437

File tree

7 files changed

+85
-89
lines changed

7 files changed

+85
-89
lines changed

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ BITCOIN_CORE_H = \
110110
init.h \
111111
key.h \
112112
keystore.h \
113-
leveldbwrapper.h \
113+
dbwrapper.h \
114114
limitedmap.h \
115115
main.h \
116116
memusage.h \
@@ -188,7 +188,7 @@ libbitcoin_server_a_SOURCES = \
188188
httprpc.cpp \
189189
httpserver.cpp \
190190
init.cpp \
191-
leveldbwrapper.cpp \
191+
dbwrapper.cpp \
192192
main.cpp \
193193
merkleblock.cpp \
194194
miner.cpp \

src/Makefile.test.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ BITCOIN_TESTS =\
5454
test/hash_tests.cpp \
5555
test/key_tests.cpp \
5656
test/limitedmap_tests.cpp \
57-
test/leveldbwrapper_tests.cpp \
57+
test/dbwrapper_tests.cpp \
5858
test/main_tests.cpp \
5959
test/mempool_tests.cpp \
6060
test/miner_tests.cpp \

src/leveldbwrapper.cpp renamed to src/dbwrapper.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include "leveldbwrapper.h"
5+
#include "dbwrapper.h"
66

77
#include "util.h"
88
#include "random.h"
@@ -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;
@@ -76,7 +76,7 @@ CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCa
7676
bool key_exists = Read(OBFUSCATE_KEY_KEY, obfuscate_key);
7777

7878
if (!key_exists && obfuscate && IsEmpty()) {
79-
// Initialize non-degenerate obfuscation if it won't upset
79+
// Initialize non-degenerate obfuscation if it won't upset
8080
// existing, non-obfuscated data.
8181
std::vector<unsigned char> new_key = CreateObfuscateKey();
8282

@@ -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,42 +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
/**
121-
* Returns a string (consisting of 8 random bytes) suitable for use as an
122-
* obfuscating XOR key.
121+
* Returns a string (consisting of 8 random bytes) suitable for use as an
122+
* 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
140-
{
141-
return obfuscate_key;
139+
const std::vector<unsigned char>& CDBWrapper::GetObfuscateKey() const
140+
{
141+
return obfuscate_key;
142142
}
143143

144-
std::string CLevelDBWrapper::GetObfuscateKeyHex() const
145-
{
146-
return HexStr(obfuscate_key);
144+
std::string CDBWrapper::GetObfuscateKeyHex() const
145+
{
146+
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::SeekToLast() { piter->SeekToLast(); }
153-
void CLevelDBIterator::Next() { piter->Next(); }
154-
void CLevelDBIterator::Prev() { piter->Prev(); }
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 renamed to src/dbwrapper.h

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#ifndef BITCOIN_LEVELDBWRAPPER_H
6-
#define BITCOIN_LEVELDBWRAPPER_H
5+
#ifndef BITCOIN_DBWRAPPER_H
6+
#define BITCOIN_DBWRAPPER_H
77

88
#include "clientversion.h"
99
#include "serialize.h"
@@ -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)
@@ -68,8 +68,8 @@ class CLevelDBBatch
6868
batch.Delete(slKey);
6969
}
7070
};
71-
72-
class CLevelDBIterator
71+
72+
class CDBIterator
7373
{
7474
private:
7575
leveldb::Iterator *piter;
@@ -81,14 +81,13 @@ 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

9090
void SeekToFirst();
91-
void SeekToLast();
9291

9392
template<typename K> void Seek(const K& key) {
9493
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
@@ -99,7 +98,6 @@ class CLevelDBIterator
9998
}
10099

101100
void Next();
102-
void Prev();
103101

104102
template<typename K> bool GetKey(K& key) {
105103
leveldb::Slice slKey = piter->key();
@@ -133,8 +131,8 @@ class CLevelDBIterator
133131
}
134132

135133
};
136-
137-
class CLevelDBWrapper
134+
135+
class CDBWrapper
138136
{
139137
private:
140138
//! custom environment this database is using (may be NULL in case of default environment)
@@ -163,10 +161,10 @@ class CLevelDBWrapper
163161

164162
//! the key under which the obfuscation key is stored
165163
static const std::string OBFUSCATE_KEY_KEY;
166-
164+
167165
//! the length of the obfuscate key in number of bytes
168166
static const unsigned int OBFUSCATE_KEY_NUM_BYTES;
169-
167+
170168
std::vector<unsigned char> CreateObfuscateKey() const;
171169

172170
public:
@@ -178,11 +176,11 @@ class CLevelDBWrapper
178176
* @param[in] obfuscate If true, store data obfuscated via simple XOR. If false, XOR
179177
* with a zero'd byte array.
180178
*/
181-
CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
182-
~CLevelDBWrapper();
179+
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
180+
~CDBWrapper();
183181

184182
template <typename K, typename V>
185-
bool Read(const K& key, V& value) const throw(leveldb_error)
183+
bool Read(const K& key, V& value) const throw(dbwrapper_error)
186184
{
187185
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
188186
ssKey.reserve(ssKey.GetSerializeSize(key));
@@ -208,15 +206,15 @@ class CLevelDBWrapper
208206
}
209207

210208
template <typename K, typename V>
211-
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)
212210
{
213-
CLevelDBBatch batch(&obfuscate_key);
211+
CDBBatch batch(&obfuscate_key);
214212
batch.Write(key, value);
215213
return WriteBatch(batch, fSync);
216214
}
217215

218216
template <typename K>
219-
bool Exists(const K& key) const throw(leveldb_error)
217+
bool Exists(const K& key) const throw(dbwrapper_error)
220218
{
221219
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
222220
ssKey.reserve(ssKey.GetSerializeSize(key));
@@ -235,30 +233,30 @@ class CLevelDBWrapper
235233
}
236234

237235
template <typename K>
238-
bool Erase(const K& key, bool fSync = false) throw(leveldb_error)
236+
bool Erase(const K& key, bool fSync = false) throw(dbwrapper_error)
239237
{
240-
CLevelDBBatch batch(&obfuscate_key);
238+
CDBBatch batch(&obfuscate_key);
241239
batch.Erase(key);
242240
return WriteBatch(batch, fSync);
243241
}
244242

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

247245
// not available for LevelDB; provide for compatibility with BDB
248246
bool Flush()
249247
{
250248
return true;
251249
}
252250

253-
bool Sync() throw(leveldb_error)
251+
bool Sync() throw(dbwrapper_error)
254252
{
255-
CLevelDBBatch batch(&obfuscate_key);
253+
CDBBatch batch(&obfuscate_key);
256254
return WriteBatch(batch, true);
257255
}
258256

259-
CLevelDBIterator *NewIterator()
257+
CDBIterator *NewIterator()
260258
{
261-
return new CLevelDBIterator(pdb->NewIterator(iteroptions), &obfuscate_key);
259+
return new CDBIterator(pdb->NewIterator(iteroptions), &obfuscate_key);
262260
}
263261

264262
/**
@@ -278,5 +276,5 @@ class CLevelDBWrapper
278276

279277
};
280278

281-
#endif // BITCOIN_LEVELDBWRAPPER_H
279+
#endif // BITCOIN_DBWRAPPER_H
282280

0 commit comments

Comments
 (0)