From f2b9f8eeda55641a09fdd661c91db9c66ac6cced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Fri, 13 Oct 2017 01:06:47 +0200 Subject: [PATCH] dht: move bucket time update to routing table --- src/dht.cpp | 4 +--- src/routing_table.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dht.cpp b/src/dht.cpp index b42db9ae..78a262ed 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -2077,10 +2077,8 @@ Dht::onError(Sp req, net::DhtProtocolException e) { } void -Dht::onReportedAddr(const InfoHash& id, const SockAddr& addr) +Dht::onReportedAddr(const InfoHash& /*id*/, const SockAddr& addr) { - const auto& b = buckets(addr.getFamily()).findBucket(id); - b->time = scheduler.time(); if (addr) reportedAddr(addr); } diff --git a/src/routing_table.cpp b/src/routing_table.cpp index 462d3c67..b0a95e9d 100644 --- a/src/routing_table.cpp +++ b/src/routing_table.cpp @@ -202,9 +202,13 @@ RoutingTable::split(const RoutingTable::iterator& b) } bool -RoutingTable::onNewNode(const Sp& node, int comfirm, const time_point& now, const InfoHash& myid, net::NetworkEngine& ne) { +RoutingTable::onNewNode(const Sp& node, int confirm, const time_point& now, const InfoHash& myid, net::NetworkEngine& ne) { auto b = findBucket(node->id); if (b == end()) return false; + + if (confirm == 2) + b->time = now; + for (auto& n : b->nodes) { if (n == node) return false; @@ -244,11 +248,11 @@ RoutingTable::onNewNode(const Sp& node, int comfirm, const time_point& now //DHT_LOG.d("Splitting from depth %u", depth(b)); b->sendCachedPing(ne); split(b); - return onNewNode(node, comfirm, now, myid, ne); + return onNewNode(node, confirm, now, myid, ne); } /* No space for this node. Cache it away for later. */ - if (comfirm or not b->cached) + if (confirm or not b->cached) b->cached = node; } else { /* Create a new node. */