aboutsummaryrefslogtreecommitdiff
path: root/src/InfoHash.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-16 00:38:01 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit0e627b69d4d0a8d01a21e4dc9bd7be370c0a1245 (patch)
treeb4385cb95cf6b4315000c149ac115c15fec10bba /src/InfoHash.cpp
parent060b6db1aadccd1ad3495c52a15b4a789e4bc8da (diff)
Replace opendht with sibs pubsub
This should fix issues with memory usage/leaks and make it easier to get peers subscribed to the same key. It will also be easier to modify and also works easier cross platform because of no additional dependencies.
Diffstat (limited to 'src/InfoHash.cpp')
-rw-r--r--src/InfoHash.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/InfoHash.cpp b/src/InfoHash.cpp
new file mode 100644
index 0000000..90e6e31
--- /dev/null
+++ b/src/InfoHash.cpp
@@ -0,0 +1,37 @@
+#include "../include/odhtdb/InfoHash.hpp"
+#include <sodium/crypto_generichash_blake2b.h>
+#include <sodium/core.h>
+#include <algorithm>
+
+namespace odhtdb
+{
+ InfoHash::InfoHash()
+ {
+
+ }
+
+ InfoHash::InfoHash(const u8 *data, const size_t size) :
+ key(data, size)
+ {
+
+ }
+
+ InfoHash InfoHash::generateHash(const u8 *data, const size_t size)
+ {
+ InfoHash infoHash;
+ int result = crypto_generichash_blake2b((unsigned char*)&infoHash.key.data[0], infoHash.key.data.size(), (const unsigned char*)data, size, nullptr, 0);
+ if(result < 0)
+ throw InfoHashException("Failed to hash data using blake2b");
+ return infoHash;
+ }
+
+ bool InfoHash::operator == (const InfoHash &other) const
+ {
+ return key == other.key;
+ }
+
+ bool InfoHash::operator != (const InfoHash &other) const
+ {
+ return !(*this == other);
+ }
+} \ No newline at end of file