aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksi Lindeman <aleksi_888@hotmail.com>2018-01-28 07:35:37 +0100
committerAleksi Lindeman <aleksi_888@hotmail.com>2018-01-28 07:35:42 +0100
commit80a9c135b8bdca64246f147f22d98485e0f05ee5 (patch)
treecbba6fc450225efe357d9597b2afc1e30283fe16
parent0fb28e5bc188440236f0b8888fd520892c97094d (diff)
Add some files...
-rw-r--r--.gitignore1
-rw-r--r--.vscode/c_cpp_properties.json79
-rw-r--r--.vscode/settings.json57
-rw-r--r--include/DataView.hpp16
-rw-r--r--include/Database.hpp31
-rw-r--r--include/Group.hpp20
-rw-r--r--include/Key.hpp14
-rw-r--r--include/Permission.hpp14
-rw-r--r--include/User.hpp15
-rw-r--r--include/types.hpp22
-rw-r--r--project.conf9
-rw-r--r--src/Database.cpp48
-rw-r--r--src/Group.cpp13
-rw-r--r--src/main.cpp51
14 files changed, 390 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..97420ef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+sibs-build/
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..6c5092f
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,79 @@
+{
+ "configurations": [
+ {
+ "name": "Mac",
+ "includePath": [
+ "/usr/include",
+ "/usr/local/include",
+ "${workspaceRoot}"
+ ],
+ "defines": [],
+ "intelliSenseMode": "clang-x64",
+ "browse": {
+ "path": [
+ "/usr/include",
+ "/usr/local/include",
+ "${workspaceRoot}"
+ ],
+ "limitSymbolsToIncludedHeaders": true,
+ "databaseFilename": ""
+ },
+ "macFrameworkPath": [
+ "/System/Library/Frameworks",
+ "/Library/Frameworks"
+ ]
+ },
+ {
+ "name": "Linux",
+ "includePath": [
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1/x86_64-pc-linux-gnu",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1/backward",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/include",
+ "/usr/local/include",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/include-fixed",
+ "/usr/include",
+ "~/.sibs/lib/fmt/4.1.0",
+ "${workspaceRoot}"
+ ],
+ "defines": [],
+ "intelliSenseMode": "clang-x64",
+ "browse": {
+ "path": [
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1/x86_64-pc-linux-gnu",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1/backward",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/include",
+ "/usr/local/include",
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/include-fixed",
+ "/usr/include",
+ "~/.sibs/lib/fmt/4.1.0",
+ "${workspaceRoot}"
+ ],
+ "limitSymbolsToIncludedHeaders": true,
+ "databaseFilename": ""
+ }
+ },
+ {
+ "name": "Win32",
+ "includePath": [
+ "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
+ "${workspaceRoot}"
+ ],
+ "defines": [
+ "_DEBUG",
+ "UNICODE"
+ ],
+ "intelliSenseMode": "msvc-x64",
+ "browse": {
+ "path": [
+ "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
+ "${workspaceRoot}"
+ ],
+ "limitSymbolsToIncludedHeaders": true,
+ "databaseFilename": ""
+ }
+ }
+ ],
+ "version": 3
+} \ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..48e2d5a
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,57 @@
+{
+ "files.associations": {
+ "*.ipp": "cpp",
+ "typeinfo": "cpp",
+ "cctype": "cpp",
+ "clocale": "cpp",
+ "cmath": "cpp",
+ "csignal": "cpp",
+ "cstdarg": "cpp",
+ "cstddef": "cpp",
+ "cstdio": "cpp",
+ "cstdlib": "cpp",
+ "cstring": "cpp",
+ "ctime": "cpp",
+ "cwchar": "cpp",
+ "cwctype": "cpp",
+ "array": "cpp",
+ "atomic": "cpp",
+ "strstream": "cpp",
+ "*.tcc": "cpp",
+ "bitset": "cpp",
+ "chrono": "cpp",
+ "cinttypes": "cpp",
+ "codecvt": "cpp",
+ "complex": "cpp",
+ "condition_variable": "cpp",
+ "cstdint": "cpp",
+ "exception": "cpp",
+ "fstream": "cpp",
+ "functional": "cpp",
+ "future": "cpp",
+ "initializer_list": "cpp",
+ "iomanip": "cpp",
+ "iosfwd": "cpp",
+ "iostream": "cpp",
+ "istream": "cpp",
+ "limits": "cpp",
+ "memory": "cpp",
+ "mutex": "cpp",
+ "new": "cpp",
+ "numeric": "cpp",
+ "optional": "cpp",
+ "ostream": "cpp",
+ "ratio": "cpp",
+ "sstream": "cpp",
+ "stdexcept": "cpp",
+ "streambuf": "cpp",
+ "string_view": "cpp",
+ "system_error": "cpp",
+ "thread": "cpp",
+ "tuple": "cpp",
+ "type_traits": "cpp",
+ "utility": "cpp",
+ "valarray": "cpp",
+ "__config": "cpp"
+ }
+} \ No newline at end of file
diff --git a/include/DataView.hpp b/include/DataView.hpp
new file mode 100644
index 0000000..982cb8a
--- /dev/null
+++ b/include/DataView.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "types.hpp"
+
+namespace odhtdb
+{
+ class DataView
+ {
+ public:
+ DataView() : data(nullptr), size(0) {}
+ DataView(void *_data, usize _size) : data(_data), size(_size) {}
+
+ const void *data;
+ const usize size;
+ };
+} \ No newline at end of file
diff --git a/include/Database.hpp b/include/Database.hpp
new file mode 100644
index 0000000..0b324e8
--- /dev/null
+++ b/include/Database.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "types.hpp"
+#include "Key.hpp"
+#include "DataView.hpp"
+#include <opendht/dhtrunner.h>
+#include <vector>
+
+namespace odhtdb
+{
+ struct StagedObject
+ {
+ Key key;
+ DataView data;
+ };
+
+ class Database
+ {
+ public:
+ Database(const char *bootstrapNodeAddr, u16 port);
+ ~Database();
+
+ void add(const Key &key, DataView data);
+ void commit();
+ private:
+ void commitStagedObject(const StagedObject &stagedObject);
+ private:
+ dht::DhtRunner node;
+ std::vector<StagedObject> stagedObjects;
+ };
+} \ No newline at end of file
diff --git a/include/Group.hpp b/include/Group.hpp
new file mode 100644
index 0000000..dafc05a
--- /dev/null
+++ b/include/Group.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <opendht/crypto.h>
+#include <string>
+#include <vector>
+
+namespace odhtdb
+{
+ class User;
+
+ class Group
+ {
+ public:
+ ~Group();
+ private:
+ dht::crypto::PublicKey publicKey;
+ std::string name;
+ std::vector<User*> users;
+ };
+} \ No newline at end of file
diff --git a/include/Key.hpp b/include/Key.hpp
new file mode 100644
index 0000000..e9f0591
--- /dev/null
+++ b/include/Key.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <opendht/infohash.h>
+
+namespace odhtdb
+{
+ class Key
+ {
+ public:
+ Key(const char *key) : hashedKey(dht::InfoHash::get(key)) {}
+
+ dht::InfoHash hashedKey;
+ };
+} \ No newline at end of file
diff --git a/include/Permission.hpp b/include/Permission.hpp
new file mode 100644
index 0000000..a6a16c3
--- /dev/null
+++ b/include/Permission.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "types.hpp"
+
+namespace odhtdb
+{
+ enum class Permission : u8
+ {
+ NONE,
+ READ,
+ WRITE,
+ READ_WRITE
+ };
+} \ No newline at end of file
diff --git a/include/User.hpp b/include/User.hpp
new file mode 100644
index 0000000..727bbcf
--- /dev/null
+++ b/include/User.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <opendht/crypto.h>
+#include <string>
+
+namespace odhtdb
+{
+ class User
+ {
+ public:
+ private:
+ dht::crypto::PublicKey publicKey;
+ std::string name;
+ };
+} \ No newline at end of file
diff --git a/include/types.hpp b/include/types.hpp
new file mode 100644
index 0000000..3cf7f02
--- /dev/null
+++ b/include/types.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <cstdint>
+
+namespace odhtdb
+{
+ typedef int8_t i8;
+ typedef int16_t i16;
+ typedef int32_t i32;
+ typedef int64_t i64;
+
+ typedef uint8_t u8;
+ typedef uint16_t u16;
+ typedef uint32_t u32;
+ typedef uint64_t u64;
+
+ typedef float f32;
+ typedef double f64;
+
+ typedef intptr_t isize;
+ typedef uintptr_t usize;
+}
diff --git a/project.conf b/project.conf
new file mode 100644
index 0000000..6c261d6
--- /dev/null
+++ b/project.conf
@@ -0,0 +1,9 @@
+[package]
+name = "odhtdb"
+version = "0.1.0"
+type = "executable"
+platforms = ["linux32", "linux64"]
+
+[dependencies]
+opendht = "1.5.0"
+fmt = "4.1.0"
diff --git a/src/Database.cpp b/src/Database.cpp
new file mode 100644
index 0000000..4fa8405
--- /dev/null
+++ b/src/Database.cpp
@@ -0,0 +1,48 @@
+#include "../include/Database.hpp"
+#include <opendht.h>
+#include <fmt/format.h>
+
+using namespace dht;
+using namespace std;
+
+namespace odhtdb
+{
+ Database::Database(const char *bootstrapNodeAddr, u16 port)
+ {
+ node.run(port, dht::crypto::generateIdentity(), true);
+ fmt::MemoryWriter portStr;
+ portStr << port;
+ node.bootstrap(bootstrapNodeAddr, portStr.c_str());
+ }
+
+ Database::~Database()
+ {
+ node.join();
+ }
+
+ void Database::add(const Key &key, DataView data)
+ {
+ stagedObjects.emplace_back(StagedObject{ key, data });
+ }
+
+ void Database::commit()
+ {
+ // TODO: Combine staged objects into one object
+ for(StagedObject stagedObject : stagedObjects)
+ {
+ commitStagedObject(stagedObject);
+ }
+ stagedObjects.clear();
+ }
+
+ void Database::commitStagedObject(const StagedObject &stagedObject)
+ {
+ Value value((const u8*)stagedObject.data.data, stagedObject.data.size);
+ node.put(stagedObject.key.hashedKey, move(value), [](bool ok)
+ {
+ // TODO: Handle failure to put data
+ if(!ok)
+ fprintf(stderr, "Failed to put: %s, what to do?\n", "commitStagedObject");
+ }, time_point(), false);
+ }
+} \ No newline at end of file
diff --git a/src/Group.cpp b/src/Group.cpp
new file mode 100644
index 0000000..213a0bb
--- /dev/null
+++ b/src/Group.cpp
@@ -0,0 +1,13 @@
+#include "../include/Group.hpp"
+#include "../include/User.hpp"
+
+namespace odhtdb
+{
+ Group::~Group()
+ {
+ for(User *user : users)
+ {
+ delete user;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..8e38e18
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,51 @@
+#include <opendht.h>
+#include <vector>
+#include "../include/Database.hpp"
+
+using namespace odhtdb;
+
+int main()
+{
+ Database database("bootstrap.ring.cx", 4222);
+ Key channelChatKey("galax.channel.CAGERIJF232dKADS528392fawdkf3fas.chat");
+ const char *data = "hello, world!";
+ database.add(channelChatKey, DataView{ (void*)data, strlen(data) });
+ database.commit();
+
+ /*
+ Database database("bootstrap.ring.cx", 4222);
+ Key channelChatKey("galax.channel.CAGERIJF232dKADS528392fawdkf3fas.chat");
+ database.add(channelChatKey, { localUser, date, "hello, world!" });
+ */
+
+#if 0
+ dht::DhtRunner node;
+
+ // Launch a dht node on a new thread, using a
+ // generated RSA key pair, and listen on port 4222.
+ node.run(4222, dht::crypto::generateIdentity(), true);
+
+ // Join the network through any running node,
+ // here using a known bootstrap node.
+ node.bootstrap("bootstrap.ring.cx", "4222");
+
+ // put some data on the dht
+ std::vector<uint8_t> some_data(5, 10);
+ node.put("unique_key", some_data);
+
+ // put some data on the dht, signed with our generated private key
+ node.putSigned("unique_key_42", some_data);
+
+ // get data from the dht
+ node.get("other_unique_key", [](const std::vector<std::shared_ptr<dht::Value>>& values) {
+ // Callback called when values are found
+ for (const auto& value : values)
+ std::cout << "Found value: " << *value << std::endl;
+ return true; // return false to stop the search
+ });
+
+ // wait for dht threads to end
+ node.join();
+ #endif
+ return 0;
+} \ No newline at end of file