2010-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added totalLength, completedLength, uploadLength, bitfield,
	downloadSpeed, uploadSpeed, infoHash, numSeeders, pieceLength,
	numPieces, connections and dir to the response of
	aria2.tellStopped XML-RPC method.  aria2.tellWaiting now always
	returns numSeeders for BitTorrent download.
	* src/DownloadResult.h
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/XmlRpcMethodImpl.cc
	* test/XmlRpcMethodTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-05-22 11:50:47 +00:00
parent 92f84f71f5
commit 1a29132b91
6 changed files with 78 additions and 19 deletions

View File

@ -1,3 +1,16 @@
2010-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added totalLength, completedLength, uploadLength, bitfield,
downloadSpeed, uploadSpeed, infoHash, numSeeders, pieceLength,
numPieces, connections and dir to the response of
aria2.tellStopped XML-RPC method. aria2.tellWaiting now always
returns numSeeders for BitTorrent download.
* src/DownloadResult.h
* src/RequestGroup.cc
* src/RequestGroup.h
* src/XmlRpcMethodImpl.cc
* test/XmlRpcMethodTest.cc
2010-05-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that connection pooling does not take into account

View File

@ -79,6 +79,22 @@ public:
SharedHandle<Option> option;
SharedHandle<MetadataInfo> metadataInfo;
uint64_t totalLength;
uint64_t completedLength;
uint64_t uploadLength;
std::string bitfieldStr;
std::string infoHashStr;
size_t pieceLength;
size_t numPieces;
std::string dir;
};
typedef SharedHandle<DownloadResult> DownloadResultHandle;

View File

@ -101,6 +101,7 @@
# include "DHTEntryPointNameResolveCommand.h"
# include "LongestSequencePieceSelector.h"
# include "PriorityPieceSelector.h"
# include "bittorrent_helper.h"
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
# include "MetalinkPostDownloadHandler.h"
@ -850,7 +851,7 @@ void RequestGroup::decreaseNumCommand()
}
TransferStat RequestGroup::calculateStat()
TransferStat RequestGroup::calculateStat() const
{
TransferStat stat;
#ifdef ENABLE_BITTORRENT
@ -859,7 +860,11 @@ TransferStat RequestGroup::calculateStat()
}
#endif // ENABLE_BITTORRENT
if(!_segmentMan.isNull()) {
stat.setDownloadSpeed(stat.getDownloadSpeed()+_segmentMan->calculateDownloadSpeed());
stat.setDownloadSpeed
(stat.getDownloadSpeed()+_segmentMan->calculateDownloadSpeed());
stat.setSessionDownloadLength
(stat.getSessionDownloadLength()+
_segmentMan->calculateSessionDownloadLength());
}
return stat;
}
@ -1045,29 +1050,35 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
_logger->debug("GID#%s - Creating DownloadResult.",
util::itos(_gid).c_str());
}
uint64_t sessionDownloadLength = 0;
#ifdef ENABLE_BITTORRENT
if(!_peerStorage.isNull()) {
sessionDownloadLength +=
_peerStorage->calculateStat().getSessionDownloadLength();
}
#endif // ENABLE_BITTORRENT
if(!_segmentMan.isNull()) {
sessionDownloadLength +=
_segmentMan->calculateSessionDownloadLength();
}
TransferStat st = calculateStat();
SharedHandle<DownloadResult> res(new DownloadResult());
res->gid = _gid;
res->fileEntries = _downloadContext->getFileEntries();
res->inMemoryDownload = _inMemoryDownload;
res->sessionDownloadLength = sessionDownloadLength;
res->sessionDownloadLength = st.getSessionDownloadLength();
res->sessionTime = _downloadContext->calculateSessionTime();
res->result = downloadResult();
res->followedBy = _followedByGIDs;
res->belongsTo = _belongsToGID;
res->option = _option;
res->metadataInfo = _metadataInfo;
res->totalLength = getTotalLength();
res->completedLength = getCompletedLength();
res->uploadLength = st.getAllTimeUploadLength();
if(!_pieceStorage.isNull()) {
if(_pieceStorage->getBitfieldLength() > 0) {
res->bitfieldStr = util::toHex(_pieceStorage->getBitfield(),
_pieceStorage->getBitfieldLength());
}
}
#ifdef ENABLE_BITTORRENT
if(_downloadContext->hasAttribute(bittorrent::BITTORRENT)) {
res->infoHashStr = bittorrent::getInfoHashString(_downloadContext);
}
#endif // ENABLE_BITTORRENT
res->pieceLength = _downloadContext->getPieceLength();
res->numPieces = _downloadContext->getNumPieces();
res->dir = _downloadContext->getDir();
return res;
}

View File

@ -258,7 +258,7 @@ public:
return _gid;
}
TransferStat calculateStat();
TransferStat calculateStat() const;
const SharedHandle<DownloadContext>& getDownloadContext() const
{

View File

@ -88,6 +88,7 @@ const BDE BDE_REMOVED = BDE("removed");
const BDE BDE_ERROR = BDE("error");
const BDE BDE_COMPLETE = BDE("complete");
const BDE BDE_USED = BDE("used");
const BDE BDE_ZERO = BDE("0");
const std::string KEY_GID = "gid";
const std::string KEY_ERROR_CODE = "errorCode";
@ -551,7 +552,7 @@ void gatherProgressCommon
createFileEntry
(files, dctx->getFileEntries().begin(), dctx->getFileEntries().end());
entryDict[KEY_FILES] = files;
entryDict[KEY_DIR] = group->getOption()->get(PREF_DIR);
entryDict[KEY_DIR] = dctx->getDir();
}
#ifdef ENABLE_BITTORRENT
@ -596,7 +597,9 @@ static void gatherProgressBitTorrent
BDE btDict = BDE::dict();
gatherBitTorrentMetadata(btDict, torrentAttrs);
entryDict[KEY_BITTORRENT] = btDict;
if(!btObject.isNull()) {
if(btObject.isNull()) {
entryDict[KEY_NUM_SEEDERS] = BDE_ZERO;
} else {
SharedHandle<PeerStorage> peerStorage = btObject._peerStorage;
assert(!peerStorage.isNull());
@ -676,6 +679,22 @@ void gatherStoppedDownload
BDE files = BDE::list();
createFileEntry(files, ds->fileEntries.begin(), ds->fileEntries.end());
entryDict[KEY_FILES] = files;
entryDict[KEY_TOTAL_LENGTH] = util::uitos(ds->totalLength);
entryDict[KEY_COMPLETED_LENGTH] = util::uitos(ds->completedLength);
entryDict[KEY_UPLOAD_LENGTH] = util::uitos(ds->uploadLength);
if(!ds->bitfieldStr.empty()) {
entryDict[KEY_BITFIELD] = ds->bitfieldStr;
}
entryDict[KEY_DOWNLOAD_SPEED] = BDE_ZERO;
entryDict[KEY_UPLOAD_SPEED] = BDE_ZERO;
if(!ds->infoHashStr.empty()) {
entryDict[KEY_INFO_HASH] = ds->infoHashStr;
entryDict[KEY_NUM_SEEDERS] = BDE_ZERO;
}
entryDict[KEY_PIECE_LENGTH] = util::uitos(ds->pieceLength);
entryDict[KEY_NUM_PIECES] = util::uitos(ds->numPieces);
entryDict[KEY_CONNECTIONS] = BDE_ZERO;
entryDict[KEY_DIR] = ds->dir;
}
BDE GetFilesXmlRpcMethod::process

View File

@ -696,7 +696,7 @@ void XmlRpcMethodTest::testGatherProgressCommon()
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0,"aria2.tar.bz2"));
std::string uris[] = { "http://localhost/aria2.tar.bz2" };
dctx->getFirstFileEntry()->addUris(vbegin(uris), vend(uris));
dctx->setDir(_option->get(PREF_DIR));
SharedHandle<RequestGroup> group(new RequestGroup(_option));
group->setDownloadContext(dctx);
std::vector<SharedHandle<RequestGroup> > followedBy;