2008-12-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed the bug that bad URI is sent to the tracker when the
	announe URI in torrent file includes query.
	* src/DefaultBtAnnounce.cc
	* test/DefaultBtAnnounceTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-12-09 11:51:07 +00:00
parent 1e6a579258
commit bd8645262d
3 changed files with 47 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2008-12-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that bad URI is sent to the tracker when the announe
URI in torrent file includes query.
* src/DefaultBtAnnounce.cc
* test/DefaultBtAnnounceTest.cc
2008-12-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added Option::blank().

View File

@ -53,6 +53,7 @@
#include "Option.h"
#include "StringFormat.h"
#include "A2STR.h"
#include "Request.h"
namespace aria2 {
@ -105,6 +106,13 @@ bool DefaultBtAnnounce::isAnnounceReady() {
isDefaultAnnounceReady();
}
static bool uriHasQuery(const std::string& uri)
{
Request req;
req.setUrl(uri);
return !req.getQuery().empty();
}
std::string DefaultBtAnnounce::getAnnounceUrl() {
if(isStoppedAnnounceReady()) {
if(!announceList.currentTierAcceptsStoppedEvent()) {
@ -134,8 +142,10 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
TransferStat stat = peerStorage->calculateStat();
uint64_t left =
pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
std::string url = announceList.getAnnounce()+
"?info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
std::string url = announceList.getAnnounce();
url += uriHasQuery(url) ? "&" : "?";
url +=
"info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
btContext->getInfoHashLength())+
"&peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+
"&uploaded="+Util::uitos(stat.getSessionUploadLength())+

View File

@ -22,6 +22,7 @@ class DefaultBtAnnounceTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
CPPUNIT_TEST(testGetAnnounceUrl);
CPPUNIT_TEST(testGetAnnounceUrl_withQuery);
CPPUNIT_TEST(testNoMoreAnnounce);
CPPUNIT_TEST(testIsAllAnnounceFailed);
CPPUNIT_TEST(testURLOrderInStoppedEvent);
@ -77,6 +78,7 @@ public:
}
void testGetAnnounceUrl();
void testGetAnnounceUrl_withQuery();
void testNoMoreAnnounce();
void testIsAllAnnounceFailed();
void testURLOrderInStoppedEvent();
@ -182,6 +184,32 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl()
CPPUNIT_ASSERT_EQUAL(std::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&supportcrypto=1"), btAnnounce.getAnnounceUrl());
}
void DefaultBtAnnounceTest::testGetAnnounceUrl_withQuery()
{
std::string trackerURI = "http://localhost/announce?k=v";
std::deque<std::string> uris;
uris.push_back(trackerURI);
SharedHandle<AnnounceTier> announceTier(new AnnounceTier(uris));
_btContext->addAnnounceTier(announceTier);
DefaultBtAnnounce btAnnounce(_btContext, _option);
btAnnounce.setPieceStorage(_pieceStorage);
btAnnounce.setPeerStorage(_peerStorage);
btAnnounce.setBtRuntime(_btRuntime);
btAnnounce.setRandomizer(SharedHandle<Randomizer>(new FixedNumberRandomizer()));
btAnnounce.generateKey();
CPPUNIT_ASSERT_EQUAL
(std::string("http://localhost/announce?k=v&"
"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&"
"supportcrypto=1"),
btAnnounce.getAnnounceUrl());
}
void DefaultBtAnnounceTest::testIsAllAnnounceFailed()
{
std::string trackerURI1 = "http://localhost/announce";