Skip to content

Commit

Permalink
git-svn-id: svn://rakshasa.no/libtorrent/trunk/libtorrent@163 e378c89…
Browse files Browse the repository at this point in the history
…8-3ddf-0310-93e7-cc216c733640
  • Loading branch information
rakshasa committed Nov 22, 2004
1 parent 3b7c6e8 commit c4468a9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
6 changes: 2 additions & 4 deletions BUGS
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
3 changes: 1 addition & 2 deletions src/content/delegator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
28 changes: 24 additions & 4 deletions src/download_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -110,6 +111,8 @@ void DownloadMain::stop() {
delete m_state.connections().front();
m_state.connections().pop_front();
}

setup_stop();
}

void DownloadMain::service(int type) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

}
10 changes: 10 additions & 0 deletions src/download_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "download_state.h"
#include "download/download_net.h"

#include <sigc++/slot.h>

namespace torrent {

class TrackerControl;
Expand Down Expand Up @@ -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;
Expand All @@ -67,6 +72,11 @@ class DownloadMain : public Service {
bool m_started;

SignalTrackerSucceded m_signalTrackerSucceded;

typedef sigc::slot1<void, uint32_t> SlotChunk;

SlotChunk m_slotChunkPassed;
SlotChunk m_slotChunkFailed;
};

} // namespace torrent
Expand Down
11 changes: 5 additions & 6 deletions src/download_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ class DownloadState {

typedef sigc::signal1<void, Peer> SignalPeerConnected;
typedef sigc::signal1<void, Peer> SignalPeerDisconnected;
typedef sigc::signal1<void, uint32_t> SignalChunkPassed;
typedef sigc::signal1<void, uint32_t> SignalChunkFailed;
typedef sigc::signal1<void, uint32_t> 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
Expand All @@ -95,8 +94,8 @@ class DownloadState {

SignalPeerConnected m_signalPeerConnected;
SignalPeerDisconnected m_signalPeerDisconnected;
SignalChunkPassed m_signalChunkPassed;
SignalChunkFailed m_signalChunkFailed;
SignalChunk m_signalChunkPassed;
SignalChunk m_signalChunkFailed;
};

}
Expand Down
1 change: 1 addition & 0 deletions src/peer_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c4468a9

Please sign in to comment.