diff options
author | Marcos Pinto <markybob@dipconsultants.com> | 2008-03-21 02:00:26 +0000 |
---|---|---|
committer | Marcos Pinto <markybob@dipconsultants.com> | 2008-03-21 02:00:26 +0000 |
commit | 06a1591b4445c6f0b0f6b3e22c19e399206acd50 (patch) | |
tree | 61999517dde1f816e74e55f51f861ee50540f375 | |
parent | 69d5aa6e2e5e40df8d8041c2a9f5fb6b1bc5e868 (diff) | |
download | deluge-06a1591b4445c6f0b0f6b3e22c19e399206acd50.tar.gz deluge-06a1591b4445c6f0b0f6b3e22c19e399206acd50.tar.bz2 deluge-06a1591b4445c6f0b0f6b3e22c19e399206acd50.zip |
fix multiple router_node support lt rev 2089
-rw-r--r-- | libtorrent/include/libtorrent/kademlia/node_id.hpp | 2 | ||||
-rw-r--r-- | libtorrent/include/libtorrent/kademlia/traversal_algorithm.hpp | 2 | ||||
-rw-r--r-- | libtorrent/src/kademlia/node.cpp | 15 | ||||
-rw-r--r-- | 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<peer_entry>& 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 <algorithm> #include <iomanip> +#include <ctime> #include <boost/bind.hpp> #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 |