summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-02-03 22:19:28 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-02-03 22:21:37 +0900
commit25615fcb1744e94f4774aaee24ed4db172af397f (patch)
tree57208721c3891951745ce543a9c83f4bfe2ce748
parentdbcf07fd11b9b29494787dd54fb29c5644798ec3 (diff)
Add "seeder" key to tellStatus RPC response
-rw-r--r--doc/manual-src/en/aria2c.rst4
-rw-r--r--src/ConsoleStatCalc.cc5
-rw-r--r--src/RequestGroup.cc6
-rw-r--r--src/RequestGroup.h3
-rw-r--r--src/RpcMethodImpl.cc13
5 files changed, 23 insertions, 8 deletions
diff --git a/doc/manual-src/en/aria2c.rst b/doc/manual-src/en/aria2c.rst
index fc60758b..4155f73e 100644
--- a/doc/manual-src/en/aria2c.rst
+++ b/doc/manual-src/en/aria2c.rst
@@ -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.
diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc
index 9ea84a88..066e814f 100644
--- a/src/ConsoleStatCalc.cc
+++ b/src/ConsoleStatCalc.cc
@@ -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();
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index a1f7080d..0098acc4 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -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
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index 38dbb1fd..fcb09cd5 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -489,6 +489,9 @@ public:
bool isSeedOnlyEnabled() { return seedOnly_; }
void enableSeedOnly();
+
+ // Returns true if this download is now seeding.
+ bool isSeeder() const;
};
} // namespace aria2
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index 0f87a948..7cded6ab 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -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,9 +782,9 @@ 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()),
- e->getBtRegistry()->get(group->getGID()), keys);
+ gatherProgressBitTorrent(entryDict, group, bittorrent::getTorrentAttrs(
+ group->getDownloadContext()),
+ e->getBtRegistry()->get(group->getGID()), keys);
}
#endif // ENABLE_BITTORRENT
}