fixed #289 in trunk, 0.12 and 0.13

This commit is contained in:
Arvid Norberg 2008-03-19 22:44:55 +00:00
parent e9e74a928c
commit fece6e9300
4 changed files with 20 additions and 16 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -71,21 +71,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)
{

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/bind.hpp>
#include "libtorrent/kademlia/node_id.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/assert.hpp"
using boost::bind;
@ -95,5 +96,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