diff --git a/README.md b/README.md index d1e4683..49b6a6d 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 @@ -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 @@ -77,8 +77,10 @@ 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 - [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) +- [Drogon](https://github.com/an-tao/drogon/tree/master) +- [XXHASH](https://github.com/Cyan4973/xxHash) 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