From 07f99a86578bee9e7ac0dd0114b89bf983a92d9b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 21 Oct 2018 15:57:36 +0200 Subject: Add database object to callback funcs --- src/DatabaseStorage.cpp | 15 +++++++++------ src/Log.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src') 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 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 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 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); } -- cgit v1.2.3