mirror of https://github.com/aria2/aria2
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
parent
7c41d11be3
commit
aef50efed0
13
ChangeLog
13
ChangeLog
|
@ -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>
|
2007-11-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Implemented checksum validation feature(1 checksum for each file)
|
Implemented checksum validation feature(1 checksum for each file)
|
||||||
|
|
|
@ -103,16 +103,16 @@ void AnnounceList::announceSuccess() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO if currentTier reaches tiers.end(), then getAllTierTried() returns true
|
|
||||||
void AnnounceList::announceFailure() {
|
void AnnounceList::announceFailure() {
|
||||||
if(currentTrackerInitialized) {
|
if(currentTrackerInitialized) {
|
||||||
currentTracker++;
|
currentTracker++;
|
||||||
if(currentTracker == (*currentTier)->urls.end()) {
|
if(currentTracker == (*currentTier)->urls.end()) {
|
||||||
currentTier++;
|
currentTier++;
|
||||||
if(currentTier == tiers.end()) {
|
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());
|
random_shuffle(urls.begin(), urls.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AnnounceList::allTiersFailed() const
|
||||||
|
{
|
||||||
|
return currentTier == tiers.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnnounceList::resetTier()
|
||||||
|
{
|
||||||
|
resetIterator();
|
||||||
|
}
|
||||||
|
|
|
@ -115,6 +115,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void moveToStoppedAllowedTier();
|
void moveToStoppedAllowedTier();
|
||||||
void moveToCompletedAllowedTier();
|
void moveToCompletedAllowedTier();
|
||||||
|
|
||||||
|
bool allTiersFailed() const;
|
||||||
|
|
||||||
|
void resetTier();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_ANNOUNCE_LIST_H_
|
#endif // _D_ANNOUNCE_LIST_H_
|
||||||
|
|
|
@ -55,7 +55,6 @@ DefaultBtAnnounce::DefaultBtAnnounce(BtContextHandle btContext,
|
||||||
complete(0),
|
complete(0),
|
||||||
incomplete(0),
|
incomplete(0),
|
||||||
announceList(btContext->getAnnounceTiers()),
|
announceList(btContext->getAnnounceTiers()),
|
||||||
trackerNumTry(0),
|
|
||||||
option(option),
|
option(option),
|
||||||
logger(LogFactory::getInstance()),
|
logger(LogFactory::getInstance()),
|
||||||
_randomizer(SimpleRandomizer::getInstance()),
|
_randomizer(SimpleRandomizer::getInstance()),
|
||||||
|
@ -76,7 +75,8 @@ void DefaultBtAnnounce::generateKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
||||||
return (trackers == 0 && prevAnnounceTime.elapsed(minInterval));
|
return (trackers == 0 && prevAnnounceTime.elapsed(minInterval) &&
|
||||||
|
!announceList.allTiersFailed());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultBtAnnounce::isStoppedAnnounceReady() {
|
bool DefaultBtAnnounce::isStoppedAnnounceReady() {
|
||||||
|
@ -113,6 +113,8 @@ string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
announceList.getEvent() == AnnounceTier::STARTED) {
|
announceList.getEvent() == AnnounceTier::STARTED) {
|
||||||
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
|
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
int32_t numWant = 50;
|
int32_t numWant = 50;
|
||||||
if(!btRuntime->lessThanEqMinPeer() ||
|
if(!btRuntime->lessThanEqMinPeer() ||
|
||||||
|
@ -160,18 +162,16 @@ void DefaultBtAnnounce::announceSuccess() {
|
||||||
|
|
||||||
void DefaultBtAnnounce::announceFailure() {
|
void DefaultBtAnnounce::announceFailure() {
|
||||||
trackers = 0;
|
trackers = 0;
|
||||||
trackerNumTry++;
|
|
||||||
announceList.announceFailure();
|
announceList.announceFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultBtAnnounce::isAllAnnounceFailed() {
|
bool DefaultBtAnnounce::isAllAnnounceFailed() {
|
||||||
return
|
return announceList.allTiersFailed();
|
||||||
trackerNumTry >= option->getAsInt(PREF_TRACKER_MAX_TRIES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtAnnounce::resetAnnounce() {
|
void DefaultBtAnnounce::resetAnnounce() {
|
||||||
prevAnnounceTime.reset();
|
prevAnnounceTime.reset();
|
||||||
trackerNumTry = 0;
|
announceList.resetTier();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -62,7 +62,6 @@ private:
|
||||||
AnnounceList announceList;
|
AnnounceList announceList;
|
||||||
string trackerId;
|
string trackerId;
|
||||||
string key;
|
string key;
|
||||||
int32_t trackerNumTry;
|
|
||||||
const Option* option;
|
const Option* option;
|
||||||
Logger* logger;
|
Logger* logger;
|
||||||
RandomizerHandle _randomizer;
|
RandomizerHandle _randomizer;
|
||||||
|
|
|
@ -71,8 +71,6 @@ bool TrackerWatcherCommand::execute() {
|
||||||
if(_trackerRequestGroup.isNull()) {
|
if(_trackerRequestGroup.isNull()) {
|
||||||
_trackerRequestGroup = createAnnounce();
|
_trackerRequestGroup = createAnnounce();
|
||||||
if(!_trackerRequestGroup.isNull()) {
|
if(!_trackerRequestGroup.isNull()) {
|
||||||
//e->_requestGroupMan->addReservedGroup(_trackerRequestGroup);
|
|
||||||
//e->_requestGroupMan->fillRequestGroupFromReserver(e);
|
|
||||||
e->addCommand(_trackerRequestGroup->createInitialCommand(e));
|
e->addCommand(_trackerRequestGroup->createInitialCommand(e));
|
||||||
logger->debug("added tracker request command");
|
logger->debug("added tracker request command");
|
||||||
}
|
}
|
||||||
|
@ -83,13 +81,7 @@ bool TrackerWatcherCommand::execute() {
|
||||||
processTrackerResponse(trackerResponse);
|
processTrackerResponse(trackerResponse);
|
||||||
btAnnounce->announceSuccess();
|
btAnnounce->announceSuccess();
|
||||||
btAnnounce->resetAnnounce();
|
btAnnounce->resetAnnounce();
|
||||||
} catch(DlAbortEx* ex) {
|
} catch(RecoverableException* ex) {
|
||||||
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
|
||||||
delete ex;
|
|
||||||
btAnnounce->announceFailure();
|
|
||||||
btAnnounce->resetAnnounce();
|
|
||||||
} catch(DlRetryEx* ex) {
|
|
||||||
// TODO Can I remove this catch clause?
|
|
||||||
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||||
delete ex;
|
delete ex;
|
||||||
btAnnounce->announceFailure();
|
btAnnounce->announceFailure();
|
||||||
|
|
|
@ -44,7 +44,8 @@ void AnnounceListTest::testSingleElementList() {
|
||||||
// ANNOUNCE_LIST
|
// ANNOUNCE_LIST
|
||||||
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
|
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
|
||||||
AnnounceList announceList(announces);
|
AnnounceList announceList(announces);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(!announceList.allTiersFailed());
|
||||||
string url = announceList.getAnnounce();
|
string url = announceList.getAnnounce();
|
||||||
string event = announceList.getEventString();
|
string event = announceList.getEventString();
|
||||||
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
|
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
|
||||||
|
@ -56,6 +57,9 @@ void AnnounceListTest::testSingleElementList() {
|
||||||
url = announceList.getAnnounce();
|
url = announceList.getAnnounce();
|
||||||
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
|
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
|
||||||
announceList.announceFailure();
|
announceList.announceFailure();
|
||||||
|
CPPUNIT_ASSERT(announceList.allTiersFailed());
|
||||||
|
announceList.resetTier();
|
||||||
|
CPPUNIT_ASSERT(!announceList.allTiersFailed());
|
||||||
// back to the first list
|
// back to the first list
|
||||||
url = announceList.getAnnounce();
|
url = announceList.getAnnounce();
|
||||||
event = announceList.getEventString();
|
event = announceList.getEventString();
|
||||||
|
@ -86,6 +90,7 @@ void AnnounceListTest::testMultiElementList() {
|
||||||
// [ [ tracker1, tracker2, tracker3 ] ]
|
// [ [ tracker1, tracker2, tracker3 ] ]
|
||||||
AnnounceList announceList(announces);
|
AnnounceList announceList(announces);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(!announceList.allTiersFailed());
|
||||||
string url = announceList.getAnnounce();
|
string url = announceList.getAnnounce();
|
||||||
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
|
CPPUNIT_ASSERT_EQUAL(string("tracker1"), url);
|
||||||
announceList.announceFailure();
|
announceList.announceFailure();
|
||||||
|
@ -102,8 +107,11 @@ void AnnounceListTest::testMultiElementList() {
|
||||||
url = announceList.getAnnounce();
|
url = announceList.getAnnounce();
|
||||||
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
|
CPPUNIT_ASSERT_EQUAL(string("tracker3"), url);
|
||||||
announceList.announceFailure();
|
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.
|
// back to the first list because there is no other list.
|
||||||
|
url = announceList.getAnnounce();
|
||||||
CPPUNIT_ASSERT_EQUAL(string("tracker2"), url);
|
CPPUNIT_ASSERT_EQUAL(string("tracker2"), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ using namespace std;
|
||||||
class DefaultBtAnnounceTest:public CppUnit::TestFixture {
|
class DefaultBtAnnounceTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
|
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
|
||||||
CPPUNIT_TEST(testIsDefaultAnnounceReady);
|
|
||||||
CPPUNIT_TEST(testGetAnnounceUrl);
|
CPPUNIT_TEST(testGetAnnounceUrl);
|
||||||
CPPUNIT_TEST(testNoMoreAnnounce);
|
CPPUNIT_TEST(testNoMoreAnnounce);
|
||||||
|
CPPUNIT_TEST(testIsAllAnnounceFailed);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
MockBtContextHandle _btContext;
|
MockBtContextHandle _btContext;
|
||||||
|
@ -71,20 +71,14 @@ public:
|
||||||
delete _option;
|
delete _option;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testIsDefaultAnnounceReady();
|
|
||||||
void testGetAnnounceUrl();
|
void testGetAnnounceUrl();
|
||||||
void testNoMoreAnnounce();
|
void testNoMoreAnnounce();
|
||||||
|
void testIsAllAnnounceFailed();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtAnnounceTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtAnnounceTest);
|
||||||
|
|
||||||
void DefaultBtAnnounceTest::testIsDefaultAnnounceReady() {
|
|
||||||
DefaultBtAnnounce btAnnounce(_btContext, _option);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT(btAnnounce.isDefaultAnnounceReady());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtAnnounceTest::testNoMoreAnnounce()
|
void DefaultBtAnnounceTest::testNoMoreAnnounce()
|
||||||
{
|
{
|
||||||
string trackerURI1 = "http://localhost/announce";
|
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());
|
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();
|
btAnnounce.announceSuccess();
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(btAnnounce.noMoreAnnounce());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtAnnounceTest::testGetAnnounceUrl()
|
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());
|
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());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue