diff --git a/BUGS b/BUGS index 401999e56..346ed4b27 100644 --- a/BUGS +++ b/BUGS @@ -1,7 +1,3 @@ -Stop/start/stop/start'ing it, dunno - -test.cc caught "DelegatorPiece dtor called on an object that still has a reservee" - 0 rtorrent [0x806ddc5] 1 /lib/tls/libc.so.6 [0x39eeb8] 2 /uio/platon/mn-l2/jaris/local/lib/libcurl.so.3(Curl_cache_addr+0x71) [0x1e0311] @@ -13,3 +9,5 @@ test.cc caught "DelegatorPiece dtor called on an object that still has a reserve 8 rtorrent [0x806ebd8] 9 /lib/tls/libc.so.6(__libc_start_main+0xed) [0x38c79d] 10 rtorrent(dlopen+0x45) [0x8065931] + +Incoming connections connect to hash-checking downloads, fixme \ No newline at end of file diff --git a/src/content/delegator.cc b/src/content/delegator.cc index 79a8bd83e..0fe7742a9 100644 --- a/src/content/delegator.cc +++ b/src/content/delegator.cc @@ -110,8 +110,7 @@ void Delegator::done(int index) { eq(call_member(&DelegatorChunk::get_index), value((unsigned int)index))); if (itr == m_chunks.end()) - //throw internal_error("Called Delegator::done(...) with an index that is not in the Delegator"); - return; + throw internal_error("Called Delegator::done(...) with an index that is not in the Delegator"); m_select.remove_ignore((*itr)->get_index()); diff --git a/src/download_main.cc b/src/download_main.cc index d54f45774..edbc3bd3f 100644 --- a/src/download_main.cc +++ b/src/download_main.cc @@ -87,15 +87,16 @@ void DownloadMain::start() { if (m_started) return; - if (m_checked) + if (m_checked) { m_tracker->send_state(TRACKER_STARTED); + setup_start(); + } m_started = true; insert_service(Timer::current() + state().settings().chokeCycle * 2, CHOKE_CYCLE); } - void DownloadMain::stop() { if (!m_started) return; @@ -110,6 +111,8 @@ void DownloadMain::stop() { delete m_state.connections().front(); m_state.connections().pop_front(); } + + setup_stop(); } void DownloadMain::service(int type) { @@ -240,12 +243,17 @@ void DownloadMain::add_peers(const Peers& p) { } void DownloadMain::receive_initial_hash(const std::string& id) { + if (m_checked) + throw internal_error("DownloadMain::receive_initial_hash called but m_checked == true"); + if (id != state().hash()) throw internal_error("DownloadMain::receive_initial_hash received wrong id"); m_checked = true; state().content().resize(); + setup_start(); + if (m_state.content().get_chunks_completed() == m_state.content().get_storage().get_chunkcount() && !m_state.content().get_bitfield().allSet()) throw internal_error("Loaded torrent is done but bitfield isn't all set"); @@ -278,8 +286,8 @@ DownloadMain::setup_delegator() { m_net.get_delegator().signal_chunk_done().connect(sigc::mem_fun(m_state, &DownloadState::chunk_done)); m_net.get_delegator().slot_chunk_size(sigc::mem_fun(m_state.content(), &Content::get_chunksize)); - m_state.signal_chunk_passed().connect(sigc::mem_fun(m_net.get_delegator(), &Delegator::done)); - m_state.signal_chunk_failed().connect(sigc::mem_fun(m_net.get_delegator(), &Delegator::redo)); + m_slotChunkPassed = sigc::mem_fun(m_net.get_delegator(), &Delegator::done); + m_slotChunkFailed = sigc::mem_fun(m_net.get_delegator(), &Delegator::redo); } void @@ -308,4 +316,16 @@ DownloadMain::setup_tracker(const bencode& b) { m_tracker->slot_stat_left(sigc::mem_fun(m_state, &DownloadState::bytes_left)); } +void +DownloadMain::setup_start() { + m_state.signal_chunk_passed().connect(m_slotChunkPassed); + m_state.signal_chunk_failed().connect(m_slotChunkFailed); +} + +void +DownloadMain::setup_stop() { + m_slotChunkPassed.disconnect(); + m_slotChunkFailed.disconnect(); +} + } diff --git a/src/download_main.h b/src/download_main.h index b01ef12df..0df44f4a2 100644 --- a/src/download_main.h +++ b/src/download_main.h @@ -6,6 +6,8 @@ #include "download_state.h" #include "download/download_net.h" +#include + namespace torrent { class TrackerControl; @@ -56,6 +58,9 @@ class DownloadMain : public Service { void setup_net(); void setup_tracker(const bencode& b); + void setup_start(); + void setup_stop(); + static Downloads m_downloads; DownloadState m_state; @@ -67,6 +72,11 @@ class DownloadMain : public Service { bool m_started; SignalTrackerSucceded m_signalTrackerSucceded; + + typedef sigc::slot1 SlotChunk; + + SlotChunk m_slotChunkPassed; + SlotChunk m_slotChunkFailed; }; } // namespace torrent diff --git a/src/download_state.h b/src/download_state.h index 3f893b7fd..f3a4cc827 100644 --- a/src/download_state.h +++ b/src/download_state.h @@ -65,13 +65,12 @@ class DownloadState { typedef sigc::signal1 SignalPeerConnected; typedef sigc::signal1 SignalPeerDisconnected; - typedef sigc::signal1 SignalChunkPassed; - typedef sigc::signal1 SignalChunkFailed; + typedef sigc::signal1 SignalChunk; SignalPeerConnected& signal_peer_connected() { return m_signalPeerConnected; } SignalPeerConnected& signal_peer_disconnected() { return m_signalPeerDisconnected; } - SignalChunkPassed& signal_chunk_passed() { return m_signalChunkPassed; } - SignalChunkFailed& signal_chunk_failed() { return m_signalChunkFailed; } + SignalChunk& signal_chunk_passed() { return m_signalChunkPassed; } + SignalChunk& signal_chunk_failed() { return m_signalChunkFailed; } private: // Disable @@ -95,8 +94,8 @@ class DownloadState { SignalPeerConnected m_signalPeerConnected; SignalPeerDisconnected m_signalPeerDisconnected; - SignalChunkPassed m_signalChunkPassed; - SignalChunkFailed m_signalChunkFailed; + SignalChunk m_signalChunkPassed; + SignalChunk m_signalChunkFailed; }; } diff --git a/src/peer_connection.cc b/src/peer_connection.cc index b2c3e262a..48e4eabd4 100644 --- a/src/peer_connection.cc +++ b/src/peer_connection.cc @@ -655,6 +655,7 @@ void PeerConnection::sendHave(int index) { } } else if (m_up.interested && !m_net->get_delegator().get_select().interested(m_bitfield)) { + // TODO: Optimize? m_sendInterested = true; m_up.interested = false; }