mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
log: add InfoHash filter
* filter log entries with new method setLogFilter * filter by node id, search or infohash * add optional parameter to 'log' in dhtnode
This commit is contained in:
1 parent
3af04a4259
commit
1d62b3ca64
12 files changed
+451
-302
No files matched your search
+138
-146
@@ -21,7 +21,6 @@
|
||||
#include "dht.h"
|
||||
#include "rng.h"
|
||||
#include "request.h"
|
||||
#include "log_enable.h"
|
||||
|
||||
#include <msgpack.hpp>
|
||||
extern "C" {
|
||||
@@ -715,9 +714,9 @@ struct Dht::Search {
|
||||
void
|
||||
Dht::setLoggers(LogMethod error, LogMethod warn, LogMethod debug)
|
||||
{
|
||||
DHT_LOG_DEBUG = debug;
|
||||
DHT_LOG_WARN = warn;
|
||||
DHT_LOG_ERR = error;
|
||||
DHT_LOG.DEBUG = debug;
|
||||
DHT_LOG.WARN = warn;
|
||||
DHT_LOG.ERR = error;
|
||||
}
|
||||
|
||||
NodeStatus
|
||||
@@ -743,7 +742,7 @@ Dht::shutdown(ShutdownCallback cb) {
|
||||
auto remaining = std::make_shared<int>(0);
|
||||
auto str_donecb = [=](bool, const std::vector<std::shared_ptr<Node>>&) {
|
||||
--*remaining;
|
||||
DHT_LOG_WARN("Shuting down node: %u ops remaining.", *remaining);
|
||||
DHT_LOG.w("shuting down node: %u ops remaining", *remaining);
|
||||
if (!*remaining && cb) { cb(); }
|
||||
};
|
||||
|
||||
@@ -752,7 +751,7 @@ Dht::shutdown(ShutdownCallback cb) {
|
||||
}
|
||||
|
||||
if (!*remaining) {
|
||||
DHT_LOG_WARN("Shuting down node: %u ops remaining.", *remaining);
|
||||
DHT_LOG.w("shuting down node: %u ops remaining", *remaining);
|
||||
if (cb)
|
||||
cb();
|
||||
}
|
||||
@@ -792,7 +791,7 @@ Dht::sendCachedPing(Bucket& b)
|
||||
if (!b.cached)
|
||||
return 0;
|
||||
|
||||
DHT_LOG_DEBUG("[node %s] Sending ping to cached node.", b.cached->toString().c_str());
|
||||
DHT_LOG.d(b.cached->id, "[node %s] sending ping to cached node", b.cached->toString().c_str());
|
||||
network_engine.sendPing(b.cached, nullptr, nullptr);
|
||||
b.cached = {};
|
||||
return 0;
|
||||
@@ -893,7 +892,7 @@ Dht::onNewNode(const std::shared_ptr<Node>& node, int confirm)
|
||||
if (not n->isGood(now)) {
|
||||
dubious = true;
|
||||
if (not n->isPendingMessage()) {
|
||||
DHT_LOG_DEBUG("[node %s] Sending ping to dubious node.", n->toString().c_str());
|
||||
DHT_LOG.d(n->id, "[node %s] sending ping to dubious node", n->toString().c_str());
|
||||
network_engine.sendPing(n, nullptr, nullptr);
|
||||
break;
|
||||
}
|
||||
@@ -901,7 +900,7 @@ Dht::onNewNode(const std::shared_ptr<Node>& node, int confirm)
|
||||
}
|
||||
|
||||
if ((mybucket || (is_bootstrap and list.depth(b) < 6)) && (!dubious || list.size() == 1)) {
|
||||
DHT_LOG_DEBUG("Splitting from depth %u", list.depth(b));
|
||||
DHT_LOG.d("Splitting from depth %u", list.depth(b));
|
||||
sendCachedPing(*b);
|
||||
list.split(b);
|
||||
onNewNode(node, 0);
|
||||
@@ -1046,7 +1045,7 @@ Dht::expireSearches()
|
||||
auto& sr = *srp.second;
|
||||
auto b = sr.callbacks.empty() && sr.announce.empty() && sr.listeners.empty() && sr.step_time < t;
|
||||
if (b) {
|
||||
DHT_LOG_DEBUG("Removing search %s", srp.first.toString().c_str());
|
||||
DHT_LOG.d(srp.first, "[search %s] removing search", srp.first.toString().c_str());
|
||||
sr.clear();
|
||||
return b;
|
||||
} else { return false; }
|
||||
@@ -1097,59 +1096,56 @@ Dht::searchNodeGetExpired(const Request& status,
|
||||
}
|
||||
|
||||
void Dht::paginate(std::weak_ptr<Search> ws, std::shared_ptr<Query> query, SearchNode* n) {
|
||||
if (auto sr = ws.lock()) {
|
||||
auto select_q = std::make_shared<Query>(Select {}.field(Value::Field::Id), query ? query->where : Where {});
|
||||
auto onSelectDone =
|
||||
[this,ws,query](const Request& status, NetworkEngine::RequestAnswer&& answer) mutable
|
||||
{
|
||||
if (auto sr = ws.lock()) {
|
||||
if (auto sn = sr->getNode(status.node)) {
|
||||
if (answer.fields.empty()) {
|
||||
searchNodeGetDone(status, std::move(answer), ws, query);
|
||||
return;
|
||||
} else {
|
||||
for (const auto& fvi : answer.fields) {
|
||||
try {
|
||||
auto vid = fvi->index.at(Value::Field::Id).getInt();
|
||||
if (vid == Value::INVALID_ID) continue;
|
||||
auto query_for_vid = std::make_shared<Query>(Select {}, Where {}.id(vid));
|
||||
sn->pagination_queries[query].push_back(query_for_vid);
|
||||
DHT_LOG_WARN("[search %s IPv%c] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6',
|
||||
sn->node->toString().c_str(), query_for_vid->toString().c_str());
|
||||
sn->getStatus[query_for_vid] = network_engine.sendGetValues(status.node,
|
||||
sr->id,
|
||||
*query_for_vid,
|
||||
-1,
|
||||
std::bind(&Dht::searchNodeGetDone, this, _1, _2, ws, query),
|
||||
std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, query_for_vid)
|
||||
);
|
||||
} catch (std::out_of_range&) {
|
||||
DHT_LOG_ERR("[search %s IPv%c] [node %s] received non-id field in response to "\
|
||||
"'SELECT id' request...",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6',
|
||||
sn->node->toString().c_str());
|
||||
}
|
||||
auto sr = ws.lock();
|
||||
if (not sr) return;
|
||||
auto select_q = std::make_shared<Query>(Select {}.field(Value::Field::Id), query ? query->where : Where {});
|
||||
auto onSelectDone =
|
||||
[this,ws,query](const Request& status, NetworkEngine::RequestAnswer&& answer) mutable
|
||||
{
|
||||
if (auto sr = ws.lock()) {
|
||||
if (auto sn = sr->getNode(status.node)) {
|
||||
if (answer.fields.empty()) {
|
||||
searchNodeGetDone(status, std::move(answer), ws, query);
|
||||
return;
|
||||
} else {
|
||||
for (const auto& fvi : answer.fields) {
|
||||
try {
|
||||
auto vid = fvi->index.at(Value::Field::Id).getInt();
|
||||
if (vid == Value::INVALID_ID) continue;
|
||||
auto query_for_vid = std::make_shared<Query>(Select {}, Where {}.id(vid));
|
||||
sn->pagination_queries[query].push_back(query_for_vid);
|
||||
DHT_LOG.w(sr->id, sn->node->id, "[search %s] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), sn->node->toString().c_str(), query_for_vid->toString().c_str());
|
||||
sn->getStatus[query_for_vid] = network_engine.sendGetValues(status.node,
|
||||
sr->id,
|
||||
*query_for_vid,
|
||||
-1,
|
||||
std::bind(&Dht::searchNodeGetDone, this, _1, _2, ws, query),
|
||||
std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, query_for_vid)
|
||||
);
|
||||
} catch (std::out_of_range&) {
|
||||
DHT_LOG.e(sr->id, sn->node->id, "[search %s] [node %s] received non-id field in response to "\
|
||||
"'SELECT id' request...",
|
||||
sr->id.toString().c_str(), sn->node->toString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
/* add pagination query key for tracking ongoing requests. */
|
||||
n->pagination_queries[query].push_back(select_q);
|
||||
|
||||
DHT_LOG_WARN("[search %s IPv%c] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6',
|
||||
n->node->toString().c_str(), select_q->toString().c_str());
|
||||
n->getStatus[select_q] = network_engine.sendGetValues(n->node,
|
||||
sr->id,
|
||||
*select_q,
|
||||
-1,
|
||||
onSelectDone,
|
||||
std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, select_q)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
/* add pagination query key for tracking ongoing requests. */
|
||||
n->pagination_queries[query].push_back(select_q);
|
||||
|
||||
DHT_LOG.w(sr->id, n->node->id, "[search %s] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), n->node->toString().c_str(), select_q->toString().c_str());
|
||||
n->getStatus[select_q] = network_engine.sendGetValues(n->node,
|
||||
sr->id,
|
||||
*select_q,
|
||||
-1,
|
||||
onSelectDone,
|
||||
std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, select_q)
|
||||
);
|
||||
}
|
||||
|
||||
Dht::SearchNode*
|
||||
@@ -1184,7 +1180,7 @@ Dht::searchSendGetValues(std::shared_ptr<Search> sr, SearchNode* pn, bool update
|
||||
if (not n)
|
||||
return nullptr;
|
||||
|
||||
DHT_LOG_WARN("[search %s] [node %s] sending 'find_node'",
|
||||
DHT_LOG.w(sr->id, n->node->id, "[search %s] [node %s] sending 'find_node'",
|
||||
sr->id.toString().c_str(), n->node->toString().c_str());
|
||||
n->getStatus[query] = network_engine.sendFindNode(n->node,
|
||||
sr->id,
|
||||
@@ -1198,7 +1194,7 @@ Dht::searchSendGetValues(std::shared_ptr<Search> sr, SearchNode* pn, bool update
|
||||
|
||||
if (query and not query->select.getSelection().empty()) {
|
||||
/* The request contains a select. No need to paginate... */
|
||||
DHT_LOG_WARN("[search %s] [node %s] sending 'get'",
|
||||
DHT_LOG.w(sr->id, n->node->id, "[search %s] [node %s] sending 'get'",
|
||||
sr->id.toString().c_str(), n->node->toString().c_str());
|
||||
n->getStatus[query] = network_engine.sendGetValues(n->node,
|
||||
sr->id,
|
||||
@@ -1272,7 +1268,7 @@ void Dht::searchSendAnnounceValue(const std::shared_ptr<Search>& sr) {
|
||||
auto next_refresh_time = now + getType(a.value->type).expiration;
|
||||
/* only put the value if the node doesn't already have it */
|
||||
if (not hasValue or seq_no < a.value->seq) {
|
||||
DHT_LOG_WARN("[search %s] [node %s] sending 'put' (vid: %d)",
|
||||
DHT_LOG.w(sr->id, sn->node->id, "[search %s] [node %s] sending 'put' (vid: %d)",
|
||||
sr->id.toString().c_str(), sn->node->toString().c_str(), a.value->id);
|
||||
sn->acked[a.value->id] = std::make_pair(network_engine.sendAnnounceValue(sn->node,
|
||||
sr->id,
|
||||
@@ -1282,7 +1278,7 @@ void Dht::searchSendAnnounceValue(const std::shared_ptr<Search>& sr) {
|
||||
onDone,
|
||||
onExpired), next_refresh_time);
|
||||
} else if (hasValue and a.permanent) {
|
||||
DHT_LOG_WARN("[search %s] [node %s] sending 'refresh' (vid: %d)",
|
||||
DHT_LOG.w(sr->id, sn->node->id, "[search %s] [node %s] sending 'refresh' (vid: %d)",
|
||||
sr->id.toString().c_str(), sn->node->toString().c_str(), a.value->id);
|
||||
sn->acked[a.value->id] = std::make_pair(network_engine.sendRefreshValue(sn->node,
|
||||
sr->id,
|
||||
@@ -1291,7 +1287,7 @@ void Dht::searchSendAnnounceValue(const std::shared_ptr<Search>& sr) {
|
||||
onDone,
|
||||
onExpired), next_refresh_time);
|
||||
} else {
|
||||
DHT_LOG.WARN("[search %s] [node %s] already has value (vid: %d). Aborting.",
|
||||
DHT_LOG.w(sr->id, sn->node->id, "[search %s] [node %s] already has value (vid: %d). Aborting.",
|
||||
sr->id.toString().c_str(), sn->node->toString().c_str(), a.value->id);
|
||||
auto ack_req = std::make_shared<Request>();
|
||||
ack_req->reply_time = now;
|
||||
@@ -1309,9 +1305,8 @@ void Dht::searchSendAnnounceValue(const std::shared_ptr<Search>& sr) {
|
||||
}
|
||||
}
|
||||
};
|
||||
DHT_LOG_WARN("[search %s IPv%c] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6',
|
||||
n.node->toString().c_str(), probe_query->toString().c_str());
|
||||
DHT_LOG.w(sr->id, n.node->id, "[search %s] [node %s] sending %s",
|
||||
sr->id.toString().c_str(), n.node->toString().c_str(), probe_query->toString().c_str());
|
||||
n.probe_query = probe_query;
|
||||
n.getStatus[probe_query] = network_engine.sendGetValues(n.node,
|
||||
sr->id,
|
||||
@@ -1333,7 +1328,7 @@ Dht::searchStep(std::shared_ptr<Search> sr)
|
||||
|
||||
const auto& now = scheduler.time();
|
||||
if (auto req_count = sr->currentlySolicitedNodeCount())
|
||||
DHT_LOG_DEBUG("[search %s IPv%c] step (%d requests)",
|
||||
DHT_LOG.d(sr->id, "[search %s IPv%c] step (%d requests)",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6', req_count);
|
||||
sr->step_time = now;
|
||||
|
||||
@@ -1375,7 +1370,7 @@ Dht::searchStep(std::shared_ptr<Search> sr)
|
||||
for (const auto& l : sr->listeners) {
|
||||
const auto& query = l.second.query;
|
||||
if (n.getListenTime(query) <= now) {
|
||||
DHT_LOG_WARN("[search %s] [node %s] sending 'listen'",
|
||||
DHT_LOG.w(sr->id, n.node->id, "[search %s] [node %s] sending 'listen'",
|
||||
sr->id.toString().c_str(), n.node->toString().c_str());
|
||||
|
||||
const auto& r = n.listenStatus.find(query);
|
||||
@@ -1432,7 +1427,7 @@ Dht::searchStep(std::shared_ptr<Search> sr)
|
||||
if (sr->getNumberOfConsecutiveBadNodes() >= std::min(sr->nodes.size(),
|
||||
static_cast<size_t>(SEARCH_MAX_BAD_NODES)))
|
||||
{
|
||||
DHT_LOG_WARN("[search %s IPv%c] expired", sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6');
|
||||
DHT_LOG.w(sr->id, "[search %s IPv%c] expired", sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6');
|
||||
sr->expire();
|
||||
connectivityChanged(sr->af);
|
||||
}
|
||||
@@ -1631,7 +1626,7 @@ unsigned Dht::refill(Dht::Search& sr) {
|
||||
auto cached_nodes = network_engine.getCachedNodes(sr.id, sr.af, SEARCH_NODES);
|
||||
|
||||
if (cached_nodes.empty()) {
|
||||
DHT_LOG_ERR("[search %s IPv%c] no nodes from cache while refilling search",
|
||||
DHT_LOG.e(sr.id, "[search %s IPv%c] no nodes from cache while refilling search",
|
||||
sr.id.toString().c_str(), (sr.af == AF_INET) ? '4' : '6');
|
||||
return 0;
|
||||
}
|
||||
@@ -1642,7 +1637,7 @@ unsigned Dht::refill(Dht::Search& sr) {
|
||||
if (sr.insertNode(i, now))
|
||||
++inserted;
|
||||
}
|
||||
DHT_LOG_DEBUG("[search %s IPv%c] refilled search with %u nodes from node cache",
|
||||
DHT_LOG.d(sr.id, "[search %s IPv%c] refilled search with %u nodes from node cache",
|
||||
sr.id.toString().c_str(), (sr.af == AF_INET) ? '4' : '6', inserted);
|
||||
sr.refill_time = now;
|
||||
return inserted;
|
||||
@@ -1654,7 +1649,7 @@ std::shared_ptr<Dht::Search>
|
||||
Dht::search(const InfoHash& id, sa_family_t af, GetCallback gcb, QueryCallback qcb, DoneCallback dcb, Value::Filter f, Query q)
|
||||
{
|
||||
if (!isRunning(af)) {
|
||||
DHT_LOG_ERR("[search %s IPv%c] unsupported protocol", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
DHT_LOG.e(id, "[search %s IPv%c] unsupported protocol", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
if (dcb)
|
||||
dcb(false, {});
|
||||
return {};
|
||||
@@ -1691,7 +1686,7 @@ Dht::search(const InfoHash& id, sa_family_t af, GetCallback gcb, QueryCallback q
|
||||
sr->expired = false;
|
||||
sr->nodes.clear();
|
||||
sr->nodes.reserve(SEARCH_NODES+1);
|
||||
DHT_LOG_WARN("[search %s IPv%c] new search", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
DHT_LOG.w(id, "[search %s IPv%c] new search", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
if (search_id == 0)
|
||||
search_id++;
|
||||
}
|
||||
@@ -1791,7 +1786,7 @@ Dht::listenTo(const InfoHash& id, sa_family_t af, GetCallback cb, Value::Filter
|
||||
std::shared_ptr<Search> sr = (srp == srs.end()) ? search(id, af) : srp->second;
|
||||
if (!sr)
|
||||
throw DhtException("Can't create search");
|
||||
DHT_LOG_ERR("[search %s IPv%c] listen", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
DHT_LOG.e(id, "[search %s IPv%c] listen", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
|
||||
sr->done = false;
|
||||
auto token = ++sr->listener_token;
|
||||
sr->listeners.emplace(token, LocalListener{q, f, cb});
|
||||
@@ -1855,7 +1850,7 @@ Dht::listen(const InfoHash& id, GetCallback cb, Value::Filter&& f, Where&& where
|
||||
auto token4 = Dht::listenTo(id, AF_INET, gcb, filter, query);
|
||||
auto token6 = Dht::listenTo(id, AF_INET6, gcb, filter, query);
|
||||
|
||||
DHT_LOG_DEBUG("Added listen : %d -> %d %d %d", token, tokenlocal, token4, token6);
|
||||
DHT_LOG.d(id, "Added listen : %d -> %d %d %d", token, tokenlocal, token4, token6);
|
||||
listeners.emplace(token, std::make_tuple(tokenlocal, token4, token6));
|
||||
return token;
|
||||
}
|
||||
@@ -1867,10 +1862,10 @@ Dht::cancelListen(const InfoHash& id, size_t token)
|
||||
|
||||
auto it = listeners.find(token);
|
||||
if (it == listeners.end()) {
|
||||
DHT_LOG_WARN("Listen token not found: %d", token);
|
||||
DHT_LOG.w(id, "Listen token not found: %d", token);
|
||||
return false;
|
||||
}
|
||||
DHT_LOG_DEBUG("cancelListen %s with token %d", id.toString().c_str(), token);
|
||||
DHT_LOG.d(id, "cancelListen %s with token %d", id.toString().c_str(), token);
|
||||
auto st = store.find(id);
|
||||
auto tokenlocal = std::get<0>(it->second);
|
||||
if (st != store.end() && tokenlocal)
|
||||
@@ -1920,7 +1915,7 @@ Dht::put(const InfoHash& id, std::shared_ptr<Value> val, DoneCallback callback,
|
||||
val->id = rand_id(rdev);
|
||||
}
|
||||
|
||||
DHT_LOG_DEBUG("put: adding %s -> %s", id.toString().c_str(), val->toString().c_str());
|
||||
DHT_LOG.d(id, "put: adding %s -> %s", id.toString().c_str(), val->toString().c_str());
|
||||
|
||||
auto ok = std::make_shared<bool>(false);
|
||||
auto done = std::make_shared<bool>(false);
|
||||
@@ -1934,13 +1929,13 @@ Dht::put(const InfoHash& id, std::shared_ptr<Value> val, DoneCallback callback,
|
||||
}
|
||||
};
|
||||
announce(id, AF_INET, val, [=](bool ok4, const std::vector<std::shared_ptr<Node>>& nodes) {
|
||||
DHT_LOG_DEBUG("Announce done IPv4 %d", ok4);
|
||||
DHT_LOG.d(id, "Announce done IPv4 %d", ok4);
|
||||
*done4 = true;
|
||||
*ok |= ok4;
|
||||
donecb(nodes);
|
||||
}, created, permanent);
|
||||
announce(id, AF_INET6, val, [=](bool ok6, const std::vector<std::shared_ptr<Node>>& nodes) {
|
||||
DHT_LOG_DEBUG("Announce done IPv6 %d", ok6);
|
||||
DHT_LOG.d(id, "Announce done IPv6 %d", ok6);
|
||||
*done6 = true;
|
||||
*ok |= ok6;
|
||||
donecb(nodes);
|
||||
@@ -2167,16 +2162,16 @@ Dht::cancelPut(const InfoHash& id, const Value::Id& vid)
|
||||
void
|
||||
Dht::storageChanged(const InfoHash& id, Storage& st, ValueStorage& v)
|
||||
{
|
||||
DHT_LOG_DEBUG("[Storage %s] changed.", id.toString().c_str());
|
||||
DHT_LOG.d(id, "[store %s] changed", id.toString().c_str());
|
||||
if (not st.local_listeners.empty()) {
|
||||
DHT_LOG_DEBUG("[Storage %s] %lu local listeners.", id.toString().c_str(), st.local_listeners.size());
|
||||
DHT_LOG.d(id, "[store %s] %lu local listeners", id.toString().c_str(), st.local_listeners.size());
|
||||
std::vector<std::pair<GetCallback, std::vector<std::shared_ptr<Value>>>> cbs;
|
||||
for (const auto& l : st.local_listeners) {
|
||||
std::vector<std::shared_ptr<Value>> vals;
|
||||
if (not l.second.filter or l.second.filter(*v.data))
|
||||
vals.push_back(v.data);
|
||||
if (not vals.empty()) {
|
||||
DHT_LOG_DEBUG("[Storage %s] Sending update local listener with token %lu.",
|
||||
DHT_LOG.d(id, "[store %s] sending update local listener with token %lu",
|
||||
id.toString().c_str(),
|
||||
l.first);
|
||||
cbs.emplace_back(l.second.get_cb, std::move(vals));
|
||||
@@ -2187,12 +2182,12 @@ Dht::storageChanged(const InfoHash& id, Storage& st, ValueStorage& v)
|
||||
cb.first(cb.second);
|
||||
}
|
||||
|
||||
DHT_LOG_DEBUG("[Storage %s] %lu remote listeners.", id.toString().c_str(), st.listeners.size());
|
||||
DHT_LOG.d(id, "[store %s] %lu remote listeners", id.toString().c_str(), st.listeners.size());
|
||||
for (const auto& l : st.listeners) {
|
||||
auto f = l.second.query.where.getFilter();
|
||||
if (f and not f(*v.data))
|
||||
continue;
|
||||
DHT_LOG_DEBUG("[Storage %s] Sending update to %s.", id.toString().c_str(), l.first->toString().c_str());
|
||||
DHT_LOG.w(id, l.first->id, "[store %s] [node %s] sending update", id.toString().c_str(), l.first->toString().c_str());
|
||||
std::vector<std::shared_ptr<Value>> vals {};
|
||||
vals.push_back(v.data);
|
||||
Blob ntoken = makeToken((const sockaddr*)&l.first->addr.first, false);
|
||||
@@ -2210,7 +2205,7 @@ Dht::storageStore(const InfoHash& id, const std::shared_ptr<Value>& value, time_
|
||||
auto expiration = created + getType(value->type).expiration;
|
||||
if (expiration < now) {
|
||||
using namespace std::chrono;
|
||||
DHT_LOG_WARN("[store %s] won't store already expired value (created %lld s ago, expired %lld s ago)",
|
||||
DHT_LOG.w(id, "[store %s] won't store already expired value (created %lld s ago, expired %lld s ago)",
|
||||
id.toString().c_str(), duration_cast<seconds>(now - created).count(),
|
||||
duration_cast<seconds>(now - expiration).count());
|
||||
return false;
|
||||
@@ -2310,7 +2305,7 @@ Dht::expireStorage()
|
||||
for (auto l = i->second.listeners.cbegin(); l != i->second.listeners.cend();){
|
||||
bool expired = l->second.time + Node::NODE_EXPIRE_TIME < now;
|
||||
if (expired) {
|
||||
DHT_LOG_DEBUG("Discarding expired listener %s", l->first->id.toString().c_str());
|
||||
DHT_LOG.d(i->first, l->first->id, "[store %s] [node %s] discarding expired listener", i->first.toString().c_str(), l->first->toString().c_str());
|
||||
i->second.listeners.erase(l++);
|
||||
} else
|
||||
++l;
|
||||
@@ -2321,7 +2316,7 @@ Dht::expireStorage()
|
||||
total_values += stats.second;
|
||||
|
||||
if (i->second.empty() && i->second.listeners.empty() && i->second.local_listeners.empty()) {
|
||||
DHT_LOG_DEBUG("Discarding expired value %s", i->first.toString().c_str());
|
||||
DHT_LOG.d(i->first, "[store %s] discarding empty storage", i->first.toString().c_str());
|
||||
i = store.erase(i);
|
||||
}
|
||||
else
|
||||
@@ -2602,7 +2597,7 @@ Dht::dumpTables() const
|
||||
|
||||
out << getStorageLog() << std::endl;
|
||||
|
||||
DHT_LOG_DEBUG("%s", out.str().c_str());
|
||||
DHT_LOG.d("%s", out.str().c_str());
|
||||
}
|
||||
|
||||
std::string
|
||||
@@ -2625,7 +2620,7 @@ Dht::getStorageLog() const
|
||||
out << " (since " << since.count() << "s, exp in " << expires.count() << "s)" << std::endl;
|
||||
}
|
||||
}
|
||||
out << "Total " << store.size() << " storages, " << total_values << " values (" << (total_store_size/1024) << " ĶB)" << std::endl;
|
||||
out << "Total " << store.size() << " storages, " << total_values << " values (" << (total_store_size/1024) << " KB)" << std::endl;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
@@ -2695,7 +2690,7 @@ Dht::Dht(int s, int s6, Config config)
|
||||
|
||||
uniform_duration_distribution<> time_dis {std::chrono::seconds(3), std::chrono::seconds(5)};
|
||||
auto confirm_nodes_time = scheduler.time() + time_dis(rd);
|
||||
DHT_LOG_DEBUG("Scheduling %s", myid.toString().c_str());
|
||||
DHT_LOG.d(myid, "Scheduling %s", myid.toString().c_str());
|
||||
nextNodesConfirmation = scheduler.add(confirm_nodes_time, std::bind(&Dht::confirmNodes, this));
|
||||
|
||||
// Fill old secret
|
||||
@@ -2707,7 +2702,7 @@ Dht::Dht(int s, int s6, Config config)
|
||||
|
||||
expire();
|
||||
|
||||
DHT_LOG_DEBUG("DHT initialised with node ID %s", myid.toString().c_str());
|
||||
DHT_LOG.d("DHT initialised with node ID %s", myid.toString().c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -2734,7 +2729,7 @@ Dht::neighbourhoodMaintenance(RoutingTable& list)
|
||||
|
||||
auto n = q->randomNode();
|
||||
if (n) {
|
||||
DHT_LOG_DEBUG("[node %s] sending [find %s] for neighborhood maintenance.",
|
||||
DHT_LOG.d(id, n->id, "[node %s] sending [find %s] for neighborhood maintenance",
|
||||
n->toString().c_str(), id.toString().c_str());
|
||||
/* Since our node-id is the same in both DHTs, it's probably
|
||||
profitable to query both families. */
|
||||
@@ -2786,12 +2781,13 @@ Dht::bucketMaintenance(RoutingTable& list)
|
||||
want = WANT4 | WANT6;
|
||||
}
|
||||
|
||||
DHT_LOG_DEBUG("[node %s] sending find %s for bucket maintenance.", n->toString().c_str(), id.toString().c_str());
|
||||
DHT_LOG.d(id, n->id, "[node %s] sending find %s for bucket maintenance", n->toString().c_str(), id.toString().c_str());
|
||||
auto start = scheduler.time();
|
||||
network_engine.sendFindNode(n, id, want, nullptr, [this,start,n](const Request&, bool over) {
|
||||
if (over) {
|
||||
auto end = scheduler.time();
|
||||
DHT_LOG_DEBUG("[node %s] bucket maintenance op expired after %llu", n->toString().c_str(), std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count());
|
||||
const auto& end = scheduler.time();
|
||||
using namespace std::chrono;
|
||||
DHT_LOG.d(n->id, "[node %s] bucket maintenance op expired after %llu ms", n->toString().c_str(), duration_cast<milliseconds>(end-start).count());
|
||||
scheduler.edit(nextNodesConfirmation, end + 3 * Node::NODE_EXPIRE_TIME);
|
||||
}
|
||||
});
|
||||
@@ -2810,14 +2806,14 @@ Dht::dataPersistence() {
|
||||
auto storage_maintenance_time = time_point::max();
|
||||
for (auto &str : store) {
|
||||
if (now > str.second.maintenance_time) {
|
||||
DHT_LOG_WARN("[storage %s] maintenance (%u values, %u bytes)",
|
||||
DHT_LOG.w(str.first, "[storage %s] maintenance (%u values, %u bytes)",
|
||||
str.first.toString().c_str(), str.second.valueCount(), str.second.totalSize());
|
||||
maintainStorage(str.first);
|
||||
str.second.maintenance_time = now + MAX_STORAGE_MAINTENANCE_EXPIRE_TIME;
|
||||
}
|
||||
storage_maintenance_time = std::min(storage_maintenance_time, str.second.maintenance_time);
|
||||
}
|
||||
DHT_LOG_WARN("[store] next maintenance in %u minutes",
|
||||
DHT_LOG.w("[store] next maintenance in %u minutes",
|
||||
std::chrono::duration_cast<std::chrono::minutes>(storage_maintenance_time-now));
|
||||
nextStorageMaintenance = storage_maintenance_time != time_point::max() ?
|
||||
scheduler.add(storage_maintenance_time, std::bind(&Dht::dataPersistence, this)) :
|
||||
@@ -2864,7 +2860,7 @@ Dht::maintainStorage(InfoHash id, bool force, DoneCallback donecb) {
|
||||
}
|
||||
|
||||
if (not want4 and not want6) {
|
||||
DHT_LOG_DEBUG("Discarding storage values %s", id.toString().c_str());
|
||||
DHT_LOG.d(id, "Discarding storage values %s", id.toString().c_str());
|
||||
auto diff = local_storage->second.clear();
|
||||
total_store_size += diff.first;
|
||||
total_values += diff.second;
|
||||
@@ -2882,7 +2878,7 @@ Dht::processMessage(const uint8_t *buf, size_t buflen, const SockAddr& from)
|
||||
try {
|
||||
network_engine.processMessage(buf, buflen, from);
|
||||
} catch (const std::exception& e) {
|
||||
DHT_LOG_ERR("Can't parse message from %s: %s", from.toString().c_str(), e.what());
|
||||
DHT_LOG.e("Can't parse message from %s: %s", from.toString().c_str(), e.what());
|
||||
//auto code = e.getCode();
|
||||
//if (code == DhtProtocolException::INVALID_TID_SIZE or code == DhtProtocolException::WRONG_NODE_INFO_BUF_LEN) {
|
||||
/* This is really annoying, as it means that we will
|
||||
@@ -2923,11 +2919,11 @@ Dht::confirmNodes()
|
||||
const auto& now = scheduler.time();
|
||||
|
||||
if (searches4.empty() and getStatus(AF_INET) == NodeStatus::Connected) {
|
||||
DHT_LOG_DEBUG("[confirm nodes] initial IPv4 'get' for my id (%s).", myid.toString().c_str());
|
||||
DHT_LOG.d(myid, "[confirm nodes] initial IPv4 'get' for my id (%s)", myid.toString().c_str());
|
||||
search(myid, AF_INET);
|
||||
}
|
||||
if (searches6.empty() and getStatus(AF_INET6) == NodeStatus::Connected) {
|
||||
DHT_LOG_DEBUG("[confirm nodes] initial IPv6 'get' for my id (%s).", myid.toString().c_str());
|
||||
DHT_LOG.d(myid, "[confirm nodes] initial IPv6 'get' for my id (%s)", myid.toString().c_str());
|
||||
search(myid, AF_INET6);
|
||||
}
|
||||
|
||||
@@ -3003,17 +2999,17 @@ Dht::importValues(const std::vector<ValuesExport>& import)
|
||||
val_time = time_point{time_point::duration{valel.via.array.ptr[0].as<time_point::duration::rep>()}};
|
||||
tmp_val.msgpack_unpack(valel.via.array.ptr[1]);
|
||||
} catch (const std::exception&) {
|
||||
DHT_LOG_ERR("Error reading value at %s", h.first.toString().c_str());
|
||||
DHT_LOG.e(h.first, "Error reading value at %s", h.first.toString().c_str());
|
||||
continue;
|
||||
}
|
||||
if (val_time + getType(tmp_val.type).expiration < scheduler.time()) {
|
||||
DHT_LOG_DEBUG("Discarding expired value at %s", h.first.toString().c_str());
|
||||
DHT_LOG.d(h.first, "Discarding expired value at %s", h.first.toString().c_str());
|
||||
continue;
|
||||
}
|
||||
storageStore(h.first, std::make_shared<Value>(std::move(tmp_val)), val_time);
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
DHT_LOG_ERR("Error reading values at %s", h.first.toString().c_str());
|
||||
DHT_LOG.e(h.first, "Error reading values at %s", h.first.toString().c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -3065,7 +3061,7 @@ void
|
||||
Dht::pingNode(const sockaddr* sa, socklen_t salen, DoneCallbackSimple&& cb)
|
||||
{
|
||||
scheduler.syncTime();
|
||||
DHT_LOG_DEBUG("Sending ping to %s", print_addr(sa, salen).c_str());
|
||||
DHT_LOG.d("Sending ping to %s", print_addr(sa, salen).c_str());
|
||||
auto& count = sa->sa_family == AF_INET ? pending_pings4 : pending_pings6;
|
||||
count++;
|
||||
network_engine.sendPing(sa, salen, [&count,cb](const Request&, NetworkEngine::RequestAnswer&&) {
|
||||
@@ -3084,7 +3080,7 @@ Dht::pingNode(const sockaddr* sa, socklen_t salen, DoneCallbackSimple&& cb)
|
||||
void
|
||||
Dht::onError(std::shared_ptr<Request> req, DhtProtocolException e) {
|
||||
if (e.getCode() == DhtProtocolException::UNAUTHORIZED) {
|
||||
DHT_LOG_ERR("[node %s] token flush", req->node->toString().c_str());
|
||||
DHT_LOG.e(req->node->id, "[node %s] token flush", req->node->toString().c_str());
|
||||
req->node->authError();
|
||||
network_engine.cancelRequest(req);
|
||||
for (auto& srp : req->node->getFamily() == AF_INET ? searches4 : searches6) {
|
||||
@@ -3098,7 +3094,7 @@ Dht::onError(std::shared_ptr<Request> req, DhtProtocolException e) {
|
||||
}
|
||||
}
|
||||
} else if (e.getCode() == DhtProtocolException::NOT_FOUND) {
|
||||
DHT_LOG.ERR("[node %s] returned error 404: storage not found", req->node->id.toString().c_str());
|
||||
DHT_LOG.e(req->node->id, "[node %s] returned error 404: storage not found", req->node->toString().c_str());
|
||||
network_engine.cancelRequest(req);
|
||||
}
|
||||
}
|
||||
@@ -3135,7 +3131,7 @@ NetworkEngine::RequestAnswer
|
||||
Dht::onGetValues(std::shared_ptr<Node> node, const InfoHash& hash, want_t, const Query& query)
|
||||
{
|
||||
if (hash == zeroes) {
|
||||
DHT_LOG_WARN("[node %s] Eek! Got get_values with no info_hash.", node->toString().c_str());
|
||||
DHT_LOG.w("[node %s] Eek! Got get_values with no info_hash", node->toString().c_str());
|
||||
throw DhtProtocolException {
|
||||
DhtProtocolException::NON_AUTHORITATIVE_INFORMATION,
|
||||
DhtProtocolException::GET_NO_INFOHASH
|
||||
@@ -3149,9 +3145,9 @@ Dht::onGetValues(std::shared_ptr<Node> node, const InfoHash& hash, want_t, const
|
||||
answer.nodes6 = buckets6.findClosestNodes(hash, now, TARGET_NODES);
|
||||
if (st != store.end() && not st->second.empty()) {
|
||||
answer.values = st->second.get(query.where.getFilter());
|
||||
DHT_LOG_DEBUG("[node %s] sending %u values.", node->toString().c_str(), answer.values.size());
|
||||
DHT_LOG.d(hash, "[node %s] sending %u values", node->toString().c_str(), answer.values.size());
|
||||
} else {
|
||||
DHT_LOG_DEBUG("[node %s] sending nodes.", node->toString().c_str());
|
||||
DHT_LOG.d(hash, "[node %s] sending nodes", node->toString().c_str());
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
@@ -3162,16 +3158,16 @@ void Dht::onGetValuesDone(const Request& status,
|
||||
const std::shared_ptr<Query>& orig_query)
|
||||
{
|
||||
if (not sr) {
|
||||
DHT_LOG_WARN("[search unknown] got reply to 'get'. Ignoring.");
|
||||
DHT_LOG.w("[search unknown] got reply to 'get'. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
DHT_LOG_DEBUG("[search %s] [node %s] got reply to 'get' with %u nodes",
|
||||
DHT_LOG.d(sr->id, "[search %s] [node %s] got reply to 'get' with %u nodes",
|
||||
sr->id.toString().c_str(), status.node->toString().c_str(), a.nodes4.size());
|
||||
|
||||
if (not a.ntoken.empty()) {
|
||||
if (not a.values.empty() or not a.fields.empty()) {
|
||||
DHT_LOG_DEBUG("[search %s IPv%c] found %u values",
|
||||
DHT_LOG.d(sr->id, "[search %s IPv%c] found %u values",
|
||||
sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6',
|
||||
a.values.size());
|
||||
for (auto& getp : sr->callbacks) { /* call all callbacks for this search */
|
||||
@@ -3216,7 +3212,7 @@ void Dht::onGetValuesDone(const Request& status,
|
||||
l.first(l.second);
|
||||
}
|
||||
} else {
|
||||
DHT_LOG_WARN("[node %s] no token provided. Ignoring response content.", status.node->toString().c_str());
|
||||
DHT_LOG.w(sr->id, "[node %s] no token provided. Ignoring response content.", status.node->toString().c_str());
|
||||
network_engine.blacklistNode(status.node);
|
||||
}
|
||||
|
||||
@@ -3232,14 +3228,14 @@ NetworkEngine::RequestAnswer
|
||||
Dht::onListen(std::shared_ptr<Node> node, const InfoHash& hash, const Blob& token, size_t rid, const Query& query)
|
||||
{
|
||||
if (hash == zeroes) {
|
||||
DHT_LOG_WARN("[node %s] Listen with no info_hash.", node->toString().c_str());
|
||||
DHT_LOG.w(node->id, "[node %s] listen with no info_hash", node->toString().c_str());
|
||||
throw DhtProtocolException {
|
||||
DhtProtocolException::NON_AUTHORITATIVE_INFORMATION,
|
||||
DhtProtocolException::LISTEN_NO_INFOHASH
|
||||
};
|
||||
}
|
||||
if (!tokenMatch(token, (sockaddr*)&node->addr.first)) {
|
||||
DHT_LOG_WARN("[node %s] incorrect token %s for 'listen'.", node->toString().c_str(), hash.toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[node %s] incorrect token %s for 'listen'", node->toString().c_str(), hash.toString().c_str());
|
||||
throw DhtProtocolException {DhtProtocolException::UNAUTHORIZED, DhtProtocolException::LISTEN_WRONG_TOKEN};
|
||||
}
|
||||
Query q = query;
|
||||
@@ -3253,20 +3249,17 @@ Dht::onListenDone(const Request& status,
|
||||
std::shared_ptr<Search>& sr,
|
||||
const std::shared_ptr<Query>& orig_query)
|
||||
{
|
||||
DHT_LOG_DEBUG("[search %s] [node %s] Got reply to listen.", sr->id.toString().c_str(), status.node->toString().c_str());
|
||||
if (sr) {
|
||||
if (not answer.values.empty()) { /* got new values from listen request */
|
||||
DHT_LOG_DEBUG("[listen %s] Got new values.", sr->id.toString().c_str());
|
||||
onGetValuesDone(status, answer, sr, orig_query);
|
||||
}
|
||||
DHT_LOG.d(sr->id, status.node->id, "[search %s] [node %s] got reply to listen (%llu values)",
|
||||
sr->id.toString().c_str(), status.node->toString().c_str(), answer.values.size());
|
||||
if (not answer.values.empty()) { /* got new values from listen request */
|
||||
onGetValuesDone(status, answer, sr, orig_query);
|
||||
}
|
||||
|
||||
if (not sr->done) {
|
||||
const auto& now = scheduler.time();
|
||||
searchSendGetValues(sr);
|
||||
scheduler.edit(sr->nextSearchStep, sr->getNextStepTime(now));
|
||||
}
|
||||
} else
|
||||
DHT_LOG_DEBUG("Unknown search or announce!");
|
||||
if (not sr->done) {
|
||||
const auto& now = scheduler.time();
|
||||
searchSendGetValues(sr);
|
||||
scheduler.edit(sr->nextSearchStep, sr->getNextStepTime(now));
|
||||
}
|
||||
}
|
||||
|
||||
NetworkEngine::RequestAnswer
|
||||
@@ -3277,14 +3270,14 @@ Dht::onAnnounce(std::shared_ptr<Node> node,
|
||||
const time_point& created)
|
||||
{
|
||||
if (hash == zeroes) {
|
||||
DHT_LOG_WARN("Put with no info_hash.");
|
||||
DHT_LOG.w(node->id, "put with no info_hash");
|
||||
throw DhtProtocolException {
|
||||
DhtProtocolException::NON_AUTHORITATIVE_INFORMATION,
|
||||
DhtProtocolException::PUT_NO_INFOHASH
|
||||
};
|
||||
}
|
||||
if (!tokenMatch(token, (sockaddr*)&node->addr.first)) {
|
||||
DHT_LOG_WARN("[node %s] incorrect token %s for 'put'.", node->toString().c_str(), hash.toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[node %s] incorrect token %s for 'put'", node->toString().c_str(), hash.toString().c_str());
|
||||
throw DhtProtocolException {DhtProtocolException::UNAUTHORIZED, DhtProtocolException::PUT_WRONG_TOKEN};
|
||||
}
|
||||
{
|
||||
@@ -3292,14 +3285,14 @@ Dht::onAnnounce(std::shared_ptr<Node> node,
|
||||
// SEARCH_NODES nodes around the target id.
|
||||
auto closest_nodes = buckets(node->getFamily()).findClosestNodes(hash, scheduler.time(), SEARCH_NODES);
|
||||
if (closest_nodes.size() >= TARGET_NODES and hash.xorCmp(closest_nodes.back()->id, myid) < 0) {
|
||||
DHT_LOG_WARN("[node %s] announce too far from the target. Dropping value.", node->toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[node %s] announce too far from the target. Dropping value.", node->toString().c_str());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& v : values) {
|
||||
if (v->id == Value::INVALID_ID) {
|
||||
DHT_LOG_WARN("[value %s] incorrect value id", hash.toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[value %s] incorrect value id", hash.toString().c_str());
|
||||
throw DhtProtocolException {
|
||||
DhtProtocolException::NON_AUTHORITATIVE_INFORMATION,
|
||||
DhtProtocolException::PUT_INVALID_ID
|
||||
@@ -3309,15 +3302,15 @@ Dht::onAnnounce(std::shared_ptr<Node> node,
|
||||
std::shared_ptr<Value> vc = v;
|
||||
if (lv) {
|
||||
if (*lv == *vc) {
|
||||
DHT_LOG_WARN("[store %s] nothing to do for %s.", hash.toString().c_str(), lv->toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[store %s] nothing to do for %s", hash.toString().c_str(), lv->toString().c_str());
|
||||
} else {
|
||||
const auto& type = getType(lv->type);
|
||||
if (type.editPolicy(hash, lv, vc, node->id, (sockaddr*)&node->addr.first, node->addr.second)) {
|
||||
DHT_LOG_DEBUG("[store %s] editing %s.",
|
||||
DHT_LOG.d(hash, node->id, "[store %s] editing %s",
|
||||
hash.toString().c_str(), vc->toString().c_str());
|
||||
storageStore(hash, vc, created);
|
||||
} else {
|
||||
DHT_LOG_DEBUG("[store %s] rejecting edition of %s because of storage policy.",
|
||||
DHT_LOG.d(hash, node->id, "[store %s] rejecting edition of %s because of storage policy",
|
||||
hash.toString().c_str(), vc->toString().c_str());
|
||||
}
|
||||
}
|
||||
@@ -3325,10 +3318,10 @@ Dht::onAnnounce(std::shared_ptr<Node> node,
|
||||
// Allow the value to be edited by the storage policy
|
||||
const auto& type = getType(vc->type);
|
||||
if (type.storePolicy(hash, vc, node->id, (sockaddr*)&node->addr.first, node->addr.second)) {
|
||||
DHT_LOG_DEBUG("[store %s] storing %s.", hash.toString().c_str(), vc->toString().c_str());
|
||||
DHT_LOG.d(hash, node->id, "[store %s] storing %s", hash.toString().c_str(), vc->toString().c_str());
|
||||
storageStore(hash, vc, created);
|
||||
} else {
|
||||
DHT_LOG_DEBUG("[store %s] rejecting storage of %s.",
|
||||
DHT_LOG.d(hash, node->id, "[store %s] rejecting storage of %s",
|
||||
hash.toString().c_str(), vc->toString().c_str());
|
||||
}
|
||||
}
|
||||
@@ -3341,17 +3334,16 @@ Dht::onRefresh(std::shared_ptr<Node> node, const InfoHash& hash, const Blob& tok
|
||||
{
|
||||
const auto& now = scheduler.time();
|
||||
if (not tokenMatch(token, (sockaddr*)&node->addr.first)) {
|
||||
DHT_LOG.WARN("[node %s] incorrect token %s for 'put'.", node->toString().c_str(), hash.toString().c_str());
|
||||
DHT_LOG.w(hash, node->id, "[node %s] incorrect token %s for 'put'", node->toString().c_str(), hash.toString().c_str());
|
||||
throw DhtProtocolException {DhtProtocolException::UNAUTHORIZED, DhtProtocolException::PUT_WRONG_TOKEN};
|
||||
}
|
||||
|
||||
auto s = store.find(hash);
|
||||
if (s != store.end() and s->second.refresh(now, vid)) {
|
||||
DHT_LOG.DEBUG("[store %s] refreshed value %s.", hash.toString().c_str(), std::to_string(vid).c_str());
|
||||
DHT_LOG.d(hash, node->id, "[store %s] [node %s] refreshed value %s", hash.toString().c_str(), node->toString().c_str(), std::to_string(vid).c_str());
|
||||
} else {
|
||||
DHT_LOG.DEBUG("[node %s] got refresh value for unknown storage (id: %s).",
|
||||
node->id.toString().c_str(),
|
||||
hash.toString().c_str());
|
||||
DHT_LOG.d(hash, node->id, "[store %s] [node %s] got refresh for unknown value",
|
||||
hash.toString().c_str(), node->toString().c_str());
|
||||
throw DhtProtocolException {DhtProtocolException::NOT_FOUND, DhtProtocolException::STORAGE_NOT_FOUND};
|
||||
}
|
||||
return {};
|
||||
@@ -3361,7 +3353,7 @@ void
|
||||
Dht::onAnnounceDone(const Request& req, NetworkEngine::RequestAnswer& answer, std::shared_ptr<Search>& sr)
|
||||
{
|
||||
const auto& now = scheduler.time();
|
||||
DHT_LOG_DEBUG("[search %s] [node %s] got reply to put!",
|
||||
DHT_LOG.d(sr->id, req.node->id, "[search %s] [node %s] got reply to put!",
|
||||
sr->id.toString().c_str(), req.node->toString().c_str());
|
||||
searchSendGetValues(sr);
|
||||
/* if (auto sn = sr->getNode(req->node)) { */
|
||||
|
||||
Reference in new issue
Block a user