network engine: handle unexpected node id

This commit is contained in:
Adrien Béraud committed 2016-05-15 01:36:25 -04:00
1 parent db6c301084
commit bd72c6468f
2 files changed
+16 -6

No files matched your search

+14 -6
View File
@@ -289,7 +289,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
return;
}
if (msg.id == myid) {
if (msg.id == myid || msg.id == zeroes) {
DHT_LOG.DEBUG("Received message from self.");
return;
}
@@ -319,14 +319,22 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
}
auto req = reqp->second;
auto node = req->node;//cache.getNode(msg.id, from, fromlen, now, 2);
node->received(now, req);
if (node->id == zeroes) {
// reply to a message sent when we didn't know the node ID.
auto node = req->node;
if (node->id != msg.id) {
bool unknown_node = node->id == zeroes;
node = cache.getNode(msg.id, from, fromlen, now, 2);
req->node = node;
if (unknown_node) {
// received reply to a message sent when we didn't know the node ID.
req->node = node;
} else {
// received reply from unexpected node
node->received(now, req);
onNewNode(node, 2);
return;
}
} else
node->update(from, fromlen);
node->received(now, req);
onNewNode(node, 2);
onReportedAddr(msg.id, (sockaddr*)&msg.addr.first, msg.addr.second);
+2
View File
@@ -28,6 +28,8 @@ NodeCache::getNode(const InfoHash& id, sa_family_t family) {
std::shared_ptr<Node>
NodeCache::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirm) {
if (id == zeroes)
return std::make_shared<Node>(id, sa, sa_len);
return (sa->sa_family == AF_INET ? cache_4 : cache_6).getNode(id, sa, sa_len, now, confirm);
}