aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-11 17:10:39 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit0c8761b3d76912f034a0cb819d72f0349a25bf4f (patch)
tree894a8d68f767d21b2239fee662cfb577bd7c988a /src
parent5e30dd8fd378b0dfb24a67aa75aec1d0902c0243 (diff)
Remove commit, maybe readd it later
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp96
1 files changed, 28 insertions, 68 deletions
diff --git a/src/Database.cpp b/src/Database.cpp
index ee18b87..41d3798 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -321,12 +321,21 @@ namespace odhtdb
shared_ptr<Hash> hashRequestKey = make_shared<Hash>(requestData.data, requestData.size);
databaseStorage.setNodeDecryptionKey(*hashRequestKey, DataView(encryptedBody.getKey().data, encryptedBody.getKey().size));
databaseStorage.createStorage(*hashRequestKey, adminGroup, timestampCombined, (const u8*)requestData.data, requestData.size, serializer.getBuffer().size());
-
- stagedCreateObjects.emplace_back(make_unique<StagedObject>(requestData, hashRequestKey));
assert(encryptedBody.getKey().size == ENCRYPTION_KEY_BYTE_SIZE);
auto key = make_shared<OwnedMemory>(new char[encryptedBody.getKey().size], encryptedBody.getKey().size);
memcpy(key->data, encryptedBody.getKey().data, encryptedBody.getKey().size);
+
+ DhtKey dhtKey(*hashRequestKey);
+ Value createDataValue((u8*)requestData.data, requestData.size);
+ delete[] (char*)requestData.data;
+ node.put(dhtKey.getNewDataListenerKey(), move(createDataValue), [](bool ok)
+ {
+ // TODO: Handle failure to put data
+ if(!ok)
+ Log::warn("Failed to put: %s, what to do?", "Database::create");
+ });
+
return make_unique<DatabaseCreateResponse>(nodeAdminUser, move(key), hashRequestKey);
}
catch (EncryptionException &e)
@@ -349,9 +358,7 @@ namespace odhtdb
errMsg += " is not allowed to perform the operation: ADD_USER";
throw PermissionDeniedException(errMsg);
}
-
- //u64 actionCounter = databaseStorage.increaseUserActionCounter(userToPerformActionWith->getPublicKey());
-
+
sibs::SafeSerializer serializer;
serializer.add(DATABASE_ADD_PACKET_STRUCTURE_VERSION);
u64 timestampCombined = getSyncedTimestampUtc().getCombined();
@@ -367,8 +374,16 @@ namespace odhtdb
DataView encryptedDataView((char*)requestData.data + serializer.getBuffer().size(), requestData.size - serializer.getBuffer().size());
databaseStorage.appendStorage(*nodeInfo.getRequestHash(), requestDataHash, DatabaseOperation::ADD_DATA, userToPerformActionWith, timestampCombined, (u8*)stagedAddObject.data, stagedAddObject.size, encryptedDataView);
delete[] (char*)requestData.data;
-
- stagedAddObjects.emplace_back(make_unique<StagedObject>(stagedAddObject, nodeInfo.getRequestHash()));
+
+ DhtKey dhtKey(requestDataHash);
+ Value addDataValue((u8*)stagedAddObject.data, stagedAddObject.size);
+ delete[] (char*)stagedAddObject.data;
+ node.put(dhtKey.getNewDataListenerKey(), move(addDataValue), [](bool ok)
+ {
+ // TODO: Handle failure to put data
+ if(!ok)
+ Log::warn("Failed to put: %s, what to do?", "Database::addData");
+ });
}
Group* getGroupWithRightsToAddUserToGroup(const vector<Group*> &groups, Group *groupToAddUserTo)
@@ -426,71 +441,16 @@ namespace odhtdb
auto userToAdd = RemoteUser::create(userToAddPublicKey, userToAddName, groupToAddUserTo);
databaseStorage.addUser(*nodeInfo.getRequestHash(), userToAdd);
databaseStorage.appendStorage(*nodeInfo.getRequestHash(), requestDataHash, DatabaseOperation::ADD_USER, userToPerformActionWith, timestampCombined, (u8*)stagedAddObject.data, stagedAddObject.size, encryptedDataView);
-
- stagedAddObjects.emplace_back(make_unique<StagedObject>(stagedAddObject, nodeInfo.getRequestHash()));
- }
-
- void Database::commit()
- {
- // TODO: Combine staged objects into one object for efficiency.
-
- try
- {
- Log::debug("Num objects to create: %zu", stagedCreateObjects.size());
- for(const auto &stagedObject : stagedCreateObjects)
- {
- commitStagedCreateObject(stagedObject);
- }
-
- Log::debug("Num objects to add: %zu", stagedAddObjects.size());
- for(const auto &stagedObject : stagedAddObjects)
- {
- commitStagedAddObject(stagedObject);
- }
- }
- catch (exception &e)
- {
- // TODO: Add rollback
- Log::error("Failed to commit, reason: %s", e.what());
- }
-
- for(const auto &stagedObject : stagedCreateObjects)
- {
- delete[] (char*)stagedObject->data.data;
- }
- stagedCreateObjects.clear();
- for(const auto &stagedObject : stagedAddObjects)
- {
- delete[] (char*)stagedObject->data.data;
- }
- stagedAddObjects.clear();
-
- // TODO: Add node.listen here to get notified when remote peers got the commit, then we can say we can return
- }
-
- void Database::commitStagedCreateObject(const unique_ptr<StagedObject> &stagedObject)
- {
- DhtKey dhtKey(*stagedObject->requestKey);
- Value createDataValue((u8*)stagedObject->data.data, stagedObject->data.size);
- node.put(dhtKey.getNewDataListenerKey(), move(createDataValue), [](bool ok)
+ DhtKey dhtKey(requestDataHash);
+ Value addDataValue((u8*)stagedAddObject.data, stagedAddObject.size);
+ delete[] (char*)stagedAddObject.data;
+ node.put(dhtKey.getNewDataListenerKey(), move(addDataValue), [](bool ok)
{
// TODO: Handle failure to put data
if(!ok)
- Log::warn("Failed to put: %s, what to do?", "commitStagedCreateObject");
- }/* TODO: How to make this work?, time_point(), false*/);
- }
-
- void Database::commitStagedAddObject(const unique_ptr<StagedObject> &stagedObject)
- {
- DhtKey dhtKey(*stagedObject->requestKey);
- Value createDataValue((u8*)stagedObject->data.data, stagedObject->data.size);
- node.put(dhtKey.getNewDataListenerKey(), move(createDataValue), [](bool ok)
- {
- // TODO: Handle failure to put data
- if(!ok)
- Log::warn("Failed to put: %s, what to do?", "commitStagedAddObject");
- }/* TODO: How to make this work?, time_point(), false*/);
+ Log::warn("Failed to put: %s, what to do?", "Database::addUser");
+ });
}
ntp::NtpTimestamp Database::getSyncedTimestampUtc() const