DHT fix where the node_id would get set after it was started and be inconsitent with rpc_manager and routing_table

This commit is contained in:
Arvid Norberg 2008-11-11 08:33:34 +00:00
parent dd26371c0a
commit 473f75e98a
5 changed files with 18 additions and 14 deletions

View File

@ -74,7 +74,7 @@ namespace libtorrent { namespace dht
friend void intrusive_ptr_add_ref(dht_tracker const*);
friend void intrusive_ptr_release(dht_tracker const*);
dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
, dht_settings const& settings);
, dht_settings const& settings, entry const* state = 0);
void start(entry const& bootstrap);
void stop();

View File

@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/iterator/transform_iterator.hpp>
#include <boost/ref.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/optional.hpp>
#include "libtorrent/socket.hpp"
@ -169,7 +170,7 @@ class node_impl : boost::noncopyable
typedef std::map<node_id, torrent_entry> table_t;
public:
node_impl(libtorrent::aux::session_impl& ses, boost::function<void(msg const&)> const& f
, dht_settings const& settings);
, dht_settings const& settings, boost::optional<node_id> nid);
virtual ~node_impl() {}
@ -194,7 +195,6 @@ public:
typedef table_t::iterator data_iterator;
void set_node_id(node_id const& nid) { m_id = nid; }
node_id const& nid() const { return m_id; }
boost::tuple<int, int> size() const{ return m_table.size(); }

View File

@ -128,11 +128,20 @@ namespace libtorrent { namespace dht
TORRENT_DEFINE_LOG(dht_tracker)
#endif
boost::optional<node_id> extract_node_id(entry const* e)
{
if (e == 0 || e->type() != entry::dictionary_t) return boost::optional<node_id>();
entry const* nid = e->find_key("node-id");
if (nid == 0 || nid->type() != entry::string_t || nid->string().length() != 20)
return boost::optional<node_id>();
return boost::optional<node_id>(node_id(nid->string().c_str()));
}
// class that puts the networking and the kademlia node in a single
// unit and connecting them together.
dht_tracker::dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
, dht_settings const& settings)
: m_dht(ses, bind(&dht_tracker::send_packet, this, _1), settings)
, dht_settings const& settings, entry const* state)
: m_dht(ses, bind(&dht_tracker::send_packet, this, _1), settings, extract_node_id(state))
, m_ses(ses)
, m_sock(sock)
, m_last_new_key(time_now() - minutes(key_refresh))
@ -189,12 +198,6 @@ namespace libtorrent { namespace dht
if (entry const* nodes = bootstrap.find_key("nodes"))
read_endpoint_list<udp::endpoint>(nodes, initial_nodes);
} catch (std::exception&) {}
entry const* nid = bootstrap.find_key("node-id");
if (nid
&& nid->type() == entry::string_t
&& nid->string().length() == 40)
m_dht.set_node_id(boost::lexical_cast<node_id>(nid->string()));
}
error_code ec;

View File

@ -94,9 +94,10 @@ void nop() {}
node_impl::node_impl(libtorrent::aux::session_impl& ses
, boost::function<void(msg const&)> const& f
, dht_settings const& settings)
, dht_settings const& settings
, boost::optional<node_id> nid)
: m_settings(settings)
, m_id(generate_id())
, m_id(nid ? *nid : generate_id())
, m_table(m_id, 8, settings)
, m_rpc(bind(&node_impl::incoming_request, this, _1)
, m_id, m_table, f)

View File

@ -2206,7 +2206,7 @@ namespace aux {
, m_dht_settings.service_port
, m_dht_settings.service_port);
}
m_dht = new dht::dht_tracker(*this, m_dht_socket, m_dht_settings);
m_dht = new dht::dht_tracker(*this, m_dht_socket, m_dht_settings, &startup_state);
if (!m_dht_socket.is_open() || m_dht_socket.local_port() != m_dht_settings.service_port)
{
m_dht_socket.bind(m_dht_settings.service_port);