aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-11-01 07:15:28 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit71733d7acab4d94ec6f36a5d2fd25560837d8ff7 (patch)
tree8aa6df4b56e95ed95f46f2c9dddddfb5d5469c75
parentb21dcdf8e25884362277dddc5884f91620175896 (diff)
Make operation callback funcs synchronous
-rw-r--r--include/odhtdb/DatabaseStorage.hpp2
-rw-r--r--src/DatabaseStorage.cpp10
2 files changed, 12 insertions, 0 deletions
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp
index b0c081e..8d559cd 100644
--- a/include/odhtdb/DatabaseStorage.hpp
+++ b/include/odhtdb/DatabaseStorage.hpp
@@ -19,6 +19,7 @@
#include <sibs/SafeDeserializer.hpp>
#include <functional>
#include <sibs/DirectConnection.hpp>
+#include <mutex>
class sqlite3;
class sqlite3_stmt;
@@ -201,5 +202,6 @@ namespace odhtdb
u8 passwordSalt[PASSWORD_SALT_LEN];
std::vector<std::shared_ptr<sibs::DirectConnectionPeer>> remotePeers;
+ std::recursive_mutex databaseOperationCallbackMutex;
};
}
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index 34dd09a..9611993 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -213,6 +213,7 @@ namespace odhtdb
void DatabaseStorage::loadNode(const Hash &nodeHash, DatabaseLoadOrder loadOrder)
{
+ std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex);
string orderByString;
if(loadOrder == DatabaseLoadOrder::OLDEST_FIRST)
orderByString = " ORDER BY timestamp ASC";
@@ -1053,7 +1054,10 @@ namespace odhtdb
{
const DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, creatorPublicKey, adminGroupId, database);
if(database->onCreateNodeCallbackFunc)
+ {
+ std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex);
database->onCreateNodeCallbackFunc(createNodeRequest);
+ }
sqlite3_reset(selectNodeAddDataByNodeStmt);
sqlite3_clear_bindings(selectNodeAddDataByNodeStmt);
@@ -1211,7 +1215,10 @@ namespace odhtdb
Log::debug("Got add object, timestamp: %zu, data: %.*s", timestamp, decryptedBody.getDecryptedText().size, decryptedBody.getDecryptedText().data);
const DatabaseAddNodeRequest addNodeRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, decryptedBody.getDecryptedText(), database);
if(database->onAddNodeCallbackFunc)
+ {
+ std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex);
database->onAddNodeCallbackFunc(addNodeRequest);
+ }
}
catch(DecryptionException &e)
{
@@ -1244,7 +1251,10 @@ namespace odhtdb
Log::debug("Got add user object, timestamp: %zu, user added: %s", timestamp, userToAddPublicKey->toString().c_str());
DatabaseAddUserRequest addUserRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, userToAddPublicKey, groupToAddUserTo, database);
if(database->onAddUserCallbackFunc)
+ {
+ std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex);
database->onAddUserCallbackFunc(addUserRequest);
+ }
return true;
}