Skip to content

Commit

Permalink
Stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed Feb 1, 2025
1 parent 51025ed commit a4cc6d3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/torrent/tracker_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ TrackerController::stop_requesting() {

uint32_t
tracker_next_timeout(Tracker* tracker, int controller_flags) {
// TODO: Rewrite to be in tracker thread or atomic tracker state.
auto tracker_state = tracker->state();

if ((controller_flags & TrackerController::flag_requesting))
return tracker_next_timeout_promiscuous(tracker);

// TODO: Rewrite to be in tracker thread or atomic tracker state.
auto tracker_state = tracker->state();

if ((tracker->is_busy() && tracker_state.latest_event() != Tracker::EVENT_SCRAPE) ||
!tracker->is_usable())
return ~uint32_t();
Expand Down
10 changes: 7 additions & 3 deletions src/torrent/tracker_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,16 @@ TrackerList::find_next_to_request(iterator itr) {
auto itr_state = (*itr)->state();

if (itr_state.failed_counter() != 0) {
if (itr_state.failed_time_next() < preferred_state.failed_time_next())
if (itr_state.failed_time_next() < preferred_state.failed_time_next()) {
preferred = itr;
preferred_state = (*preferred)->state();
}

} else {
if (itr_state.success_time_next() < preferred_state.failed_time_next())
if (itr_state.success_time_next() < preferred_state.failed_time_next()) {
preferred = itr;
preferred_state = (*preferred)->state();
}

break;
}
Expand Down Expand Up @@ -289,7 +293,7 @@ TrackerList::receive_success(Tracker* tracker, AddressList* l) {

// Promote the tracker to the front of the group since it was
// successfull.
itr = promote(itr);
promote(itr);

l->sort();
l->erase(std::unique(l->begin(), l->end()), l->end());
Expand Down
21 changes: 2 additions & 19 deletions test/torrent/tracker_controller_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <iostream>

#include "rak/priority_queue_default.h"
#include "test/torrent/tracker_list_test.h"
#include "test/torrent/tracker_controller_test.h"

#include "globals.h"
#include "torrent/tracker_list_test.h"
#include "torrent/tracker_controller_test.h"

CPPUNIT_TEST_SUITE_REGISTRATION(tracker_controller_test);

Expand All @@ -16,8 +16,6 @@ test_goto_next_timeout(torrent::TrackerController* tracker_controller, uint32_t
uint32_t next_timeout = tracker_controller->task_timeout()->is_queued() ? tracker_controller->seconds_to_next_timeout() : ~uint32_t();
uint32_t next_scrape = tracker_controller->task_scrape()->is_queued() ? tracker_controller->seconds_to_next_scrape() : ~uint32_t();

std::cout << "test_goto_next_timeout: " << next_timeout << ' ' << next_scrape << ' ' << assumed_timeout << ' ' << is_scrape << std::endl;

if (next_timeout == next_scrape && next_timeout == ~uint32_t()) {
std::cout << "(nq)";
return false;
Expand Down Expand Up @@ -332,36 +330,23 @@ tracker_controller_test::test_multiple_failure() {
CPPUNIT_ASSERT(tracker_0_0->trigger_failure());
CPPUNIT_ASSERT(!tracker_controller.is_failure_mode());

std::cout << "test_multiple_failure: 1" << std::endl;
TEST_MULTI3_IS_BUSY("01000", "01000");
std::cout << "test_multiple_failure: 2" << std::endl;
CPPUNIT_ASSERT(tracker_0_1->trigger_failure());
std::cout << "test_multiple_failure: 3" << std::endl;
TEST_MULTI3_IS_BUSY("00100", "00100");
std::cout << "test_multiple_failure: 4" << std::endl;
CPPUNIT_ASSERT(tracker_1_0->trigger_success());

// CPPUNIT_ASSERT(test_goto_next_timeout(&tracker_controller, tracker_1_0->state().normal_interval()));
// TODO: Why are we checking 1_0? possible issue with default interval constrcutor.
CPPUNIT_ASSERT(test_goto_next_timeout(&tracker_controller, tracker_1_0->state().normal_interval()));

std::cout << "test_multiple_failure: 5" << std::endl;

TEST_MULTI3_IS_BUSY("10000", "10000");
CPPUNIT_ASSERT(tracker_0_0->trigger_failure());
std::cout << "test_multiple_failure: 5.1" << std::endl;
TEST_MULTI3_IS_BUSY("01000", "01000");
CPPUNIT_ASSERT(tracker_0_1->trigger_failure());

std::cout << "test_multiple_failure: 5.2" << std::endl;

CPPUNIT_ASSERT(!tracker_controller.is_failure_mode());
TEST_MULTI3_IS_BUSY("00100", "00100");
CPPUNIT_ASSERT(tracker_1_0->trigger_failure());
CPPUNIT_ASSERT(tracker_controller.is_failure_mode());

std::cout << "test_multiple_failure: 6" << std::endl;

TEST_MULTI3_IS_BUSY("00010", "00010");
CPPUNIT_ASSERT(tracker_2_0->trigger_failure());
TEST_MULTI3_IS_BUSY("00001", "00001");
Expand All @@ -377,8 +362,6 @@ tracker_controller_test::test_multiple_failure() {

// Try inserting some delays in order to test the timers.

std::cout << "test_multiple_failure: 7" << std::endl;

CPPUNIT_ASSERT(test_goto_next_timeout(&tracker_controller, 5));
TEST_MULTI3_IS_BUSY("00100", "00100");
CPPUNIT_ASSERT(tracker_1_0->trigger_success());
Expand Down
14 changes: 0 additions & 14 deletions test/torrent/tracker_list_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ TrackerTest::set_new_min_interval(uint32_t timeout) {

void
TrackerTest::send_state(int state) {
std::cout << "send_state: 0 " << this << " " << is_busy() << " " << is_open() << std::endl;

// Trackers close on-going requests when new state is sent.
m_busy = true;
m_open = true;
Expand All @@ -83,8 +81,6 @@ TrackerTest::send_state(int state) {

void
TrackerTest::send_scrape() {
std::cout << "send_scrape: 0 " << this << " " << is_busy() << " " << is_open() << std::endl;

// We ignore scrapes if we're already making a request.
// if (m_open)
// return;
Expand Down Expand Up @@ -137,26 +133,18 @@ TrackerTest::trigger_success(torrent::TrackerList::address_list* address_list, u

bool
TrackerTest::trigger_failure() {
std::cout << "trigger_failure: 0 " << this << " " << is_busy() << " " << is_open() << std::endl;

CPPUNIT_ASSERT(is_busy() && is_open());

if (parent() == NULL)
return false;

std::cout << "trigger_failure: 1" << std::endl;

m_busy = false;
m_open = !(m_flags & flag_close_on_done);
return_new_peers = 0;

if (state().latest_event() == EVENT_SCRAPE) {
std::cout << "trigger_failure: scrape:2" << std::endl;

parent()->receive_scrape_failed(this, "failed");
} else {
std::cout << "trigger_failure: normal:2" << std::endl;

auto tracker_state = state();
tracker_state.set_normal_interval(0);
tracker_state.set_min_interval(0);
Expand All @@ -165,8 +153,6 @@ TrackerTest::trigger_failure() {
parent()->receive_failed(this, "failed");
}

std::cout << "trigger_failure: 3" << std::endl;

m_requesting_state = -1;
return true;
}
Expand Down

0 comments on commit a4cc6d3

Please sign in to comment.