diff --git a/ChangeLog b/ChangeLog index ae53a059..e08b8209 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2010-08-24 Tatsuhiro Tsujikawa + + Added --bt-tracker and --bt-exclude-tracker option. In + --bt-tracker option, you can specify comma separated list of + additional BitTorrent tracker's announce URI. These URIs are not + affected by --bt-exclude-tracker option because they are added + after URIs in --bt-exclude-tracker option are removed. In + --bt-exclude-tracker option, you can specify comma separated list + of BitTorrent tracker's announce URI to remove. You can use + special value '*' which matches all URIs, thus removes all + announce URIs. When specifying '*' in shell command-line, don't + forget to escape or quote it. + * src/BtDependency.cc + * src/OptionHandlerFactory.cc + * src/UTMetadataPostDownloadHandler.cc + * src/bittorrent_helper.cc + * src/bittorrent_helper.h + * src/download_helper.cc + * src/download_helper.h + * src/prefs.cc + * src/prefs.h + * src/usage_text.h + * test/BittorrentHelperTest.cc + * test/DownloadHelperTest.cc + 2010-08-24 Tatsuhiro Tsujikawa Code cleanup diff --git a/src/BtDependency.cc b/src/BtDependency.cc index 75babd74..fb8a1c9a 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -88,9 +88,13 @@ bool BtDependency::resolve() bittorrent::getTorrentAttrs(dependee->getDownloadContext()); bittorrent::loadFromMemory (bittorrent::metadata2Torrent(content, attrs), context, "default"); + // We don't call bittorrent::adjustAnnounceUri() because it + // has already been called with attrs. } else { bittorrent::loadFromMemory (content, context, File(dependee->getFirstFilePath()).getBasename()); + bittorrent::adjustAnnounceUri(bittorrent::getTorrentAttrs(context), + dependant_->getOption()); } const std::vector >& fileEntries = context->getFileEntries(); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 7766ef0a..f737761f 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -1145,6 +1145,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_BITTORRENT); handlers.push_back(op); } + { + SharedHandle op(new DefaultOptionHandler + (PREF_BT_EXCLUDE_TRACKER, + TEXT_BT_EXCLUDE_TRACKER, + NO_DESCRIPTION, + "URI,... " + "or *")); + op->addTag(TAG_BITTORRENT); + handlers.push_back(op); + } { SharedHandle op(new DefaultOptionHandler (PREF_BT_EXTERNAL_IP, @@ -1288,6 +1298,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->hide(); handlers.push_back(op); } + { + SharedHandle op(new DefaultOptionHandler + (PREF_BT_TRACKER, + TEXT_BT_TRACKER, + NO_DESCRIPTION, + "URI,...")); + op->addTag(TAG_BITTORRENT); + handlers.push_back(op); + } { SharedHandle op(new NumberOptionHandler (PREF_BT_TRACKER_CONNECT_TIMEOUT, diff --git a/src/UTMetadataPostDownloadHandler.cc b/src/UTMetadataPostDownloadHandler.cc index c82e11c9..7a603d6b 100644 --- a/src/UTMetadataPostDownloadHandler.cc +++ b/src/UTMetadataPostDownloadHandler.cc @@ -93,8 +93,10 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups } if(!requestGroup->getOption()->getAsBool(PREF_BT_METADATA_ONLY)) { std::vector > newRgs; + // Don't adjust announce URI because it has been done when + // RequestGroup is created with magnet URI. createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(), - std::vector(), torrent); + std::vector(), torrent, false); requestGroup->followedBy(newRgs.begin(), newRgs.end()); if(!requestGroup->getMetadataInfo().isNull()) { setMetadataInfo(newRgs.begin(), newRgs.end(), diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 6801e95e..bfa204ce 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -55,6 +55,8 @@ #include "bencode2.h" #include "TorrentAttribute.h" #include "SocketCore.h" +#include "Option.h" +#include "prefs.h" namespace aria2 { @@ -1005,6 +1007,60 @@ int getCompactLength(int family) } } +void removeAnnounceUri +(const SharedHandle& attrs, + const std::vector& uris) +{ + if(uris.empty()) { + return; + } + if(std::find(uris.begin(), uris.end(), "*") == uris.end()) { + for(std::vector >::iterator i = + attrs->announceList.begin(); i != attrs->announceList.end();) { + for(std::vector::iterator j =(*i).begin();j != (*i).end();) { + if(std::find(uris.begin(), uris.end(), *j) == uris.end()) { + ++j; + } else { + j = (*i).erase(j); + } + } + if((*i).empty()) { + i = attrs->announceList.erase(i); + } else { + ++i; + } + } + } else { + attrs->announceList.clear(); + } +} + +void addAnnounceUri +(const SharedHandle& attrs, + const std::vector& uris) +{ + for(std::vector::const_iterator i = uris.begin(), + eoi = uris.end(); i != eoi; ++i) { + std::vector tier; + tier.push_back(*i); + attrs->announceList.push_back(tier); + } +} + +void adjustAnnounceUri +(const SharedHandle& attrs, + const SharedHandle