diff --git a/ChangeLog b/ChangeLog index 846ec34b..f5b96892 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-09-02 Tatsuhiro Tsujikawa + + Contact tracker frequently when the number of connections are 0 and + download is not finished yet. + * src/ActivePeerConnectionCommand.cc + * src/BtAnnounce.h + * src/DefaultBtAnnounce.cc + * src/DefaultBtAnnounce.h + * test/MockBtAnnounce.h + 2008-09-02 Tatsuhiro Tsujikawa Moved threthold values to UTPexExtensionMessage. diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index e89693c7..5f4c5734 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -47,6 +47,7 @@ #include "Option.h" #include "BtConstants.h" #include "SocketCore.h" +#include "BtAnnounce.h" namespace aria2 { @@ -96,6 +97,10 @@ bool ActivePeerConnectionCommand::execute() { PeerHandle peer = peerStorage->getUnusedPeer(); connectToPeer(peer); } + if(btRuntime->getConnections() == 0 && + !pieceStorage->downloadFinished()) { + btAnnounce->overrideMinInterval(BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL); + } } } e->commands.push_back(this); diff --git a/src/BtAnnounce.h b/src/BtAnnounce.h index e7c76109..1eb6978f 100644 --- a/src/BtAnnounce.h +++ b/src/BtAnnounce.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include "a2time.h" #include namespace aria2 { @@ -104,6 +105,8 @@ public: */ virtual void shuffleAnnounce() = 0; + virtual void overrideMinInterval(time_t interval) = 0; + static const std::string FAILURE_REASON; static const std::string WARNING_MESSAGE; @@ -119,6 +122,8 @@ public: static const std::string INCOMPLETE; static const std::string PEERS; + + static const unsigned int DEFAULT_ANNOUNCE_INTERVAL = 120; }; typedef SharedHandle BtAnnounceHandle; diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index d7047b2f..6b9b9784 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -316,4 +316,9 @@ PeerStorageHandle DefaultBtAnnounce::getPeerStorage() const return peerStorage; } +void DefaultBtAnnounce::overrideMinInterval(time_t interval) +{ + minInterval = interval; +} + } // namespace aria2 diff --git a/src/DefaultBtAnnounce.h b/src/DefaultBtAnnounce.h index 40ce0c0a..dac1c4cc 100644 --- a/src/DefaultBtAnnounce.h +++ b/src/DefaultBtAnnounce.h @@ -67,9 +67,6 @@ private: SharedHandle btRuntime; SharedHandle pieceStorage; SharedHandle peerStorage; - - static const unsigned int DEFAULT_ANNOUNCE_INTERVAL = 120; - public: DefaultBtAnnounce(const SharedHandle& btContext, const Option* option); @@ -115,6 +112,8 @@ public: virtual void shuffleAnnounce(); + virtual void overrideMinInterval(time_t interval); + void generateKey(); void setRandomizer(const SharedHandle& randomizer); diff --git a/test/MockBtAnnounce.h b/test/MockBtAnnounce.h index 3d596b80..790a6c6b 100644 --- a/test/MockBtAnnounce.h +++ b/test/MockBtAnnounce.h @@ -56,6 +56,8 @@ public: return peerId; } + virtual void overrideMinInterval(time_t interval) {} + void setPeerId(const std::string& peerId) { this->peerId = peerId; }