Add "seeder" key to tellStatus RPC response

pull/558/head
Tatsuhiro Tsujikawa 2016-02-03 22:19:28 +09:00
parent dbcf07fd11
commit 25615fcb17
5 changed files with 23 additions and 8 deletions

View File

@ -2518,6 +2518,10 @@ For information on the *secret* parameter, see :ref:`rpc_auth`.
``numSeeders``
The number of seeders aria2 has connected to. BitTorrent only.
``seeder``
``true`` if the local endpoint is a seeder. Otherwise ``false``.
BitTorrent only.
``pieceLength``
Piece length in bytes.

View File

@ -105,10 +105,7 @@ void printSizeProgress(ColorizedStream& o,
const SizeFormatter& sizeFormatter)
{
#ifdef ENABLE_BITTORRENT
if (rg->getDownloadContext()->hasAttribute(CTX_ATTR_BT) &&
!bittorrent::getTorrentAttrs(rg->getDownloadContext())
->metadata.empty() &&
rg->downloadFinished()) {
if (rg->isSeeder()) {
o << "SEED(";
if (rg->getCompletedLength() > 0) {
std::streamsize oldprec = o.precision();

View File

@ -1264,4 +1264,10 @@ void RequestGroup::enableSeedOnly()
}
}
bool RequestGroup::isSeeder() const {
return downloadContext_->hasAttribute(CTX_ATTR_BT) &&
!bittorrent::getTorrentAttrs(downloadContext_)->metadata.empty() &&
downloadFinished();
}
} // namespace aria2

View File

@ -489,6 +489,9 @@ public:
bool isSeedOnlyEnabled() { return seedOnly_; }
void enableSeedOnly();
// Returns true if this download is now seeding.
bool isSeeder() const;
};
} // namespace aria2

View File

@ -710,7 +710,9 @@ void gatherBitTorrentMetadata(Dict* btDict, TorrentAttribute* torrentAttrs)
}
namespace {
void gatherProgressBitTorrent(Dict* entryDict, TorrentAttribute* torrentAttrs,
void gatherProgressBitTorrent(Dict* entryDict,
const std::shared_ptr<RequestGroup>& group,
TorrentAttribute* torrentAttrs,
BtObject* btObject,
const std::vector<std::string>& keys)
{
@ -734,6 +736,9 @@ void gatherProgressBitTorrent(Dict* entryDict, TorrentAttribute* torrentAttrs,
util::uitos(countSeeder(peers.begin(), peers.end())));
}
}
if (requested_key(keys, KEY_SEEDER)) {
entryDict->put(KEY_SEEDER, group->isSeeder() ? VLB_TRUE : VLB_FALSE);
}
}
} // namespace
@ -777,8 +782,8 @@ void gatherProgress(Dict* entryDict, const std::shared_ptr<RequestGroup>& group,
gatherProgressCommon(entryDict, group, keys);
#ifdef ENABLE_BITTORRENT
if (group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
gatherProgressBitTorrent(
entryDict, bittorrent::getTorrentAttrs(group->getDownloadContext()),
gatherProgressBitTorrent(entryDict, group, bittorrent::getTorrentAttrs(
group->getDownloadContext()),
e->getBtRegistry()->get(group->getGID()), keys);
}
#endif // ENABLE_BITTORRENT