aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-02-10 19:36:35 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:12 +0200
commita9a7ecaa25e6bc11062e21affd458e2de78747ff (patch)
treec14a4e269cbf46163cf334781a5925d052e72aa1 /src
parent64df3de50aa88f15e1a46f21a0f62281eb582603 (diff)
Fix put not working because used time discards message before received
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;
}