2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Made string literal for tracker response static const 
std::string
	* src/BtAnnounce.cc
	* src/BtAnnounce.h
	* src/DefaultBtAnnounce.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-05-14 11:47:15 +00:00
parent 412429dfe6
commit cb795bc989
6 changed files with 121 additions and 33 deletions

View File

@ -1,3 +1,10 @@
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made string literal for tracker response static const std::string
* src/BtAnnounce.cc
* src/BtAnnounce.h
* src/DefaultBtAnnounce.cc
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use DHTMessage::T instead of "t".

55
src/BtAnnounce.cc Normal file
View File

@ -0,0 +1,55 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "BtAnnounce.h"
namespace aria2 {
const std::string BtAnnounce::FAILURE_REASON("failure reason");
const std::string BtAnnounce::WARNING_MESSAGE("warning message");
const std::string BtAnnounce::TRACKER_ID("tracker id");
const std::string BtAnnounce::INTERVAL("interval");
const std::string BtAnnounce::MIN_INTERVAL("min interval");
const std::string BtAnnounce::COMPLETE("complete");
const std::string BtAnnounce::INCOMPLETE("incomplete");
const std::string BtAnnounce::PEERS("peers");
} // namespace aria2

View File

@ -103,6 +103,22 @@ public:
* Shuffles the URLs in each announce tier.
*/
virtual void shuffleAnnounce() = 0;
static const std::string FAILURE_REASON;
static const std::string WARNING_MESSAGE;
static const std::string TRACKER_ID;
static const std::string INTERVAL;
static const std::string MIN_INTERVAL;
static const std::string COMPLETE;
static const std::string INCOMPLETE;
static const std::string PEERS;
};
typedef SharedHandle<BtAnnounce> BtAnnounceHandle;

View File

@ -140,26 +140,26 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
if(left < 0) {
left = 0;
}
std::string url = announceList.getAnnounce()+"?"+
"info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
btContext->getInfoHashLength())+"&"+
"peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+"&"+
"uploaded="+Util::uitos(stat.getSessionUploadLength())+"&"+
"downloaded="+Util::uitos(stat.getSessionDownloadLength())+"&"+
"left="+Util::uitos(left)+"&"+
"compact=1"+"&"+
"key="+key+"&"+
"numwant="+Util::uitos(numWant)+"&"+
"no_peer_id=1";
std::string url = announceList.getAnnounce()+
"?info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
btContext->getInfoHashLength())+
"&peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+
"&uploaded="+Util::uitos(stat.getSessionUploadLength())+
"&downloaded="+Util::uitos(stat.getSessionDownloadLength())+
"&left="+Util::uitos(left)+
"&compact=1"+
"&key="+key+
"&numwant="+Util::uitos(numWant)+
"&no_peer_id=1";
if(btRuntime->getListenPort() > 0) {
url += std::string("&")+"port="+Util::uitos(btRuntime->getListenPort());
url += "&port="+Util::uitos(btRuntime->getListenPort());
}
std::string event = announceList.getEventString();
if(!event.empty()) {
url += std::string("&")+"event="+event;
url += "&event="+event;
}
if(!trackerId.empty()) {
url += std::string("&")+"trackerid="+Util::torrentUrlencode(trackerId);
url += "&trackerid="+Util::torrentUrlencode(trackerId);
}
if(option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
url += "&requirecrypto=1";
@ -202,23 +202,27 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
if(!response) {
throw DlAbortEx(MSG_NULL_TRACKER_RESPONSE);
}
const Data* failureReasonData = dynamic_cast<const Data*>(response->get("failure reason"));
const Data* failureReasonData =
dynamic_cast<const Data*>(response->get(BtAnnounce::FAILURE_REASON));
if(failureReasonData) {
throw DlAbortEx
(StringFormat(EX_TRACKER_FAILURE,
failureReasonData->toString().c_str()).str());
}
const Data* warningMessageData = dynamic_cast<const Data*>(response->get("warning message"));
const Data* warningMessageData =
dynamic_cast<const Data*>(response->get(BtAnnounce::WARNING_MESSAGE));
if(warningMessageData) {
logger->warn(MSG_TRACKER_WARNING_MESSAGE,
warningMessageData->toString().c_str());
}
const Data* trackerIdData = dynamic_cast<const Data*>(response->get("tracker id"));
const Data* trackerIdData =
dynamic_cast<const Data*>(response->get(BtAnnounce::TRACKER_ID));
if(trackerIdData) {
trackerId = trackerIdData->toString();
logger->debug("Tracker ID:%s", trackerId.c_str());
}
const Data* intervalData = dynamic_cast<const Data*>(response->get("interval"));
const Data* intervalData =
dynamic_cast<const Data*>(response->get(BtAnnounce::INTERVAL));
if(intervalData) {
time_t t = intervalData->toInt();
if(t > 0) {
@ -226,7 +230,8 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
logger->debug("Interval:%d", interval);
}
}
const Data* minIntervalData = dynamic_cast<const Data*>(response->get("min interval"));
const Data* minIntervalData =
dynamic_cast<const Data*>(response->get(BtAnnounce::MIN_INTERVAL));
if(minIntervalData) {
time_t t = minIntervalData->toInt();
if(t > 0) {
@ -237,17 +242,19 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
if(minInterval > interval) {
minInterval = interval;
}
const Data* completeData = dynamic_cast<const Data*>(response->get("complete"));
const Data* completeData =
dynamic_cast<const Data*>(response->get(BtAnnounce::COMPLETE));
if(completeData) {
complete = completeData->toInt();
logger->debug("Complete:%d", complete);
}
const Data* incompleteData = dynamic_cast<const Data*>(response->get("incomplete"));
const Data* incompleteData =
dynamic_cast<const Data*>(response->get(BtAnnounce::INCOMPLETE));
if(incompleteData) {
incomplete = incompleteData->toInt();
logger->debug("Incomplete:%d", incomplete);
}
const MetaEntry* peersEntry = response->get("peers");
const MetaEntry* peersEntry = response->get(BtAnnounce::PEERS);
if(peersEntry &&
!btRuntime->isHalt() &&
btRuntime->lessThanMinPeer()) {

View File

@ -236,7 +236,7 @@ SRCS += MetaEntry.h\
DefaultBtContext.cc DefaultBtContext.h\
PeerStorage.h\
DefaultPeerStorage.cc DefaultPeerStorage.h\
BtAnnounce.h\
BtAnnounce.cc BtAnnounce.h\
DefaultBtAnnounce.cc DefaultBtAnnounce.h\
BtRuntime.h\
BtContextAwareCommand.cc BtContextAwareCommand.h\

View File

@ -80,7 +80,7 @@ bin_PROGRAMS = aria2c$(EXEEXT)
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.cc DefaultBtContext.h\
@ENABLE_BITTORRENT_TRUE@ PeerStorage.h\
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.cc DefaultPeerStorage.h\
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.h\
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.cc BtAnnounce.h\
@ENABLE_BITTORRENT_TRUE@ DefaultBtAnnounce.cc DefaultBtAnnounce.h\
@ENABLE_BITTORRENT_TRUE@ BtRuntime.h\
@ENABLE_BITTORRENT_TRUE@ BtContextAwareCommand.cc BtContextAwareCommand.h\
@ -435,15 +435,16 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
DelegatingPeerListProcessor.h AnnounceTier.h AnnounceList.h \
AnnounceList.cc BtContext.h DefaultBtContext.cc \
DefaultBtContext.h PeerStorage.h DefaultPeerStorage.cc \
DefaultPeerStorage.h BtAnnounce.h DefaultBtAnnounce.cc \
DefaultBtAnnounce.h BtRuntime.h BtContextAwareCommand.cc \
BtContextAwareCommand.h BtMessage.h AbstractBtMessage.cc \
AbstractBtMessage.h SimpleBtMessage.cc SimpleBtMessage.h \
BtAllowedFastMessage.cc BtAllowedFastMessage.h \
BtBitfieldMessage.cc BtBitfieldMessage.h BtCancelMessage.cc \
BtCancelMessage.h BtChokeMessage.cc BtChokeMessage.h \
BtHaveAllMessage.cc BtHaveAllMessage.h BtHaveMessage.cc \
BtHaveMessage.h BtHaveNoneMessage.cc BtHaveNoneMessage.h \
DefaultPeerStorage.h BtAnnounce.cc BtAnnounce.h \
DefaultBtAnnounce.cc DefaultBtAnnounce.h BtRuntime.h \
BtContextAwareCommand.cc BtContextAwareCommand.h BtMessage.h \
AbstractBtMessage.cc AbstractBtMessage.h SimpleBtMessage.cc \
SimpleBtMessage.h BtAllowedFastMessage.cc \
BtAllowedFastMessage.h BtBitfieldMessage.cc \
BtBitfieldMessage.h BtCancelMessage.cc BtCancelMessage.h \
BtChokeMessage.cc BtChokeMessage.h BtHaveAllMessage.cc \
BtHaveAllMessage.h BtHaveMessage.cc BtHaveMessage.h \
BtHaveNoneMessage.cc BtHaveNoneMessage.h \
BtInterestedMessage.cc BtInterestedMessage.h \
BtKeepAliveMessage.cc BtKeepAliveMessage.h \
BtNotInterestedMessage.cc BtNotInterestedMessage.h \
@ -591,6 +592,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
@ENABLE_BITTORRENT_TRUE@ AnnounceList.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtAnnounce.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ BtContextAwareCommand.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ AbstractBtMessage.$(OBJEXT) \
@ -1245,6 +1247,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManFactory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAnnounce.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtBitfieldMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtCancelMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtCheckIntegrityEntry.Po@am__quote@