mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
fix no values sent in response to 'find' request
This was due to using the wrong InfoHash field from the ParsedMessage when responding to 'find' request.
This commit is contained in:
1 parent
8cc6c21d19
commit
ff72487b02
3 files changed
+26
-25
No files matched your search
@@ -406,20 +406,20 @@ private:
|
||||
|
||||
struct ParsedMessage {
|
||||
MessageType type;
|
||||
InfoHash id;
|
||||
InfoHash info_hash;
|
||||
InfoHash target;
|
||||
TransId tid;
|
||||
Blob token;
|
||||
Value::Id value_id;
|
||||
time_point created { time_point::max() };
|
||||
Blob nodes4;
|
||||
Blob nodes6;
|
||||
std::vector<std::shared_ptr<Value>> values;
|
||||
want_t want;
|
||||
uint16_t error_code;
|
||||
InfoHash id; /* the id of the sender */
|
||||
InfoHash info_hash; /* hash for which values are requested */
|
||||
InfoHash target; /* target id around which to find nodes */
|
||||
TransId tid; /* transaction id */
|
||||
Blob token; /* security token */
|
||||
Value::Id value_id; /* the value id */
|
||||
time_point created { time_point::max() }; /* time when value was first created */
|
||||
Blob nodes4; /* IPv4 nodes in response to a 'find' request */
|
||||
Blob nodes6; /* IPv6 nodes in response to a 'find' request */
|
||||
std::vector<std::shared_ptr<Value>> values; /* values for a 'get' request */
|
||||
want_t want; /* states if ipv4 or ipv6 request */
|
||||
uint16_t error_code; /* error code in case of error */
|
||||
std::string ua;
|
||||
Address addr;
|
||||
Address addr; /* reported address by the distant node */
|
||||
void msgpack_unpack(msgpack::object o);
|
||||
};
|
||||
|
||||
|
||||
+11
-10
@@ -2600,17 +2600,17 @@ Dht::onPing(std::shared_ptr<Node>)
|
||||
}
|
||||
|
||||
NetworkEngine::RequestAnswer
|
||||
Dht::onFindNode(std::shared_ptr<Node> node, InfoHash& hash, want_t want)
|
||||
Dht::onFindNode(std::shared_ptr<Node> node, InfoHash& target, want_t want)
|
||||
{
|
||||
const auto& now = scheduler.time();
|
||||
Blob ntoken = makeToken((sockaddr*)&node->ss, false);
|
||||
std::vector<std::shared_ptr<Node>> nodes, nodes6;
|
||||
if (want & WANT4) {
|
||||
auto tmp = buckets.findClosestNodes(hash, now, TARGET_NODES);
|
||||
auto tmp = buckets.findClosestNodes(target, now, TARGET_NODES);
|
||||
nodes.insert(nodes.begin(), tmp.begin(), tmp.end());
|
||||
}
|
||||
if (want & WANT6) {
|
||||
auto tmp = buckets6.findClosestNodes(hash, now, TARGET_NODES);
|
||||
auto tmp = buckets6.findClosestNodes(target, now, TARGET_NODES);
|
||||
nodes6.insert(nodes6.begin(), tmp.begin(), tmp.end());
|
||||
}
|
||||
return NetworkEngine::RequestAnswer {ntoken, Value::INVALID_ID, {}, std::move(nodes), std::move(nodes6)};
|
||||
@@ -2620,7 +2620,7 @@ NetworkEngine::RequestAnswer
|
||||
Dht::onGetValues(std::shared_ptr<Node> node, InfoHash& hash, want_t)
|
||||
{
|
||||
const auto& now = scheduler.time();
|
||||
NetworkEngine::RequestAnswer* answer;
|
||||
std::shared_ptr<NetworkEngine::RequestAnswer> answer {};
|
||||
if (hash == zeroes) {
|
||||
DHT_LOG.WARN("[node %s %s] Eek! Got get_values with no info_hash.",
|
||||
node->id.toString().c_str(), print_addr(node->ss, node->sslen).c_str());
|
||||
@@ -2628,12 +2628,12 @@ Dht::onGetValues(std::shared_ptr<Node> node, InfoHash& hash, want_t)
|
||||
} else {
|
||||
auto st = findStorage(hash);
|
||||
Blob ntoken = makeToken((sockaddr*)&node->ss, false);
|
||||
answer = new NetworkEngine::RequestAnswer {
|
||||
ntoken,
|
||||
0,
|
||||
{},
|
||||
buckets.findClosestNodes(hash, now, TARGET_NODES),
|
||||
buckets6.findClosestNodes(hash, now, TARGET_NODES)
|
||||
answer = std::shared_ptr<NetworkEngine::RequestAnswer> {
|
||||
new NetworkEngine::RequestAnswer {
|
||||
ntoken, 0, {},
|
||||
buckets.findClosestNodes(hash, now, TARGET_NODES),
|
||||
buckets6.findClosestNodes(hash, now, TARGET_NODES)
|
||||
}
|
||||
};
|
||||
if (st != store.end() && not st->empty()) {
|
||||
DHT_LOG.DEBUG("[node %s %s] sending %u values.",
|
||||
@@ -2657,6 +2657,7 @@ Dht::onGetValuesDone(std::shared_ptr<NetworkEngine::RequestStatus> status, Netwo
|
||||
if (not sr)
|
||||
return;
|
||||
|
||||
DHT_LOG.DEBUG("[search %s IPv%c] got reply to 'get'", sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6');
|
||||
const auto& now = scheduler.time();
|
||||
sr->insertNode(status->node, now, a.ntoken);
|
||||
for (auto& sn : sr->nodes) {
|
||||
|
||||
@@ -176,7 +176,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
|
||||
DHT_LOG.DEBUG("[node %s %s] got 'find' request (%d).",
|
||||
msg.id.toString().c_str(), print_addr(from, fromlen).c_str(), msg.want);
|
||||
++in_stats.find;
|
||||
RequestAnswer answer = onFindNode(node, msg.info_hash, msg.want);
|
||||
RequestAnswer answer = onFindNode(node, msg.target, msg.want);
|
||||
auto nnodes = bufferNodes(from->sa_family, msg.target, msg.want, answer.nodes, answer.nodes6);
|
||||
sendNodesValues(from, fromlen, msg.tid, nnodes.first, nnodes.second, {}, answer.ntoken);
|
||||
break;
|
||||
@@ -186,7 +186,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
|
||||
node->id.toString().c_str(), print_addr(node->ss, node->sslen).c_str(), msg.info_hash.toString().c_str());
|
||||
++in_stats.get;
|
||||
RequestAnswer answer = onGetValues(node, msg.info_hash, msg.want);
|
||||
auto nnodes = bufferNodes(from->sa_family, msg.target, msg.want, answer.nodes, answer.nodes6);
|
||||
auto nnodes = bufferNodes(from->sa_family, msg.info_hash, msg.want, answer.nodes, answer.nodes6);
|
||||
sendNodesValues(from, fromlen, msg.tid, nnodes.first, nnodes.second, answer.values, answer.ntoken);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user