aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/Database.cpp b/src/Database.cpp
index f0c7b04..cd87845 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -104,17 +104,21 @@ namespace odhtdb
// TODO: Combine staged objects into one object for efficiency.
// TODO: Add rollback
+ printf("Num objects to create: %d\n", stagedCreateObjects.size());
for(StagedCreateObject &stagedObject : stagedCreateObjects)
{
commitStagedCreateObject(stagedObject);
}
stagedCreateObjects.clear();
+ printf("Num objects to add: %d\n", stagedAddObjects.size());
for(StagedAddObject &stagedObject : stagedAddObjects)
{
commitStagedAddObject(stagedObject);
}
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 StagedCreateObject &stagedObject)
@@ -143,7 +147,7 @@ namespace odhtdb
// TODO: Handle failure to put data
if(!ok)
fprintf(stderr, "Failed to put: %s, what to do?\n", "commitStagedCreateObject");
- }, time_point(), false);
+ }/* TODO: How to make this work?, time_point(), false*/);
// Post data for listeners of this key
Value putKeyValue(serializer.getBuffer().data() + OPENDHT_INFOHASH_LEN, serializer.getBuffer().size() - OPENDHT_INFOHASH_LEN);
@@ -152,7 +156,7 @@ namespace odhtdb
// TODO: Handle failure to put data
if(!ok)
fprintf(stderr, "Failed to put for listeners: %s, what to do?\n", "commitStagedCreateObject");
- }, time_point(), false);
+ });
}
void Database::commitStagedAddObject(const StagedAddObject &stagedObject)
@@ -242,36 +246,32 @@ namespace odhtdb
return result;
}
- bool Database::listenCreateData(const std::vector<std::shared_ptr<dht::Value>> &values)
+ bool Database::listenCreateData(std::shared_ptr<dht::Value> value)
{
- for(const shared_ptr<Value> &value : values)
+ printf("Got create data\n");
+ try
{
- try
- {
- // TODO: Verify createObject timestamp is not in the future
- StagedCreateObject createObject = deserializeCreateRequest(value);
- delete createObject.primaryAdminGroup;
- }
- catch (sibs::DeserializeException &e)
- {
- fprintf(stderr, "Warning: Failed to deserialize 'create' request: %s\n", e.what());
- }
+ // TODO: Verify createObject timestamp is not in the future
+ StagedCreateObject createObject = deserializeCreateRequest(value);
+ delete createObject.primaryAdminGroup;
+ }
+ catch (sibs::DeserializeException &e)
+ {
+ fprintf(stderr, "Warning: Failed to deserialize 'create' request: %s\n", e.what());
}
return true;
}
- bool Database::listenAddData(const std::vector<std::shared_ptr<dht::Value>> &values)
+ bool Database::listenAddData(std::shared_ptr<dht::Value> value)
{
- for(const shared_ptr<Value> &value : values)
+ printf("Got add data\n");
+ try
{
- try
- {
- StagedAddObject addObject = deserializeAddRequest(value);
- }
- catch (sibs::DeserializeException &e)
- {
- fprintf(stderr, "Warning: Failed to deserialize 'add' request: %s\n", e.what());
- }
+ StagedAddObject addObject = deserializeAddRequest(value);
+ }
+ catch (sibs::DeserializeException &e)
+ {
+ fprintf(stderr, "Warning: Failed to deserialize 'add' request: %s\n", e.what());
}
return true;
}