From d2d0e26f4c56850639daa3ef04eee52c5e189b89 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Fri, 21 Mar 2008 02:00:26 +0000 Subject: [PATCH] fix multiple router_node support lt rev 2089 --- .../include/libtorrent/kademlia/node_id.hpp | 2 ++ .../kademlia/traversal_algorithm.hpp | 2 +- libtorrent/src/kademlia/node.cpp | 15 --------------- libtorrent/src/kademlia/node_id.cpp | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libtorrent/include/libtorrent/kademlia/node_id.hpp b/libtorrent/include/libtorrent/kademlia/node_id.hpp index 5e732acac..4173808c9 100644 --- a/libtorrent/include/libtorrent/kademlia/node_id.hpp +++ b/libtorrent/include/libtorrent/kademlia/node_id.hpp @@ -54,6 +54,8 @@ bool compare_ref(node_id const& n1, node_id const& n2, node_id const& ref); // usefult for finding out which bucket a node belongs to int distance_exp(node_id const& n1, node_id const& n2); +node_id generate_id(); + } } // namespace libtorrent::dht #endif // NODE_ID_HPP diff --git a/libtorrent/include/libtorrent/kademlia/traversal_algorithm.hpp b/libtorrent/include/libtorrent/kademlia/traversal_algorithm.hpp index d51ed5506..b333b385e 100644 --- a/libtorrent/include/libtorrent/kademlia/traversal_algorithm.hpp +++ b/libtorrent/include/libtorrent/kademlia/traversal_algorithm.hpp @@ -150,7 +150,7 @@ traversal_algorithm::traversal_algorithm( for (routing_table::router_iterator i = table.router_begin() , end(table.router_end()); i != end; ++i) { - add_entry(node_id(0), *i, result::initial); + add_entry(generate_id(), *i, result::initial); } } diff --git a/libtorrent/src/kademlia/node.cpp b/libtorrent/src/kademlia/node.cpp index 5b919393c..d4b343519 100644 --- a/libtorrent/src/kademlia/node.cpp +++ b/libtorrent/src/kademlia/node.cpp @@ -72,21 +72,6 @@ using asio::ip::udp; TORRENT_DEFINE_LOG(node) #endif -node_id generate_id() -{ - char random[20]; - std::srand(std::time(0)); -#ifdef _MSC_VER - std::generate(random, random + 20, &rand); -#else - std::generate(random, random + 20, &std::rand); -#endif - - hasher h; - h.update(random, 20); - return h.final(); -} - // remove peers that have timed out void purge_peers(std::set& peers) { diff --git a/libtorrent/src/kademlia/node_id.cpp b/libtorrent/src/kademlia/node_id.cpp index 99f3df219..758af2f8d 100644 --- a/libtorrent/src/kademlia/node_id.cpp +++ b/libtorrent/src/kademlia/node_id.cpp @@ -34,9 +34,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include "libtorrent/kademlia/node_id.hpp" +#include "libtorrent/hasher.hpp" #include "libtorrent/assert.hpp" using boost::bind; @@ -95,5 +97,21 @@ int distance_exp(node_id const& n1, node_id const& n2) return 0; } +struct static_ { static_() { std::srand(std::time(0)); } } static__; + +node_id generate_id() +{ + char random[20]; +#ifdef _MSC_VER + std::generate(random, random + 20, &rand); +#else + std::generate(random, random + 20, &std::rand); +#endif + + hasher h; + h.update(random, 20); + return h.final(); +} + } } // namespace libtorrent::dht