From 6cdc242b6e5c68729e6cb3bef31e969bc16c6ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 24 May 2016 03:11:28 -0400 Subject: [PATCH] node: add pendingMesageCount --- include/opendht/node.h | 4 +++- src/dht.cpp | 2 +- src/node.cpp | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/opendht/node.h b/include/opendht/node.h index e2b84bb4..acf1f502 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 54a4ccf4..f6a47c62 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 9beeca2e..74149dec 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) { -- GitLab