2007-11-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Do not rotate tiers in announce-list.
	* src/DefaultBtAnnounce.{h, cc}: Removed trackerNumTry.
	AnnounceList::allTiersFailed() used instead to detect whether 
all
	tiers are tried and failed.
	* test/DefaultBtAnnounceTest.cc
	* src/AnnounceList.{h, cc}: If all tiers are tried and failed 
then
	allTiersFailed() returns true. To reset tier pointer, call 
resetTier();
	* test/AnnounceListTest.cc
	* src/TrackerWatcherCommand.cc (execute): Removed DlAbortEx 
catch
	clause. Catch RecoverableException instead of DlRetryEx instead.
pull/1/head
Tatsuhiro Tsujikawa 2007-11-12 14:13:00 +00:00
parent 7c41d11be3
commit aef50efed0
8 changed files with 91 additions and 29 deletions

View File

@ -1,3 +1,16 @@
2007-11-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Do not rotate tiers in announce-list.
* src/DefaultBtAnnounce.{h, cc}: Removed trackerNumTry.
AnnounceList::allTiersFailed() used instead to detect whether all
tiers are tried and failed.
* test/DefaultBtAnnounceTest.cc
* src/AnnounceList.{h, cc}: If all tiers are tried and failed then
allTiersFailed() returns true. To reset tier pointer, call resetTier();
* test/AnnounceListTest.cc
* src/TrackerWatcherCommand.cc (execute): Removed DlAbortEx catch
clause. Catch RecoverableException instead of DlRetryEx instead.
2007-11-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented checksum validation feature(1 checksum for each file)

View File

@ -103,16 +103,16 @@ void AnnounceList::announceSuccess() {
}
}
// TODO if currentTier reaches tiers.end(), then getAllTierTried() returns true
void AnnounceList::announceFailure() {
if(currentTrackerInitialized) {
currentTracker++;
if(currentTracker == (*currentTier)->urls.end()) {
currentTier++;
if(currentTier == tiers.end()) {
currentTier = tiers.begin();
currentTrackerInitialized = false;
} else {
currentTracker = (*currentTier)->urls.begin();
}
currentTracker = (*currentTier)->urls.begin();
}
}
}
@ -225,3 +225,13 @@ void AnnounceList::shuffle() {
random_shuffle(urls.begin(), urls.end());
}
}
bool AnnounceList::allTiersFailed() const
{
return currentTier == tiers.end();
}
void AnnounceList::resetTier()
{
resetIterator();
}

View File

@ -115,6 +115,10 @@ public:
*/
void moveToStoppedAllowedTier();
void moveToCompletedAllowedTier();
bool allTiersFailed() const;
void resetTier();
};
#endif // _D_ANNOUNCE_LIST_H_

View File

@ -55,7 +55,6 @@ DefaultBtAnnounce::DefaultBtAnnounce(BtContextHandle btContext,
complete(0),
incomplete(0),
announceList(btContext->getAnnounceTiers()),
trackerNumTry(0),
option(option),
logger(LogFactory::getInstance()),
_randomizer(SimpleRandomizer::getInstance()),
@ -76,7 +75,8 @@ void DefaultBtAnnounce::generateKey()
}
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
return (trackers == 0 && prevAnnounceTime.elapsed(minInterval));
return (trackers == 0 && prevAnnounceTime.elapsed(minInterval) &&
!announceList.allTiersFailed());
}
bool DefaultBtAnnounce::isStoppedAnnounceReady() {
@ -113,6 +113,8 @@ string DefaultBtAnnounce::getAnnounceUrl() {
announceList.getEvent() == AnnounceTier::STARTED) {
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
}
} else {
return "";
}
int32_t numWant = 50;
if(!btRuntime->lessThanEqMinPeer() ||
@ -160,18 +162,16 @@ void DefaultBtAnnounce::announceSuccess() {
void DefaultBtAnnounce::announceFailure() {
trackers = 0;
trackerNumTry++;
announceList.announceFailure();
}
bool DefaultBtAnnounce::isAllAnnounceFailed() {
return
trackerNumTry >= option->getAsInt(PREF_TRACKER_MAX_TRIES);
return announceList.allTiersFailed();
}
void DefaultBtAnnounce::resetAnnounce() {
prevAnnounceTime.reset();
trackerNumTry = 0;
announceList.resetTier();
}
void

View File

@ -62,7 +62,6 @@ private:
AnnounceList announceList;
string trackerId;
string key;
int32_t trackerNumTry;
const Option* option;
Logger* logger;
RandomizerHandle _randomizer;

View File

@ -71,8 +71,6 @@ bool TrackerWatcherCommand::execute() {
if(_trackerRequestGroup.isNull()) {
_trackerRequestGroup = createAnnounce();
if(!_trackerRequestGroup.isNull()) {
//e->_requestGroupMan->addReservedGroup(_trackerRequestGroup);
//e->_requestGroupMan->fillRequestGroupFromReserver(e);
e->addCommand(_trackerRequestGroup->createInitialCommand(e));
logger->debug("added tracker request command");
}
@ -83,13 +81,7 @@ bool TrackerWatcherCommand::execute() {
processTrackerResponse(trackerResponse);
btAnnounce->announceSuccess();
btAnnounce->resetAnnounce();
} catch(DlAbortEx* ex) {
logger->error(EX_EXCEPTION_CAUGHT, ex);
delete ex;
btAnnounce->announceFailure();
btAnnounce->resetAnnounce();
} catch(DlRetryEx* ex) {
// TODO Can I remove this catch clause?
} catch(RecoverableException* ex) {
logger->error(EX_EXCEPTION_CAUGHT, ex);
delete ex;
btAnnounce->announceFailure();

View File

@ -44,7 +44,8 @@ void AnnounceListTest::testSingleElementList() {
// ANNOUNCE_LIST
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces);
CPPUNIT_ASSERT(!announceList.allTiersFailed());
string url = announceList.getAnnounce();
string event = announceList.getEventString();
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
@ -56,6 +57,9 @@ void AnnounceListTest::testSingleElementList() {
url = announceList.getAnnounce();
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
announceList.announceFailure();
CPPUNIT_ASSERT(announceList.allTiersFailed());
announceList.resetTier();
CPPUNIT_ASSERT(!announceList.allTiersFailed());
// back to the first list
url = announceList.getAnnounce();
event = announceList.getEventString();
@ -86,6 +90,7 @@ void AnnounceListTest::testMultiElementList() {
// [ [ tracker1, tracker2, tracker3 ] ]
AnnounceList announceList(announces);
CPPUNIT_ASSERT(!announceList.allTiersFailed());
string url = announceList.getAnnounce();
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
announceList.announceFailure();
@ -102,8 +107,11 @@ void AnnounceListTest::testMultiElementList() {
url = announceList.getAnnounce();
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
announceList.announceFailure();
url = announceList.getAnnounce();
CPPUNIT_ASSERT(announceList.allTiersFailed());
announceList.resetTier();
CPPUNIT_ASSERT(!announceList.allTiersFailed());
// back to the first list because there is no other list.
url = announceList.getAnnounce();
CPPUNIT_ASSERT_EQUAL(string("tracker2"), url);
}

View File

@ -16,9 +16,9 @@ using namespace std;
class DefaultBtAnnounceTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
CPPUNIT_TEST(testIsDefaultAnnounceReady);
CPPUNIT_TEST(testGetAnnounceUrl);
CPPUNIT_TEST(testNoMoreAnnounce);
CPPUNIT_TEST(testIsAllAnnounceFailed);
CPPUNIT_TEST_SUITE_END();
private:
MockBtContextHandle _btContext;
@ -71,20 +71,14 @@ public:
delete _option;
}
void testIsDefaultAnnounceReady();
void testGetAnnounceUrl();
void testNoMoreAnnounce();
void testIsAllAnnounceFailed();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtAnnounceTest);
void DefaultBtAnnounceTest::testIsDefaultAnnounceReady() {
DefaultBtAnnounce btAnnounce(_btContext, _option);
CPPUNIT_ASSERT(btAnnounce.isDefaultAnnounceReady());
}
void DefaultBtAnnounceTest::testNoMoreAnnounce()
{
string trackerURI1 = "http://localhost/announce";
@ -139,6 +133,8 @@ void DefaultBtAnnounceTest::testNoMoreAnnounce()
CPPUNIT_ASSERT_EQUAL(string("http://backup/announce?info_hash=%01%23Eg%89%ab%cd%ef%01%23Eg%89%ab%cd%ef%01%23Eg&peer_id=%2daria2%2dultrafastdltl&uploaded=1572864&downloaded=1310720&left=1572864&compact=1&key=AAAAAAAA&numwant=0&no_peer_id=1&port=6989&event=stopped"), btAnnounce.getAnnounceUrl());
btAnnounce.announceSuccess();
CPPUNIT_ASSERT(btAnnounce.noMoreAnnounce());
}
void DefaultBtAnnounceTest::testGetAnnounceUrl()
@ -175,3 +171,43 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl()
CPPUNIT_ASSERT_EQUAL(string("http://localhost/announce?info_hash=%01%23Eg%89%ab%cd%ef%01%23Eg%89%ab%cd%ef%01%23Eg&peer_id=%2daria2%2dultrafastdltl&uploaded=1572864&downloaded=1310720&left=1572864&compact=1&key=AAAAAAAA&numwant=0&no_peer_id=1&port=6989&event=stopped"), btAnnounce.getAnnounceUrl());
}
void DefaultBtAnnounceTest::testIsAllAnnounceFailed()
{
string trackerURI1 = "http://localhost/announce";
Strings uris1;
uris1.push_back(trackerURI1);
AnnounceTierHandle announceTier1 = new AnnounceTier(uris1);
string trackerURI2 = "http://backup/announce";
Strings uris2;
uris2.push_back(trackerURI2);
AnnounceTierHandle announceTier2 = new AnnounceTier(uris2);
_btContext->addAnnounceTier(announceTier1);
_btContext->addAnnounceTier(announceTier2);
DefaultBtAnnounce btAnnounce(_btContext, _option);
btAnnounce.setPieceStorage(_pieceStorage);
btAnnounce.setPeerStorage(_peerStorage);
btAnnounce.setBtRuntime(_btRuntime);
btAnnounce.setRandomizer(new FixedNumberRandomizer());
btAnnounce.generateKey();
CPPUNIT_ASSERT_EQUAL(string("http://localhost/announce?info_hash=%01%23Eg%89%ab%cd%ef%01%23Eg%89%ab%cd%ef%01%23Eg&peer_id=%2daria2%2dultrafastdltl&uploaded=1572864&downloaded=1310720&left=1572864&compact=1&key=AAAAAAAA&numwant=50&no_peer_id=1&port=6989&event=started"), btAnnounce.getAnnounceUrl());
btAnnounce.announceFailure();
CPPUNIT_ASSERT_EQUAL(string("http://backup/announce?info_hash=%01%23Eg%89%ab%cd%ef%01%23Eg%89%ab%cd%ef%01%23Eg&peer_id=%2daria2%2dultrafastdltl&uploaded=1572864&downloaded=1310720&left=1572864&compact=1&key=AAAAAAAA&numwant=50&no_peer_id=1&port=6989&event=started"), btAnnounce.getAnnounceUrl());
btAnnounce.announceFailure();
CPPUNIT_ASSERT(!btAnnounce.isAnnounceReady());
CPPUNIT_ASSERT_EQUAL(string(""), btAnnounce.getAnnounceUrl());
CPPUNIT_ASSERT(btAnnounce.isAllAnnounceFailed());
btAnnounce.resetAnnounce();
CPPUNIT_ASSERT(!btAnnounce.isAllAnnounceFailed());
}