aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-10-21 15:57:36 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-10-21 15:57:36 +0200
commit109108c896f1ada76121330ab01602072f32dd8c (patch)
tree64546db690e8edb814053ebcfb3603ff792a0a54 /src
parent22abf1aa83b2668f918556491a55947be798f89f (diff)
Add database object to callback funcs
Diffstat (limited to 'src')
-rw-r--r--src/DatabaseStorage.cpp15
-rw-r--r--src/Log.cpp12
2 files changed, 15 insertions, 12 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index de9d0df..34dd09a 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -14,6 +14,9 @@
using namespace std;
+// TODO: The latest user data will be used when processing old nodes. When processing a node the user state should be the same as it was at the time the node was created.
+// This can be done by having history of changes in user data so we can retrieve the user data state at a specific time in history.
+
namespace odhtdb
{
enum StorageType : u8
@@ -230,7 +233,7 @@ namespace odhtdb
const DataView adminGroupRaw = nodeQuery.getBlob(2);
memcpy(adminGroupId, adminGroupRaw.data, GROUP_ID_LENGTH);
- DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, &creatorPublicKey, DataView(adminGroupId, GROUP_ID_LENGTH));
+ DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, &creatorPublicKey, DataView(adminGroupId, GROUP_ID_LENGTH), database);
createNodeRequest.loadedFromCache = true;
database->onCreateNodeCallbackFunc(createNodeRequest);
}
@@ -278,7 +281,7 @@ namespace odhtdb
OwnedByteArray decryptedData(new u8[decryptedDataSize], decryptedDataSize);
memcpy(decryptedData.data, decryptedDataRaw, decryptedDataSize);
- DatabaseAddNodeRequest addNodeRequest(&nodeHash, &requestHash, timestamp, &creatorPublicKey, DataView(decryptedData.data, decryptedData.size));
+ DatabaseAddNodeRequest addNodeRequest(&nodeHash, &requestHash, timestamp, &creatorPublicKey, DataView(decryptedData.data, decryptedData.size), database);
addNodeRequest.loadedFromCache = true;
database->onAddNodeCallbackFunc(addNodeRequest);
}
@@ -307,7 +310,7 @@ namespace odhtdb
u8 groupToAddUserTo[GROUP_ID_LENGTH];
memcpy(groupToAddUserTo, groupToAddUserToRaw, GROUP_ID_LENGTH);
- DatabaseAddUserRequest addUserRequest(&nodeHash, &requestHash, timestamp, &creatorPublicKey, &userToAddPublicKey, DataView(groupToAddUserTo, GROUP_ID_LENGTH));
+ DatabaseAddUserRequest addUserRequest(&nodeHash, &requestHash, timestamp, &creatorPublicKey, &userToAddPublicKey, DataView(groupToAddUserTo, GROUP_ID_LENGTH), database);
addUserRequest.loadedFromCache = true;
database->onAddUserCallbackFunc(addUserRequest);
}
@@ -1048,7 +1051,7 @@ namespace odhtdb
bool DatabaseStorage::decryptNodeData(const Hash &nodeHash, const shared_ptr<OwnedByteArray> decryptionKey, const Signature::PublicKey *creatorPublicKey, const DataView &adminGroupId, u64 timestamp)
{
- const DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, creatorPublicKey, adminGroupId);
+ const DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, creatorPublicKey, adminGroupId, database);
if(database->onCreateNodeCallbackFunc)
database->onCreateNodeCallbackFunc(createNodeRequest);
@@ -1206,7 +1209,7 @@ namespace odhtdb
setNodeAddDataDecryptedData(rowId, decryptedBody.getDecryptedText());
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());
+ const DatabaseAddNodeRequest addNodeRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, decryptedBody.getDecryptedText(), database);
if(database->onAddNodeCallbackFunc)
database->onAddNodeCallbackFunc(addNodeRequest);
}
@@ -1239,7 +1242,7 @@ namespace odhtdb
setNodeAddDataDecrypted(rowId);
Log::debug("Got add user object, timestamp: %zu, user added: %s", timestamp, userToAddPublicKey->toString().c_str());
- DatabaseAddUserRequest addUserRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, userToAddPublicKey, groupToAddUserTo);
+ DatabaseAddUserRequest addUserRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, userToAddPublicKey, groupToAddUserTo, database);
if(database->onAddUserCallbackFunc)
database->onAddUserCallbackFunc(addUserRequest);
return true;
diff --git a/src/Log.cpp b/src/Log.cpp
index b8f75c8..0feb3ac 100644
--- a/src/Log.cpp
+++ b/src/Log.cpp
@@ -13,9 +13,9 @@ namespace odhtdb
std::lock_guard<std::mutex> lock(mutexLog);
va_list args;
va_start(args, fmt);
- fputs("\033[1;32mDebug:\033[0m ", stdout);
- vfprintf(stdout, fmt, args);
- fputs("\n", stdout);
+ fputs("\033[1;32mDebug:\033[0m ", stderr);
+ vfprintf(stderr, fmt, args);
+ fputs("\n", stderr);
va_end(args);
}
@@ -24,9 +24,9 @@ namespace odhtdb
std::lock_guard<std::mutex> lock(mutexLog);
va_list args;
va_start(args, fmt);
- fputs("\033[1;33mWarning:\033[0m ", stdout);
- vfprintf(stdout, fmt, args);
- fputs("\n", stdout);
+ fputs("\033[1;33mWarning:\033[0m ", stderr);
+ vfprintf(stderr, fmt, args);
+ fputs("\n", stderr);
va_end(args);
}