diff --git a/src/op_cache.h b/src/op_cache.h index 51668157..b083e358 100644 --- a/src/op_cache.h +++ b/src/op_cache.h @@ -51,8 +51,8 @@ public: } bool onValue(const std::vector>& vals, bool expired, const system_clock::time_point& t = system_clock::time_point::min()) { - return expired - ? onValuesExpired(vals, t) + return expired + ? onValuesExpired(vals, t) : onValuesAdded(vals, t); } @@ -74,6 +74,7 @@ public: std::vector> get(const Value::Filter& filter) const; Sp get(Value::Id id) const; std::vector> getValues() const; + size_t size() const { return values.size(); } private: OpValueCache(const OpValueCache&) = delete; @@ -145,6 +146,10 @@ public: } time_point getExpiration() const; + size_t size() const { + return cache.size(); + } + size_t searchToken; private: constexpr static const std::chrono::seconds EXPIRATION {60}; @@ -176,6 +181,13 @@ public: std::vector> get(const Value::Filter& filter) const; Sp get(Value::Id id) const; + std::pair size() const { + size_t tot = 0; + for (const auto& c : ops) + tot += c.second->size(); + return {ops.size(), tot}; + } + private: SearchCache(const SearchCache&) = delete; SearchCache& operator=(const SearchCache&) = delete; diff --git a/src/search.h b/src/search.h index b7a5ffcb..3212bb2c 100644 --- a/src/search.h +++ b/src/search.h @@ -124,6 +124,14 @@ struct Dht::SearchNode { return last_get_reply + Node::NODE_EXPIRE_TIME; } + friend std::ostream& operator<< (std::ostream& s, const SearchNode& node) { + s << "getStatus:" << node.getStatus.size() + << " listenStatus:" << node.listenStatus.size() + << " acked:" << node.acked.size() + << " cache:" << (node.listenStatus.empty() ? 0 : node.listenStatus.begin()->second.cache.size()) << std::endl; + return s; + } + /** * Could a particular "get" request be sent to this node now ? * @@ -417,6 +425,18 @@ struct Dht::Search { } } + friend std::ostream& operator<< (std::ostream& s, const Search& sr) { + auto csize = sr.cache.size(); + s << "announce:" << sr.announce.size() + << " gets:" << sr.callbacks.size() + << " listeners:" << sr.listeners.size() + << " cache:" << csize.first << ',' << csize.second << std::endl; + s << "nodes:" << std::endl; + for (const auto& n : sr.nodes) + s << *n; + return s; + } + /** * @returns true if the node was not present and added to the search */ diff --git a/src/value_cache.h b/src/value_cache.h index b168ee6e..8870e081 100644 --- a/src/value_cache.h +++ b/src/value_cache.h @@ -142,6 +142,10 @@ public: } } + size_t size() const { + return values.size(); + } + private: // prevent copy ValueCache(const ValueCache&) = delete;