diff --git a/include/opendht/node.h b/include/opendht/node.h index e2b84bb4eb50f3fa9f7c6c1b1a15080aa811508a..acf1f502f45a4eb04243580e16754d7ec315ae0e 100644 --- a/include/opendht/node.h +++ b/include/opendht/node.h @@ -57,7 +57,9 @@ struct Node { } bool isExpired() const { return expired_; } bool isGood(time_point now) const; - bool isMessagePending() const; + bool isPendingMessage() const; + size_t getPendingMessageCount() const; + NodeExport exportNode() const { return NodeExport {id, ss, sslen}; } sa_family_t getFamily() const { return ss.ss_family; } diff --git a/src/dht.cpp b/src/dht.cpp index 54a4ccf4c89885e4ad5fbcbd7a0b5c221fd1fe7f..f6a47c628e92dd17470acfa396ff765a8c171771 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -503,7 +503,7 @@ Dht::newNode(const std::shared_ptr<Node>& node, int confirm) of bad nodes fast. */ if (not n->isGood(now)) { dubious = true; - if (not n->isMessagePending()) { + if (not n->isPendingMessage()) { DHT_LOG.DEBUG("Sending ping to dubious node %s.", n->toString().c_str()); network_engine.sendPing(n, nullptr, nullptr); break; diff --git a/src/node.cpp b/src/node.cpp index 9beeca2e4ff26f5423801b76ba496d4a17659825..74149decd63aed8d71b1cc63e0417e1c86c1183c 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -40,7 +40,7 @@ Node::isGood(time_point now) const } bool -Node::isMessagePending() const +Node::isPendingMessage() const { for (auto w : requests_) { if (auto r = w.lock()) { @@ -51,6 +51,19 @@ Node::isMessagePending() const return false; } +size_t +Node::getPendingMessageCount() const +{ + size_t count {0}; + for (auto w : requests_) { + if (auto r = w.lock()) { + if (r->pending()) + count++; + } + } + return count; +} + void Node::update(const sockaddr* sa, socklen_t salen) {