don't count pad-files as partial download pieces in the piece picker. prioritize which immutable dht items to keep also based on distance from our ID. remove some todo comments that probably should not be done

This commit is contained in:
Arvid Norberg 2013-09-14 10:08:31 +00:00
parent 1aa47fc13e
commit f1f89123e8
8 changed files with 47 additions and 16 deletions

View File

@ -76,7 +76,6 @@ namespace libtorrent { namespace dht
friend void intrusive_ptr_add_ref(dht_tracker const*);
friend void intrusive_ptr_release(dht_tracker const*);
// TODO: 3 take a udp_socket_interface here instead. Move udp_socket_interface down into libtorrent core
dht_tracker(libtorrent::aux::session_impl& ses, rate_limited_udp_socket& sock
, dht_settings const& settings, entry const* state = 0);
virtual ~dht_tracker();

View File

@ -53,7 +53,6 @@ namespace libtorrent
typedef boost::function<void(int, address, int, error_code const&)> portmap_callback_t;
typedef boost::function<void(char const*)> log_callback_t;
// TODO: 2 make this a shared_ptr instead
class natpmp : public intrusive_ptr_base<natpmp>
{
public:

View File

@ -511,6 +511,8 @@ namespace libtorrent
{ return index == p.index && peer_count == p.peer_count; }
};
void set_num_pad_files(int n) { m_num_pad_files = n; }
private:
#ifndef TORRENT_DEBUG_REFCOUNTS
@ -595,8 +597,8 @@ namespace libtorrent
// second entry in m_downloads and so on.
std::vector<block_info> m_block_info;
int m_blocks_per_piece;
int m_blocks_in_last_piece;
boost::uint16_t m_blocks_per_piece;
boost::uint16_t m_blocks_in_last_piece;
// the number of filtered pieces that we don't already
// have. total_number_of_pieces - number_of_pieces_we_have
@ -622,6 +624,13 @@ namespace libtorrent
// the number of regions of pieces we don't have.
int m_sparse_regions;
// this is the number of partial download pieces
// that may be caused by pad files. We raise the limit
// of number of partial pieces by this amount, to not
// prioritize pieces that intersect pad files for no
// apparent reason
int m_num_pad_files;
// if this is set to true, it means update_pieces()
// has to be called before accessing m_pieces.
mutable bool m_dirty;

View File

@ -700,7 +700,6 @@ namespace libtorrent
// if a comment is found in the torrent file
// this will be set to that comment
// TODO: 2 these strings (m_comment, m_created_by, m_ssl_root_cert) could be lazy_entry* to save memory
std::string m_comment;
// an optional string naming the software used

View File

@ -118,8 +118,8 @@ namespace libtorrent
typedef boost::function<void(int, address, int, error_code const&)> portmap_callback_t;
typedef boost::function<void(char const*)> log_callback_t;
// TODO: support using the windows API for UPnP operations as well
class TORRENT_EXTRA_EXPORT upnp : public intrusive_ptr_base<upnp>
// TODO: 2 make this a shared_ptr instead
{
public:
upnp(io_service& ios, connection_queue& cc

View File

@ -612,6 +612,30 @@ void incoming_error(entry& e, char const* msg, int error_code)
l.push_back(entry(msg));
}
// return true of the first argument is a better canidate for removal, i.e.
// less important to keep
struct immutable_item_comparator
{
immutable_item_comparator(node_id const& our_id) : m_our_id(our_id) {}
bool operator() (std::pair<node_id, dht_immutable_item> const& lhs
, std::pair<node_id, dht_immutable_item> const& rhs) const
{
int l_distance = distance_exp(lhs.first, m_our_id);
int r_distance = distance_exp(rhs.first, m_our_id);
// this is a score taking the popularity (number of announcers) and the
// fit, in terms of distance from ideal storing node, into account.
// each additional 5 announcers is worth one extra bit in the distance.
// that is, an item with 10 announcers is allowed to be twice as far
// from another item with 5 announcers, from our node ID. Twice as far
// because it gets one more bit.
return lhs.second.num_announcers / 5 - l_distance < rhs.second.num_announcers / 5 - r_distance;
}
node_id const& m_our_id;
};
// build response
void node_impl::incoming_request(msg const& m, entry& e)
{
@ -876,15 +900,12 @@ void node_impl::incoming_request(msg const& m, entry& e)
if (int(m_immutable_table.size()) >= m_settings.max_dht_items)
{
// delete the least important one (i.e. the one
// the fewest peers are announcing)
// TODO: 3 also take into account how far away from our node ID
// the item is
// the fewest peers are announcing, and farthest
// from our node ID)
dht_immutable_table_t::iterator j = std::min_element(m_immutable_table.begin()
, m_immutable_table.end()
, boost::bind(&dht_immutable_item::num_announcers
, boost::bind(&dht_immutable_table_t::value_type::second, _1))
< boost::bind(&dht_immutable_item::num_announcers
, boost::bind(&dht_immutable_table_t::value_type::second, _2)));
, immutable_item_comparator(m_id));
TORRENT_ASSERT(j != m_immutable_table.end());
free(j->second.value);
m_immutable_table.erase(j);

View File

@ -74,6 +74,7 @@ namespace libtorrent
, m_cursor(0)
, m_reverse_cursor(0)
, m_sparse_regions(1)
, m_num_pad_files(0)
, m_dirty(false)
{
#ifdef TORRENT_PICKER_LOG
@ -1486,9 +1487,7 @@ namespace libtorrent
// make this scale by the number of peers we have. For large
// scale clients, we would have more peers, and allow a higher
// threshold for the number of partials
// TODO: 2 m_downloads size will be > 0 just by having pad-files
// in the torrent. That should be taken into account here.
if (m_downloads.size() > num_peers * 3 / 2) options |= prioritize_partials;
if (m_downloads.size() > m_num_pad_files + num_peers * 3 / 2) options |= prioritize_partials;
if (options & ignore_whole_pieces) prefer_whole_pieces = 0;

View File

@ -1711,10 +1711,13 @@ namespace libtorrent
m_resume_data_loaded = true;
#endif
int num_pad_files = 0;
TORRENT_ASSERT(block_size() > 0);
file_storage const& fs = m_torrent_file->files();
for (int i = 0; i < fs.num_files(); ++i)
{
if (fs.pad_file_at(i)) ++num_pad_files;
if (!fs.pad_file_at(i) || fs.file_size(i) == 0) continue;
m_padding += fs.file_size(i);
@ -1766,6 +1769,8 @@ namespace libtorrent
}
}
m_picker->set_num_pad_files(num_pad_files);
m_storage->async_check_fastresume(&m_resume_entry
, boost::bind(&torrent::on_resume_data_checked
, shared_from_this(), _1, _2));