Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/AsyncLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class AsyncLogger {
public:
AsyncLogger() : exitFlag(false) {
AsyncLogger() : exitFlag(false), queueFullWarningShown(false) {
worker = std::thread([this] {
processQueue();
});
Expand All @@ -32,17 +32,27 @@ class AsyncLogger {
void log(const std::string& message) {
{
std::lock_guard<std::mutex> lock(queueMutex);
if (msgQueue.size() >= MAX_QUEUE_SIZE) {
if (!queueFullWarningShown) {
std::cerr << "[Security] AsyncLogger queue full (" << MAX_QUEUE_SIZE
<< " messages). Dropping logs to prevent DoS.\n";
queueFullWarningShown = true;
}
return;
}
msgQueue.push(message);
}
cv.notify_one();
}

private:
const size_t MAX_QUEUE_SIZE = 10000;
std::thread worker;
std::queue<std::string> msgQueue;
std::mutex queueMutex;
std::condition_variable cv;
bool exitFlag;
bool queueFullWarningShown;

void processQueue() {
while (true) {
Expand All @@ -63,6 +73,11 @@ class AsyncLogger {
std::cout << msg << std::flush;
lock.lock();
}

// Reset warning flag when queue is empty
if (msgQueue.empty()) {
queueFullWarningShown = false;
}
}
}
};
4 changes: 0 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ class RacingEngine {
// Async Logger
AsyncLogger logger;

// UX State Tracking
float currentFPS = 0.0f;
float frameTimeMs = 0.0f;

void updateWindowTitle() {
glm::vec3 pos = camera.getPosition();
char title[512];
Expand Down