HTTPServer: generate sequential Ids for each newly accepted connection
What changed, and why it matters
This commit adds a simple internal counter so each incoming HTTP connection can be assigned a unique sequential ID. It does not change any externally visible behavior, fix a bug, or close a security hole. It is a routine code-structure change.
No security action needed. Treat as normal infrastructure/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces HTTPServer::Id as uint64_t, a std::atomic
Changed components
src/httpserver.cppsrc/httpserver.hInspect captured patch +21 / −0
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index 0bda2843..0b846523 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -1008,4 +1008,9 @@ std::unique_ptr<Sock> HTTPServer::AcceptConnection(const Sock& listen_sock, CSer
return sock;
}
+
+HTTPServer::Id HTTPServer::GetNewId()
+{
+ return m_next_id.fetch_add(1, std::memory_order_relaxed);
+}
} // namespace http_bitcoin
diff --git a/src/httpserver.h b/src/httpserver.h
index e4dabc63..20b9731c 100644
--- a/src/httpserver.h
+++ b/src/httpserver.h
@@ -5,6 +5,7 @@
#ifndef BITCOIN_HTTPSERVER_H
#define BITCOIN_HTTPSERVER_H
+#include <atomic>
#include <functional>
#include <memory>
#include <optional>
@@ -306,6 +307,11 @@ public:
class HTTPServer
{
public:
+ /**
+ * Each connection is assigned an unique id of this type.
+ */
+ using Id = uint64_t;
+
/**
* Bind to a new address:port, start listening and add the listen socket to `m_listen`.
* @param[in] to Where to bind.
@@ -339,6 +345,11 @@ private:
*/
std::vector<std::shared_ptr<Sock>> m_listen;
+ /**
+ * The id to assign to the next created connection.
+ */
+ std::atomic<Id> m_next_id{0};
+
/**
* Accept a connection.
* @param[in] listen_sock Socket on which to accept the connection.
@@ -346,6 +357,11 @@ private:
* @return Newly created socket for the accepted connection.
*/
std::unique_ptr<Sock> AcceptConnection(const Sock& listen_sock, CService& addr);
+
+ /**
+ * Generate an id for a newly created connection.
+ */
+ Id GetNewId();
};
} // namespace http_bitcoin
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.