fix multiple router_node support lt rev 2089

This commit is contained in:
Marcos Pinto 2008-03-21 02:00:26 +00:00
parent f55fdcf118
commit d2d0e26f4c
4 changed files with 21 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

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

View File

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