the DHT can now change listen port runtime, and the same listen interface will be used for the DHT as is used for the torrent listen port. The DHT buckets are refreshed slightly more evenly distributed over time.
This commit is contained in:
parent
0d0f07189d
commit
b1411fcdf7
|
@ -899,10 +899,10 @@ int main(int ac, char* av[])
|
||||||
for (int i = 0; i < info.num_files(); ++i)
|
for (int i = 0; i < info.num_files(); ++i)
|
||||||
{
|
{
|
||||||
if (file_progress[i] == 1.f)
|
if (file_progress[i] == 1.f)
|
||||||
out << progress_bar(file_progress[i], 10, "32") << " "
|
out << progress_bar(file_progress[i], 20, "32") << " "
|
||||||
<< info.file_at(i).path.leaf() << "\n";
|
<< info.file_at(i).path.leaf() << "\n";
|
||||||
else
|
else
|
||||||
out << progress_bar(file_progress[i], 10, "33") << " "
|
out << progress_bar(file_progress[i], 20, "33") << " "
|
||||||
<< info.file_at(i).path.leaf() << "\n";
|
<< info.file_at(i).path.leaf() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,11 +62,13 @@ namespace libtorrent { namespace dht
|
||||||
struct dht_tracker
|
struct dht_tracker
|
||||||
{
|
{
|
||||||
dht_tracker(asio::io_service& d, dht_settings const& settings
|
dht_tracker(asio::io_service& d, dht_settings const& settings
|
||||||
, entry const& bootstrap);
|
, asio::ip::address listen_interface, entry const& bootstrap);
|
||||||
|
|
||||||
void add_node(udp::endpoint node);
|
void add_node(udp::endpoint node);
|
||||||
void add_node(std::pair<std::string, int> const& node);
|
void add_node(std::pair<std::string, int> const& node);
|
||||||
|
|
||||||
|
void rebind(asio::ip::address interface, int listen_port);
|
||||||
|
|
||||||
entry state() const;
|
entry state() const;
|
||||||
|
|
||||||
void announce(sha1_hash const& ih, int listen_port
|
void announce(sha1_hash const& ih, int listen_port
|
||||||
|
|
|
@ -216,7 +216,8 @@ private:
|
||||||
typedef boost::array<std::pair<bucket_t, bucket_t>, 160> table_t;
|
typedef boost::array<std::pair<bucket_t, bucket_t>, 160> table_t;
|
||||||
table_t m_buckets;
|
table_t m_buckets;
|
||||||
// timestamps of the last activity in each bucket
|
// timestamps of the last activity in each bucket
|
||||||
boost::array<boost::posix_time::ptime, 160> m_bucket_activity;
|
typedef boost::array<boost::posix_time::ptime, 160> table_activity_t;
|
||||||
|
table_activity_t m_bucket_activity;
|
||||||
node_id m_id; // our own node id
|
node_id m_id; // our own node id
|
||||||
|
|
||||||
// this is the lowest bucket index with nodes in it
|
// this is the lowest bucket index with nodes in it
|
||||||
|
|
|
@ -115,9 +115,9 @@ namespace libtorrent { namespace dht
|
||||||
// class that puts the networking and the kademlia node in a single
|
// class that puts the networking and the kademlia node in a single
|
||||||
// unit and connecting them together.
|
// unit and connecting them together.
|
||||||
dht_tracker::dht_tracker(asio::io_service& d, dht_settings const& settings
|
dht_tracker::dht_tracker(asio::io_service& d, dht_settings const& settings
|
||||||
, entry const& bootstrap)
|
, asio::ip::address listen_interface, entry const& bootstrap)
|
||||||
: m_demuxer(d)
|
: m_demuxer(d)
|
||||||
, m_socket(m_demuxer, udp::endpoint(address(), settings.service_port))
|
, m_socket(m_demuxer, udp::endpoint(listen_interface, settings.service_port))
|
||||||
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings
|
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings
|
||||||
, read_id(bootstrap))
|
, read_id(bootstrap))
|
||||||
, m_buffer(0)
|
, m_buffer(0)
|
||||||
|
@ -215,6 +215,14 @@ namespace libtorrent { namespace dht
|
||||||
assert(false);
|
assert(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void dht_tracker::rebind(asio::ip::address listen_interface, int listen_port)
|
||||||
|
{
|
||||||
|
m_socket.close();
|
||||||
|
m_socket.open(asio::ip::udp::v4());
|
||||||
|
m_socket.bind(udp::endpoint(listen_interface, listen_port));
|
||||||
|
assert(m_settings.service_port == listen_port);
|
||||||
|
}
|
||||||
|
|
||||||
void dht_tracker::tick(asio::error const& e)
|
void dht_tracker::tick(asio::error const& e)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,8 +66,10 @@ routing_table::routing_table(node_id const& id, int bucket_size
|
||||||
, m_id(id)
|
, m_id(id)
|
||||||
, m_lowest_active_bucket(160)
|
, m_lowest_active_bucket(160)
|
||||||
{
|
{
|
||||||
std::fill(m_bucket_activity.begin(), m_bucket_activity.end()
|
// distribute the refresh times for the buckets in an
|
||||||
, second_clock::universal_time() - hours(1));
|
// attempt do even out the network load
|
||||||
|
for (int i = 0; i < 160; ++i)
|
||||||
|
m_bucket_activity[i] = second_clock::universal_time() - seconds(15*60 - i*5);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::tuple<int, int> routing_table::size() const
|
boost::tuple<int, int> routing_table::size() const
|
||||||
|
|
|
@ -1425,6 +1425,16 @@ namespace libtorrent
|
||||||
if (m_impl.m_listen_socket)
|
if (m_impl.m_listen_socket)
|
||||||
m_impl.m_listen_socket.reset();
|
m_impl.m_listen_socket.reset();
|
||||||
|
|
||||||
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
if (m_impl.m_listen_interface.address() != new_interface.address()
|
||||||
|
&& m_impl.m_dht)
|
||||||
|
{
|
||||||
|
// the listen interface changed, rebind the dht listen socket as well
|
||||||
|
m_impl.m_dht->rebind(new_interface.address()
|
||||||
|
, m_impl.m_dht_settings.service_port);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
m_impl.m_incoming_connection = false;
|
m_impl.m_incoming_connection = false;
|
||||||
m_impl.m_listen_interface = new_interface;
|
m_impl.m_listen_interface = new_interface;
|
||||||
|
|
||||||
|
@ -1466,7 +1476,8 @@ namespace libtorrent
|
||||||
void session::start_dht(entry const& startup_state)
|
void session::start_dht(entry const& startup_state)
|
||||||
{
|
{
|
||||||
m_impl.m_dht.reset(new dht::dht_tracker(m_impl.m_selector
|
m_impl.m_dht.reset(new dht::dht_tracker(m_impl.m_selector
|
||||||
, m_impl.m_dht_settings, startup_state));
|
, m_impl.m_dht_settings, m_impl.m_listen_interface.address()
|
||||||
|
, startup_state));
|
||||||
}
|
}
|
||||||
|
|
||||||
void session::stop_dht()
|
void session::stop_dht()
|
||||||
|
@ -1479,8 +1490,8 @@ namespace libtorrent
|
||||||
if (settings.service_port != m_impl.m_dht_settings.service_port
|
if (settings.service_port != m_impl.m_dht_settings.service_port
|
||||||
&& m_impl.m_dht)
|
&& m_impl.m_dht)
|
||||||
{
|
{
|
||||||
assert(false); // not implemented yet
|
m_impl.m_dht->rebind(m_impl.m_listen_interface.address()
|
||||||
// TODO: change dht service port!
|
, settings.service_port);
|
||||||
}
|
}
|
||||||
m_impl.m_dht_settings = settings;
|
m_impl.m_dht_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue