From 4403eac97b4b306a39b2d9ec72534ae085fd75f7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 8 Jul 2006 19:41:39 +0000 Subject: [PATCH] fixed bugs reported by Massaroddel. Tracker request peer-count could be incorrect. Empty files were not created in full allocation mode. --- ChangeLog | 3 +++ include/libtorrent/policy.hpp | 3 +-- src/file.cpp | 5 +++++ src/peer_connection.cpp | 20 ++++++++++++++++++++ src/policy.cpp | 3 +-- src/storage.cpp | 10 ++++++++++ 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 826158c45..4d4631f80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ release 0.10 + * fixed a bug where the requested number of peers in a tracker request could + be too big. + * fixed a bug where empty files were not created in full allocation mode. * fixed a bug in storage that would, in rare cases, fail to do a complete check. * exposed more settings for tweaking parameters in the piece-picker, diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 975180c61..1358e2bdf 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -171,7 +171,7 @@ namespace libtorrent int num_peers() const { - return m_num_peers; + return m_peers.size(); } int num_uploads() const @@ -223,7 +223,6 @@ namespace libtorrent std::vector m_peers; - int m_num_peers; torrent* m_torrent; // the number of unchoked peers diff --git a/src/file.cpp b/src/file.cpp index dd78e461c..082c77063 100755 --- a/src/file.cpp +++ b/src/file.cpp @@ -212,6 +212,11 @@ namespace libtorrent assert(m_open_mode & mode_out); assert(m_fd != -1); + // Test this a bit more, what happens with random failures in + // the files? +// if ((rand() % 100) > 80) +// throw file_error("debug"); + size_type ret = ::write(m_fd, buf, num_bytes); if (ret == -1) { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 1fb6407cc..cbb8d37d3 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/io.hpp" +#include "libtorrent/file.hpp" #include "libtorrent/version.hpp" using namespace boost::posix_time; @@ -1763,6 +1764,25 @@ namespace libtorrent setup_receive(); } + catch (file_error& e) + { + session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + + boost::shared_ptr t = m_torrent.lock(); + if (!t) + { + m_ses.connection_failed(m_socket, remote(), e.what()); + return; + } + + if (t->alerts().should_post(alert::fatal)) + { + t->alerts().post_alert( + file_error_alert(t->get_handle() + , std::string("torrent paused: ") + e.what())); + } + t->pause(); + } catch (std::exception& e) { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); diff --git a/src/policy.cpp b/src/policy.cpp index 728ecdaa0..31da5401d 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -350,8 +350,7 @@ namespace namespace libtorrent { policy::policy(torrent* t) - : m_num_peers(0) - , m_torrent(t) + : m_torrent(t) // , m_max_uploads(std::numeric_limits::max()) // , m_max_connections(std::numeric_limits::max()) , m_num_unchoked(0) diff --git a/src/storage.cpp b/src/storage.cpp index 3e83fcc0f..1eb80cc41 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1482,6 +1482,13 @@ namespace libtorrent end_iter = m_info.end_files(); file_iter != end_iter; ++file_iter) { path dir = (m_save_path / file_iter->path).branch_path(); + + // if the file is empty, just create it. But also make sure + // the directory exits. + if (dir == last_path + && file_iter->size == 0) + file(m_save_path / file_iter->path, file::out); + if (dir == last_path) continue; last_path = dir; @@ -1492,6 +1499,9 @@ namespace libtorrent if (!exists(last_path)) create_directories(last_path); #endif + + if (file_iter->size == 0) + file(m_save_path / file_iter->path, file::out); } m_current_slot = 0; m_state = state_full_check;