From 339795311bd3d07da1d49fb2c5c2e7efa8833922 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Nov 2009 09:58:49 +0000 Subject: 2009-11-28 Tatsuhiro Tsujikawa Accept BitTorrent Magnet URI in Metalink resource type bittorrent. Rewritten UTMetadataPostDownloadHandler. To create torrent data from metadata, use new metadata2Torrent() function. * src/BtDependency.cc * src/UTMetadataPostDownloadHandler.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * test/BittorrentHelperTest.cc * test/BtDependencyTest.cc --- src/UTMetadataPostDownloadHandler.cc | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'src/UTMetadataPostDownloadHandler.cc') diff --git a/src/UTMetadataPostDownloadHandler.cc b/src/UTMetadataPostDownloadHandler.cc index 90ced69f..12e0f9dc 100644 --- a/src/UTMetadataPostDownloadHandler.cc +++ b/src/UTMetadataPostDownloadHandler.cc @@ -45,6 +45,7 @@ #include "a2functional.h" #include "DiskAdaptor.h" #include "PieceStorage.h" +#include "bencode.h" namespace aria2 { @@ -72,35 +73,13 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups { SharedHandle dctx = requestGroup->getDownloadContext(); const BDE& attrs = dctx->getAttribute(bittorrent::BITTORRENT); - std::string torrent = - strconcat("d4:info", - util::toString(requestGroup->getPieceStorage()->getDiskAdaptor()), - "e"); + std::string metadata = + util::toString(requestGroup->getPieceStorage()->getDiskAdaptor()); + std::string torrent = bittorrent::metadata2Torrent(metadata, attrs); try { std::deque > newRgs; createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(), std::deque(), torrent); - if(attrs.containsKey(bittorrent::ANNOUNCE_LIST)) { - for(std::deque >::const_iterator i = - newRgs.begin(); i != newRgs.end(); ++i) { - SharedHandle newDctx = (*i)->getDownloadContext(); - if(!newDctx->hasAttribute(bittorrent::BITTORRENT)) { - continue; - } - BDE& newAttrs = newDctx->getAttribute(bittorrent::BITTORRENT); - if(attrs[bittorrent::INFO_HASH].s() != - newAttrs[bittorrent::INFO_HASH].s()) { - continue; - } - assert(newAttrs[bittorrent::ANNOUNCE_LIST].isList()); - if(newAttrs[bittorrent::ANNOUNCE_LIST].size() == 0) { - newAttrs[bittorrent::ANNOUNCE_LIST] = - attrs[bittorrent::ANNOUNCE_LIST]; - } - break; - } - } - groups.insert(groups.end(), newRgs.begin(), newRgs.end()); } catch(RecoverableException& e) { _logger->error("Failed to parse BitTorrent metadata.", e); -- cgit