summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-05-10 21:51:41 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-05-10 21:51:41 +0900
commit1a953d5f9394cd03e128aabb9b59eda62023fc9e (patch)
tree25092daf469771ca1369d47e5f7333d68e8a63a3 /src
parent1b6827b060d1c2175cb82234de3c7ef4d037f07e (diff)
Add DownloadHandle::getInfohash() and getPieceLength()
Diffstat (limited to 'src')
-rw-r--r--src/aria2api.cc28
-rw-r--r--src/includes/aria2/aria2.h9
2 files changed, 37 insertions, 0 deletions
diff --git a/src/aria2api.cc b/src/aria2api.cc
index a23e0fea..87555929 100644
--- a/src/aria2api.cc
+++ b/src/aria2api.cc
@@ -58,6 +58,10 @@
#include "RpcMethodImpl.h"
#include "console.h"
#include "KeepRunningCommand.h"
+#include "A2STR.h"
+#ifdef ENABLE_BITTORRENT
+# include "bittorrent_helper.h"
+#endif // ENABLE_BITTORRENT
namespace aria2 {
@@ -507,6 +511,22 @@ struct RequestGroupDH : public DownloadHandle {
{
return ts.uploadSpeed;
}
+ virtual const std::string& getInfoHash()
+ {
+#ifdef ENABLE_BITTORRENT
+ if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
+ SharedHandle<TorrentAttribute> torrentAttrs =
+ bittorrent::getTorrentAttrs(group->getDownloadContext());
+ return torrentAttrs->infoHash;
+ }
+#endif // ENABLE_BITTORRENT
+ return A2STR::NIL;
+ }
+ virtual size_t getPieceLength()
+ {
+ const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
+ return dctx->getPieceLength();
+ }
virtual size_t getNumPieces()
{
return group->getDownloadContext()->getNumPieces();
@@ -603,6 +623,14 @@ struct DownloadResultDH : public DownloadHandle {
{
return 0;
}
+ virtual const std::string& getInfoHash()
+ {
+ return dr->infoHash;
+ }
+ virtual size_t getPieceLength()
+ {
+ return dr->pieceLength;
+ }
virtual size_t getNumPieces()
{
return dr->numPieces;
diff --git a/src/includes/aria2/aria2.h b/src/includes/aria2/aria2.h
index 8f0500d2..97130e25 100644
--- a/src/includes/aria2/aria2.h
+++ b/src/includes/aria2/aria2.h
@@ -461,6 +461,15 @@ public:
*/
virtual int getUploadSpeed() = 0;
/**
+ * Returns 20 bytes InfoHash if BitTorrent transfer is
+ * involved. Otherwise the empty string is returned.
+ */
+ virtual const std::string& getInfoHash() = 0;
+ /**
+ * Returns piece length in bytes.
+ */
+ virtual size_t getPieceLength() = 0;
+ /**
* Returns the number of pieces.
*/
virtual size_t getNumPieces() = 0;