From 17091ad9d2973e262f060dc9e3f4ad7051e3e3d3 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Apr 2021 06:58:56 -0700 Subject: [PATCH 1/3] :racehorse: replaced hash function --- README.md | 3 ++- include/bank.hpp | 10 +++++----- include/user.hpp | 4 ++-- main.cpp | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d1e4683..133231c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ make -j sudo ./bank ``` -you also have to edit the config file to add your cert locations, I personally use cert bot +**you also have to edit the config file to add your cert locations**, I personally use cert bot ### Connected Services @@ -77,6 +77,7 @@ Ideas: - **Web front-end** - **RESTful** API for connected services like a market, gambling, or anything else you can think of - able to be used millions of blocks away, across dimensions, servers, **vanilla or modded**. In contrast to an in-game modded implementation that would be range limited. +- **Logging** #### Dependencies diff --git a/include/bank.hpp b/include/bank.hpp index 5c92dc9..f7aa24c 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -54,7 +54,7 @@ public: bool DelUser(const std::string &name, const std::string &attempt) { std::shared_lock lock{size_lock}; - return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 1) == u.password); }); + return users.erase_if(name, [&attempt](const User &u) { return (XXH3_64bits(attempt.data(), attempt.size()) == u.password); }); } bool AdminDelUser(const std::string &name, const std::string &attempt) { @@ -75,7 +75,7 @@ public: bool state = false; std::shared_lock lock{send_funds_l}; //because SendFunds requires 3 locking operations users.modify_if(a_name, [&state, amount, &attempt](User &a) { - if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 1))) + if (state = (a.balance >= amount) && (a.password == XXH3_64bits(attempt.data(), attempt.size()))) { a.balance -= amount; } @@ -130,7 +130,7 @@ public: { int_fast8_t res = -1; users.if_contains(name, [&res, &attempt](const User &u) { - res = u.password == XXH64(attempt.data(), attempt.size(), 1); + res = u.password == XXH3_64bits(attempt.data(), attempt.size()); }); return res; } @@ -138,10 +138,10 @@ public: { int_fast8_t res = -1; users.modify_if(name, [&res, &attempt, &new_pass](User &u) { - res = (u.password == XXH64(attempt.data(), attempt.size(), 1)); + res = (u.password == XXH3_64bits(attempt.data(), attempt.size())); if (res) { - u.password = XXH64(new_pass.data(), new_pass.size(), 1); + u.password = XXH3_64bits(new_pass.data(), new_pass.size()); } }); return res; diff --git a/include/user.hpp b/include/user.hpp index 367b9cf..130e776 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -13,7 +13,7 @@ struct User * * @param init_pass initial password */ - User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 1)) {} + User(std::string &&init_pass) : password(XXH3_64bits(init_pass.data(), init_pass.size())) {} /** * @brief User Constructor for admins @@ -21,7 +21,7 @@ struct User * @param init_bal initial balance * @param init_pass initial password */ - User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 1)), is_admin(state) {} + User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())), is_admin(state) {} User(uint_fast32_t init_bal, uint64_t init_pass, bool state = false) : balance(init_bal), password(init_pass), is_admin(state) {} Json::Value Serialize() const diff --git a/main.cpp b/main.cpp index 77df02c..60f994c 100644 --- a/main.cpp +++ b/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) [](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) { resp->addHeader("Access-Control-Allow-Origin", "*"); }); - app().loadConfigFile("../config.json").addListener("0.0.0.0", 80).registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run(); + app().loadConfigFile("../config.json").registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run(); return 0; } \ No newline at end of file From 1f76d6215e608d03f6f22c0377bb68930d05fd01 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Apr 2021 07:02:54 -0700 Subject: [PATCH 2/3] Updated README for hashing info --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 133231c..80d7d82 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Ideas: - written in **C++**, arguably the fastest language - **multi-threaded** - **parallel hashmaps** a far superior HashMap implementation to the STD, that also benefit from multi-threaded -- **Passwords are Hashed**, allowing each user to be 12 bytes, which is allows hashmap to be flat +- **Passwords are Hashed**, allowing each user to be 12 bytes, which is allows hashmap to be flat. This hashing is also very fast at 31.5 GB/s on a i7-9700K ### Safety @@ -83,3 +83,4 @@ Ideas: - [Parallel HashMap](https://github.com/greg7mdp/parallel-hashmap/tree/master) - [drogon web framework (and all its dependencies)](https://github.com/an-tao/drogon/tree/master) +- [xxhash](https://github.com/Cyan4973/xxHash) From 95749f31886a3e594d8ce72144e5319a52d4f007 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Apr 2021 07:25:41 -0700 Subject: [PATCH 3/3] README changes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80d7d82..49b6a6d 100644 --- a/README.md +++ b/README.md @@ -82,5 +82,5 @@ Ideas: #### Dependencies - [Parallel HashMap](https://github.com/greg7mdp/parallel-hashmap/tree/master) -- [drogon web framework (and all its dependencies)](https://github.com/an-tao/drogon/tree/master) -- [xxhash](https://github.com/Cyan4973/xxHash) +- [Drogon](https://github.com/an-tao/drogon/tree/master) +- [XXHASH](https://github.com/Cyan4973/xxHash)