mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
1e6a579258
commit
bd8645262d
|
@ -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>
|
2008-12-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Added Option::blank().
|
Added Option::blank().
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "Request.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -105,6 +106,13 @@ bool DefaultBtAnnounce::isAnnounceReady() {
|
||||||
isDefaultAnnounceReady();
|
isDefaultAnnounceReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool uriHasQuery(const std::string& uri)
|
||||||
|
{
|
||||||
|
Request req;
|
||||||
|
req.setUrl(uri);
|
||||||
|
return !req.getQuery().empty();
|
||||||
|
}
|
||||||
|
|
||||||
std::string DefaultBtAnnounce::getAnnounceUrl() {
|
std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
if(isStoppedAnnounceReady()) {
|
if(isStoppedAnnounceReady()) {
|
||||||
if(!announceList.currentTierAcceptsStoppedEvent()) {
|
if(!announceList.currentTierAcceptsStoppedEvent()) {
|
||||||
|
@ -134,8 +142,10 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
TransferStat stat = peerStorage->calculateStat();
|
TransferStat stat = peerStorage->calculateStat();
|
||||||
uint64_t left =
|
uint64_t left =
|
||||||
pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
||||||
std::string url = announceList.getAnnounce()+
|
std::string url = announceList.getAnnounce();
|
||||||
"?info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
|
url += uriHasQuery(url) ? "&" : "?";
|
||||||
|
url +=
|
||||||
|
"info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
|
||||||
btContext->getInfoHashLength())+
|
btContext->getInfoHashLength())+
|
||||||
"&peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+
|
"&peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+
|
||||||
"&uploaded="+Util::uitos(stat.getSessionUploadLength())+
|
"&uploaded="+Util::uitos(stat.getSessionUploadLength())+
|
||||||
|
|
|
@ -22,6 +22,7 @@ class DefaultBtAnnounceTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
|
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
|
||||||
CPPUNIT_TEST(testGetAnnounceUrl);
|
CPPUNIT_TEST(testGetAnnounceUrl);
|
||||||
|
CPPUNIT_TEST(testGetAnnounceUrl_withQuery);
|
||||||
CPPUNIT_TEST(testNoMoreAnnounce);
|
CPPUNIT_TEST(testNoMoreAnnounce);
|
||||||
CPPUNIT_TEST(testIsAllAnnounceFailed);
|
CPPUNIT_TEST(testIsAllAnnounceFailed);
|
||||||
CPPUNIT_TEST(testURLOrderInStoppedEvent);
|
CPPUNIT_TEST(testURLOrderInStoppedEvent);
|
||||||
|
@ -77,6 +78,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void testGetAnnounceUrl();
|
void testGetAnnounceUrl();
|
||||||
|
void testGetAnnounceUrl_withQuery();
|
||||||
void testNoMoreAnnounce();
|
void testNoMoreAnnounce();
|
||||||
void testIsAllAnnounceFailed();
|
void testIsAllAnnounceFailed();
|
||||||
void testURLOrderInStoppedEvent();
|
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());
|
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()
|
void DefaultBtAnnounceTest::testIsAllAnnounceFailed()
|
||||||
{
|
{
|
||||||
std::string trackerURI1 = "http://localhost/announce";
|
std::string trackerURI1 = "http://localhost/announce";
|
||||||
|
|
Loading…
Reference in New Issue