diff --git a/src/request.h b/src/request.h index 2a0d9395..11689223 100644 --- a/src/request.h +++ b/src/request.h @@ -29,6 +29,8 @@ namespace net { class NetworkEngine; struct ParsedMessage; +extern std::atomic REQ_COUNT; + /*! * @class Request * @brief An atomic request destined to a node. @@ -67,14 +69,22 @@ struct Request { } } - Request(State state = State::PENDING) : state_(state) {} + Request(State state = State::PENDING) : state_(state) { + REQ_COUNT++; + } Request(MessageType type, Tid tid, Sp node, Blob&& msg, std::function on_done, std::function on_expired, Tid socket = 0) : - node(node), tid(tid), type(type), on_done(on_done), on_expired(on_expired), msg(std::move(msg)), socket(socket) { } + node(node), tid(tid), type(type), on_done(on_done), on_expired(on_expired), msg(std::move(msg)), socket(socket) { + REQ_COUNT++; + } + + ~Request() { + REQ_COUNT--; + } Tid getTid() const { return tid; } MessageType getType() const { return type; } diff --git a/src/utils.cpp b/src/utils.cpp index 1ad5fedf..2047f557 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -34,6 +34,9 @@ #endif namespace dht { +namespace net { +std::atomic REQ_COUNT {0}; +} static constexpr std::array MAPPED_IPV4_PREFIX {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}};