Unverified Commit ea74ba94 authored by kladko's avatar kladko

SKALE-3067-cleanup-sgx

parent b000e648
...@@ -43,15 +43,10 @@ static WriteOptions writeOptions; ...@@ -43,15 +43,10 @@ static WriteOptions writeOptions;
static ReadOptions readOptions; static ReadOptions readOptions;
std::shared_ptr<string> LevelDB::readString(const string &_key) { std::shared_ptr<string> LevelDB::readString(const string &_key) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto result = std::make_shared<string>(); auto result = std::make_shared<string>();
if (db == nullptr) { CHECK_STATE(db)
throw SGXException(NULL_DATABASE, "Null db");
}
spdlog::debug("key to read from db: {}", _key);
auto status = db->Get(readOptions, _key, result.get()); auto status = db->Get(readOptions, _key, result.get());
...@@ -65,18 +60,14 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) { ...@@ -65,18 +60,14 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
} }
void LevelDB::writeString(const string &_key, const string &_value) { void LevelDB::writeString(const string &_key, const string &_value) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Put(writeOptions, Slice(_key), Slice(_value)); auto status = db->Put(writeOptions, Slice(_key), Slice(_value));
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("written key: {}", _key);
} }
void LevelDB::deleteDHDKGKey(const string &_key) { void LevelDB::deleteDHDKGKey(const string &_key) {
std::lock_guard<std::recursive_mutex> lock(mutex);
string full_key = "DKG_DH_KEY_" + _key; string full_key = "DKG_DH_KEY_" + _key;
...@@ -84,48 +75,31 @@ void LevelDB::deleteDHDKGKey(const string &_key) { ...@@ -84,48 +75,31 @@ void LevelDB::deleteDHDKGKey(const string &_key) {
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("key deleted: {}", full_key);
} }
void LevelDB::deleteTempNEK(const string &_key) { void LevelDB::deleteTempNEK(const string &_key) {
std::lock_guard<std::recursive_mutex> lock(mutex);
string prefix = _key.substr(0,8); CHECK_STATE(_key.rfind("tmp_NEK", 0) == 0);
if (prefix != "tmp_NEK:") {
return;
}
auto status = db->Delete(writeOptions, Slice(_key)); auto status = db->Delete(writeOptions, Slice(_key));
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("key deleted: {}", _key);
} }
void LevelDB::deleteKey(const string &_key) { void LevelDB::deleteKey(const string &_key) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Delete(writeOptions, Slice(_key)); auto status = db->Delete(writeOptions, Slice(_key));
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("key deleted: {}", _key);
} }
void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value,
size_t _valueLen) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Put(writeOptions, Slice(_key, _keyLen), Slice(value, _valueLen));
throwExceptionOnError(status);
}
void LevelDB::writeByteArray(string &_key, const char *value, void LevelDB::writeByteArray(string &_key, const char *value,
size_t _valueLen) { size_t _valueLen) {
std::lock_guard<std::recursive_mutex> lock(mutex);
CHECK_STATE(value);
auto status = db->Put(writeOptions, Slice(_key), Slice(value, _valueLen)); auto status = db->Put(writeOptions, Slice(_key), Slice(value, _valueLen));
...@@ -142,6 +116,9 @@ void LevelDB::throwExceptionOnError(Status _status) { ...@@ -142,6 +116,9 @@ void LevelDB::throwExceptionOnError(Status _status) {
} }
uint64_t LevelDB::visitKeys(LevelDB::KeyVisitor *_visitor, uint64_t _maxKeysToVisit) { uint64_t LevelDB::visitKeys(LevelDB::KeyVisitor *_visitor, uint64_t _maxKeysToVisit) {
CHECK_STATE(_visitor);
uint64_t readCounter = 0; uint64_t readCounter = 0;
leveldb::Iterator *it = db->NewIterator(readOptions); leveldb::Iterator *it = db->NewIterator(readOptions);
...@@ -187,7 +164,7 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) { ...@@ -187,7 +164,7 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) {
writeString(key, value); writeString(key, value);
spdlog::debug("{}",Name, " is written to db");
} }
......
...@@ -24,10 +24,9 @@ ...@@ -24,10 +24,9 @@
#ifndef SGXWALLET_SGXWALLETSERVER_HPP #ifndef SGXWALLET_SGXWALLETSERVER_HPP
#define SGXWALLET_SGXWALLETSERVER_HPP #define SGXWALLET_SGXWALLETSERVER_HPP
#include <boost/thread/shared_mutex.hpp>
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>
#include <mutex>
#include "abstractstubserver.h" #include "abstractstubserver.h"
using namespace jsonrpc; using namespace jsonrpc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment