10 #include <boost/filesystem.hpp> 12 #include <leveldb/cache.h> 13 #include <leveldb/env.h> 14 #include <leveldb/filter_policy.h> 23 if (status.IsCorruption())
25 if (status.IsIOError())
27 if (status.IsNotFound())
34 leveldb::Options options;
35 options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
36 options.write_buffer_size = nCacheSize / 4;
37 options.filter_policy = leveldb::NewBloomFilterPolicy(10);
38 options.compression = leveldb::kNoCompression;
39 options.max_open_files = 64;
40 if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
43 options.paranoid_checks =
true;
48 CDBWrapper::CDBWrapper(
const boost::filesystem::path& path,
size_t nCacheSize,
bool fMemory,
bool fWipe,
bool obfuscate)
56 options.create_if_missing =
true;
58 penv = leveldb::NewMemEnv(leveldb::Env::Default());
62 LogPrintf(
"Wiping LevelDB in %s\n", path.string());
63 leveldb::Status
result = leveldb::DestroyDB(path.string(),
options);
67 LogPrintf(
"Opening LevelDB in %s\n", path.string());
69 leveldb::Status status = leveldb::DB::Open(
options, path.string(), &
pdb);
71 LogPrintf(
"Opened LevelDB successfully\n");
78 if (!key_exists && obfuscate &&
IsEmpty()) {
107 leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
136 return !(it->Valid());
leveldb::Env * penv
custom environment this database is using (may be NULL in case of default environment) ...
static const unsigned int OBFUSCATE_KEY_NUM_BYTES
the length of the obfuscate key in number of bytes
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
static const std::string OBFUSCATE_KEY_KEY
the key under which the obfuscation key is stored
leveldb::DB * pdb
the database itself
bool Write(const K &key, const V &value, bool fSync=false)
leveldb::Options options
database options used
std::string GetObfuscateKeyHex() const
CDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false, bool obfuscate=false)
void HandleError(const leveldb::Status &status)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool TryCreateDirectory(const boost::filesystem::path &p)
leveldb::WriteOptions syncoptions
options used when sync writing to the database
leveldb::ReadOptions readoptions
options used when reading from the database
leveldb::ReadOptions iteroptions
options used when iterating over values of the database
void GetRandBytes(unsigned char *buf, int num)
CDBIterator * NewIterator()
const std::vector< unsigned char > & GetObfuscateKey() const
std::vector< unsigned char > CreateObfuscateKey() const
static leveldb::Options GetOptions(size_t nCacheSize)
bool Read(const K &key, V &value) const
leveldb::Iterator * piter
std::vector< unsigned char > obfuscate_key
a key used for optional XOR-obfuscation of the database