Skip to content

Commit

Permalink
Don't start requesting more peers if connected to PEX-enabled peers.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed Dec 19, 2012
1 parent 4202ad3 commit c2bc7f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/download/download_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,24 @@ DownloadMain::receive_tracker_success() {
return;

priority_queue_erase(&taskScheduler, &m_taskTrackerRequest);
priority_queue_insert(&taskScheduler, &m_taskTrackerRequest, (cachedTime + rak::timer::from_seconds(30)).round_seconds());
priority_queue_insert(&taskScheduler, &m_taskTrackerRequest, (cachedTime + rak::timer::from_seconds(10)).round_seconds());
}

void
DownloadMain::receive_tracker_request() {
if (connection_list()->size() + peer_list()->available_list()->size() / 2 >= connection_list()->min_size()) {
m_tracker_controller->stop_requesting();
return;
}
bool should_stop = false;
bool should_start = false;

m_tracker_controller->start_requesting();
if (info()->is_pex_enabled() && info()->size_pex() > 0)
should_stop = true;

if (connection_list()->size() + peer_list()->available_list()->size() / 2 < connection_list()->min_size())
should_start = true;

if (should_stop)
m_tracker_controller->stop_requesting();
else if (should_start)
m_tracker_controller->start_requesting();
}

struct SocketAddressCompact_less {
Expand Down
8 changes: 5 additions & 3 deletions src/torrent/tracker_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,20 @@ TrackerController::disable() {

void
TrackerController::start_requesting() {
if (!(m_flags & flag_active) || (m_flags & flag_requesting))
if ((m_flags & flag_requesting))
return;

m_flags |= flag_requesting;
update_timeout(0);

if ((m_flags & flag_active))
update_timeout(0);

LT_LOG_TRACKER(INFO, "Start requesting.", 0);
}

void
TrackerController::stop_requesting() {
if (!(m_flags & flag_active) || !(m_flags & flag_requesting))
if (!(m_flags & flag_requesting))
return;

m_flags &= ~flag_requesting;
Expand Down

0 comments on commit c2bc7f9

Please sign in to comment.