dht: add inspection methods

This commit is contained in:
Adrien Béraud committed 2021-03-09 17:43:57 -05:00
1 parent 0b4caeda73
commit 2256434ec7
3 files changed
+38 -2

No files matched your search

+14 -2
View File
@@ -51,8 +51,8 @@ public:
}
bool onValue(const std::vector<Sp<Value>>& 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<Sp<Value>> get(const Value::Filter& filter) const;
Sp<Value> get(Value::Id id) const;
std::vector<Sp<Value>> 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<Sp<Value>> get(const Value::Filter& filter) const;
Sp<Value> get(Value::Id id) const;
std::pair<size_t, size_t> 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;
+20
View File
@@ -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
*/
+4
View File
@@ -142,6 +142,10 @@ public:
}
}
size_t size() const {
return values.size();
}
private:
// prevent copy
ValueCache(const ValueCache&) = delete;