aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-14 20:13:24 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit080487c961b424c9dd822d38ec8c2c4d79aff24b (patch)
tree2380205a466eee8837d62f599b83a3a50c41d7c1 /include
parent4241bcd4e14095e4340a0300e205f6fdc503f1d8 (diff)
Only download nodes that we are missing
Diffstat (limited to 'include')
-rw-r--r--include/odhtdb/DatabaseStorage.hpp14
-rw-r--r--include/odhtdb/sql/Sql.hpp37
-rw-r--r--include/odhtdb/sql/SqlExec.hpp33
-rw-r--r--include/odhtdb/sql/SqlQuery.hpp30
4 files changed, 82 insertions, 32 deletions
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp
index 0d94c91..73b22b9 100644
--- a/include/odhtdb/DatabaseStorage.hpp
+++ b/include/odhtdb/DatabaseStorage.hpp
@@ -63,8 +63,10 @@ namespace odhtdb
const int PASSWORD_SALT_LEN = 16;
const int HASHED_PASSWORD_LEN = 32;
- using FetchNodeRawCallbackFunc = std::function<void(const DataView)>;
- using FetchNodeAddDataRawCallbackFunc = std::function<void(const DataView)>;
+ using FetchNodeRawCallbackFunc = std::function<void(const DataView rawData)>;
+ using FetchNodeAddDataRawCallbackFunc = std::function<void(const DataView rawData, const DataView creatorPublicKey, u64 actionCounter)>;
+ using FetchNodeUserActionGapsCallbackFunc = std::function<void(const DataView userPublicKey, u64 start, u64 range)>;
+ using FetchNodeUserLatestActionCounterCallbackFunc = std::function<void(const DataView userPublicKey, u64 latestActionCounter)>;
class DatabaseStorage
{
@@ -83,7 +85,7 @@ namespace odhtdb
// Throws DatabaseStorageNotFound if data with @nodeHash hash has not been created yet.
// Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash)
- void appendStorage(const Hash &nodeHash, const Hash &dataHash, DatabaseOperation operation, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const void *data, usize size, const DataView &additionalDataView);
+ void appendStorage(const Hash &nodeHash, const Hash &dataHash, DatabaseOperation operation, u64 newUserActionCounter, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const void *data, usize size, const DataView &additionalDataView);
// Throws DatabaseStorageAlreadyExists if group already exists in node
void addGroup(const Hash &nodeHash, const DataView &groupId, const Permission &permissions);
@@ -96,9 +98,15 @@ namespace odhtdb
void fetchNodeRaw(const Hash &nodeHash, FetchNodeRawCallbackFunc callbackFunc);
void fetchNodeAddDataRaw(const Hash &nodeHash, FetchNodeAddDataRawCallbackFunc callbackFunc);
+ void fetchNodeUserActionGaps(const Hash &nodeHash, FetchNodeUserActionGapsCallbackFunc callbackFunc);
+ void fetchNodeUserLatestActionCounter(const Hash &nodeHash, FetchNodeUserLatestActionCounterCallbackFunc callbackFunc);
+
bool isUserAllowedToAddDataInNode(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const;
bool isUserAllowedToAddUserToGroupInNode(const Hash &nodeHash, const Signature::PublicKey &userPublicKey, const DataView &groupToAddUserTo) const;
+ // Throws DatabaseStorageNotFound if user doesn't exist in node
+ u64 getUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const;
+
// Username and key pair has to be unique, returns true on success
//bool storeLocalUser(const std::string &username, const Signature::KeyPair &keyPair, const std::string &password);
diff --git a/include/odhtdb/sql/Sql.hpp b/include/odhtdb/sql/Sql.hpp
new file mode 100644
index 0000000..6c78360
--- /dev/null
+++ b/include/odhtdb/sql/Sql.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "../DataView.hpp"
+
+class sqlite3;
+class sqlite3_stmt;
+
+namespace odhtdb
+{
+ class SqlArg
+ {
+ public:
+ enum class Type : u8
+ {
+ DATA_VIEW,
+ INT,
+ INT64,
+ UINT64
+ };
+
+ SqlArg(const DataView &data) : dataView(data), type(Type::DATA_VIEW) {}
+ SqlArg(int data) : integer(data), type(Type::INT) {}
+ SqlArg(i64 data) : integer64(data), type(Type::INT64) {}
+ SqlArg(u64 data) : uinteger64(data), type(Type::UINT64) {}
+
+ int bind(sqlite3_stmt *stmt, int paramIndex) const;
+ private:
+ union
+ {
+ const DataView dataView;
+ const int integer;
+ const i64 integer64;
+ const u64 uinteger64;
+ };
+ const Type type;
+ };
+}
diff --git a/include/odhtdb/sql/SqlExec.hpp b/include/odhtdb/sql/SqlExec.hpp
new file mode 100644
index 0000000..07146ea
--- /dev/null
+++ b/include/odhtdb/sql/SqlExec.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "Sql.hpp"
+#include <utility>
+#include <stdexcept>
+#include <mutex>
+
+namespace odhtdb
+{
+ class SqlExecException : public std::runtime_error
+ {
+ public:
+ SqlExecException(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
+ class SqlExec
+ {
+ public:
+ // Throws SqlExecException on failure
+ SqlExec(sqlite3 *db, const char *sql);
+ ~SqlExec();
+
+ // Throws SqlExecException on failure
+ void execWithArgs(std::initializer_list<SqlArg> args);
+
+ // Throws SqlExecException on failure
+ void exec();
+ private:
+ sqlite3 *db;
+ sqlite3_stmt *stmt;
+ std::mutex mutex;
+ };
+}
diff --git a/include/odhtdb/sql/SqlQuery.hpp b/include/odhtdb/sql/SqlQuery.hpp
index f26ee1a..615fa3f 100644
--- a/include/odhtdb/sql/SqlQuery.hpp
+++ b/include/odhtdb/sql/SqlQuery.hpp
@@ -1,12 +1,9 @@
#pragma once
-#include "../DataView.hpp"
+#include "Sql.hpp"
#include <utility>
#include <stdexcept>
-class sqlite3;
-class sqlite3_stmt;
-
namespace odhtdb
{
class SqlQueryException : public std::runtime_error
@@ -15,31 +12,6 @@ namespace odhtdb
SqlQueryException(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
- class SqlArg
- {
- public:
- enum class Type : u8
- {
- DATA_VIEW,
- INT,
- INT64
- };
-
- SqlArg(const DataView &data) : dataView(data), type(Type::DATA_VIEW) {}
- SqlArg(int data) : integer(data), type(Type::INT) {}
- SqlArg(i64 data) : integer64(data), type(Type::INT64) {}
-
- int bind(sqlite3_stmt *stmt, int paramIndex) const;
- private:
- union
- {
- const DataView dataView;
- const int integer;
- const i64 integer64;
- };
- const Type type;
- };
-
class SqlQuery
{
public: