Loading src/api.cpp +17 −51 Original line number Diff line number Diff line Loading @@ -354,13 +354,7 @@ public: sha512 sha; sha.hash(pw, pwsalt); // O(1) indexed lookup by clientname instead of O(n) scan. // If index points to an unusable client record (seen under heavy parallel checks), // run one repair pass (vacuum + index invalidate) and retry once. bool repairedOnce = false; for (;;) { bool inconsistentIndexedHit = false; // O(1) indexed lookup by clientname instead of O(n) scan { AuthBackend::Guard guard(_Backend, AuthBackend::Shared); RecordIndex &idx = _Backend.getIndex(); Loading @@ -368,22 +362,12 @@ public: idx.build(_Backend); uuid::uuid found_clid; if (!idx.findByName(DataType::ClientData, "clientname", name, found_clid)) { return nullptr; } if (idx.findByName(DataType::ClientData, "clientname", name, found_clid)) { class ClientData cdat(found_clid); size_t upos = sizeof(AuthHeader); AuthClient.info(_Backend, cdat, upos); try { const char *storedName = cdat.getName(); const char *storedKey = cdat.getKey(); if (!storedName || !storedKey || storedName[0] == '\0' || storedKey[0] == '\0') { inconsistentIndexedHit = true; } else if (name != storedName) { inconsistentIndexedHit = true; } else if (constant_time_eq(pwsalt, storedKey)) { if (constant_time_eq(pwsalt, cdat.getKey())) { ClientConnections* cid = AuthClient.addConnection(_Backend, cdat); json_object* respid = json_object_new_object(); uuid::uuid coid = cid->getId(); Loading @@ -391,27 +375,9 @@ public: json_object_new_string(coid.c_str())); json_object_array_add(response, respid); return cid; } else { return nullptr; // wrong secret } } catch (const AuthBackendError &) { inconsistentIndexedHit = true; } } if (inconsistentIndexedHit && !repairedOnce && _Backend.getType() == AuthBackendType::File) { repairedOnce = true; try { vacuumRecords(_Backend); _Backend.getIndex().invalidate(); continue; } catch (const std::exception &e) { std::cerr << "[api] ClientLogin repair failed: " << e.what() << std::endl; return nullptr; } return nullptr; // wrong secret } return nullptr; } } } Loading Loading
src/api.cpp +17 −51 Original line number Diff line number Diff line Loading @@ -354,13 +354,7 @@ public: sha512 sha; sha.hash(pw, pwsalt); // O(1) indexed lookup by clientname instead of O(n) scan. // If index points to an unusable client record (seen under heavy parallel checks), // run one repair pass (vacuum + index invalidate) and retry once. bool repairedOnce = false; for (;;) { bool inconsistentIndexedHit = false; // O(1) indexed lookup by clientname instead of O(n) scan { AuthBackend::Guard guard(_Backend, AuthBackend::Shared); RecordIndex &idx = _Backend.getIndex(); Loading @@ -368,22 +362,12 @@ public: idx.build(_Backend); uuid::uuid found_clid; if (!idx.findByName(DataType::ClientData, "clientname", name, found_clid)) { return nullptr; } if (idx.findByName(DataType::ClientData, "clientname", name, found_clid)) { class ClientData cdat(found_clid); size_t upos = sizeof(AuthHeader); AuthClient.info(_Backend, cdat, upos); try { const char *storedName = cdat.getName(); const char *storedKey = cdat.getKey(); if (!storedName || !storedKey || storedName[0] == '\0' || storedKey[0] == '\0') { inconsistentIndexedHit = true; } else if (name != storedName) { inconsistentIndexedHit = true; } else if (constant_time_eq(pwsalt, storedKey)) { if (constant_time_eq(pwsalt, cdat.getKey())) { ClientConnections* cid = AuthClient.addConnection(_Backend, cdat); json_object* respid = json_object_new_object(); uuid::uuid coid = cid->getId(); Loading @@ -391,27 +375,9 @@ public: json_object_new_string(coid.c_str())); json_object_array_add(response, respid); return cid; } else { return nullptr; // wrong secret } } catch (const AuthBackendError &) { inconsistentIndexedHit = true; } } if (inconsistentIndexedHit && !repairedOnce && _Backend.getType() == AuthBackendType::File) { repairedOnce = true; try { vacuumRecords(_Backend); _Backend.getIndex().invalidate(); continue; } catch (const std::exception &e) { std::cerr << "[api] ClientLogin repair failed: " << e.what() << std::endl; return nullptr; } return nullptr; // wrong secret } return nullptr; } } } Loading