fixes for torrents with smaller pieces than 16kB

This commit is contained in:
Arvid Norberg 2008-06-18 12:34:39 +00:00
parent 77c13d73f6
commit 9c94f54868
4 changed files with 15 additions and 10 deletions

View File

@ -179,7 +179,7 @@ namespace libtorrent
, m_max_uploads((std::numeric_limits<int>::max)())
, m_num_uploads(0)
, m_max_connections((std::numeric_limits<int>::max)())
, m_block_size(block_size)
, m_block_size((std::min)(block_size, tf->piece_length()))
, m_complete(-1)
, m_incomplete(-1)
, m_deficit_counter(0)
@ -405,13 +405,15 @@ namespace libtorrent
TORRENT_ASSERT(m_torrent_file->num_files() > 0);
TORRENT_ASSERT(m_torrent_file->total_size() >= 0);
m_block_size = (std::min)(m_block_size, m_torrent_file->piece_length());
// the shared_from_this() will create an intentional
// cycle of ownership, se the hpp file for description.
m_owning_storage = new piece_manager(shared_from_this(), m_torrent_file
, m_save_path, m_ses.m_files, m_ses.m_disk_thread, m_storage_constructor
, m_storage_mode);
m_storage = m_owning_storage.get();
m_picker->init(m_torrent_file->piece_length() / m_block_size
m_picker->init((std::max)(m_torrent_file->piece_length() / m_block_size, 1)
, int((m_torrent_file->total_size()+m_block_size-1)/m_block_size));
std::vector<std::string> const& url_seeds = m_torrent_file->url_seeds();
@ -3350,6 +3352,8 @@ namespace libtorrent
TORRENT_ASSERT(total_done == m_torrent_file->total_size());
else
TORRENT_ASSERT(total_done != m_torrent_file->total_size() || !m_files_checked);
TORRENT_ASSERT(m_block_size <= m_torrent_file->piece_length());
}
else
{

View File

@ -164,7 +164,7 @@ boost::intrusive_ptr<T> clone_ptr(boost::intrusive_ptr<T> const& ptr)
return boost::intrusive_ptr<T>(new T(*ptr));
}
boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file)
boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file, int piece_size)
{
char const* tracker_url = "http://non-existent-name.com/announce";
@ -173,10 +173,10 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file)
file_storage fs;
int total_size = 2 * 1024 * 1024;
fs.add_file(path("temporary"), total_size);
libtorrent::create_torrent t(fs, 16 * 1024);
libtorrent::create_torrent t(fs, piece_size);
t.add_tracker(tracker_url);
std::vector<char> piece(16 * 1024);
std::vector<char> piece(piece_size);
for (int i = 0; i < int(piece.size()); ++i)
piece[i] = (i % 26) + 'A';
@ -204,7 +204,7 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file)
boost::tuple<torrent_handle, torrent_handle, torrent_handle>
setup_transfer(session* ses1, session* ses2, session* ses3
, bool clear_files, bool use_metadata_transfer, bool connect_peers
, std::string suffix)
, std::string suffix, int piece_size)
{
using namespace boost::filesystem;
@ -218,7 +218,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3
create_directory("./tmp1" + suffix);
std::ofstream file(("./tmp1" + suffix + "/temporary").c_str());
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file);
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, piece_size);
file.close();
if (clear_files)
{

View File

@ -10,13 +10,13 @@ void print_alerts(libtorrent::session& ses, char const* name
, bool allow_no_torrents = false);
void test_sleep(int millisec);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024);
boost::tuple<libtorrent::torrent_handle, libtorrent::torrent_handle
, libtorrent::torrent_handle>
setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2
, libtorrent::session* ses3, bool clear_files, bool use_metadata_transfer = true
, bool connect = true, std::string suffix = "");
, bool connect = true, std::string suffix = "", int piece_size = 16 * 1024);
void start_web_server(int port, bool ssl = false);
void stop_web_server(int port);

View File

@ -54,7 +54,8 @@ void test_swarm()
torrent_handle tor2;
torrent_handle tor3;
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, true, "_swarm");
// test using piece sizes smaller than 16kB
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, true, "_swarm", 8 * 1024);
float sum_dl_rate2 = 0.f;
float sum_dl_rate3 = 0.f;