mirror of https://github.com/aria2/aria2
DownloadContext::attrs_ now holds std::unique_ptr
DownloadContext::getAttribute() returns a raw pointer.pull/103/head
parent
1a299c4d7c
commit
bef6236da8
|
@ -101,7 +101,7 @@ bool BtDependency::resolve()
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
std::string content = util::toString(diskAdaptor);
|
std::string content = util::toString(diskAdaptor);
|
||||||
if(dependee->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
|
if(dependee->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
|
||||||
std::shared_ptr<TorrentAttribute> attrs =
|
auto attrs =
|
||||||
bittorrent::getTorrentAttrs(dependee->getDownloadContext());
|
bittorrent::getTorrentAttrs(dependee->getDownloadContext());
|
||||||
bittorrent::loadFromMemory
|
bittorrent::loadFromMemory
|
||||||
(bittorrent::metadata2Torrent(content, attrs), context,
|
(bittorrent::metadata2Torrent(content, attrs), context,
|
||||||
|
|
|
@ -98,7 +98,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
||||||
if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){
|
if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs =
|
||||||
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
|
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
|
||||||
bool metadataGetMode = torrentAttrs->metadata.empty();
|
bool metadataGetMode = torrentAttrs->metadata.empty();
|
||||||
const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
|
const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
|
||||||
|
|
|
@ -195,8 +195,7 @@ void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
|
||||||
m->setClientVersion("aria2/" PACKAGE_VERSION);
|
m->setClientVersion("aria2/" PACKAGE_VERSION);
|
||||||
m->setTCPPort(tcpPort_);
|
m->setTCPPort(tcpPort_);
|
||||||
m->setExtensions(extensionMessageRegistry_->getExtensions());
|
m->setExtensions(extensionMessageRegistry_->getExtensions());
|
||||||
std::shared_ptr<TorrentAttribute> attrs =
|
auto attrs = bittorrent::getTorrentAttrs(downloadContext_);
|
||||||
bittorrent::getTorrentAttrs(downloadContext_);
|
|
||||||
if(!attrs->metadata.empty()) {
|
if(!attrs->metadata.empty()) {
|
||||||
m->setMetadataSize(attrs->metadataSize);
|
m->setMetadataSize(attrs->metadataSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -478,8 +478,7 @@ void DefaultPieceStorage::completePiece(const std::shared_ptr<Piece>& piece)
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_);
|
||||||
bittorrent::getTorrentAttrs(downloadContext_);
|
|
||||||
if(!torrentAttrs->metadata.empty()) {
|
if(!torrentAttrs->metadata.empty()) {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
// On Windows, if aria2 opens files with GENERIC_WRITE access
|
// On Windows, if aria2 opens files with GENERIC_WRITE access
|
||||||
|
|
|
@ -150,19 +150,18 @@ void DownloadContext::setFileFilter(SegList<int>& sgl)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadContext::setAttribute
|
void DownloadContext::setAttribute
|
||||||
(ContextAttributeType key, const std::shared_ptr<ContextAttribute>& value)
|
(ContextAttributeType key, std::unique_ptr<ContextAttribute>&& value)
|
||||||
{
|
{
|
||||||
assert(key < MAX_CTX_ATTR);
|
assert(key < MAX_CTX_ATTR);
|
||||||
attrs_[key] = value;
|
attrs_[key] = std::move(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<ContextAttribute>& DownloadContext::getAttribute
|
ContextAttribute* DownloadContext::getAttribute(ContextAttributeType key)
|
||||||
(ContextAttributeType key)
|
|
||||||
{
|
{
|
||||||
assert(key < MAX_CTX_ATTR);
|
assert(key < MAX_CTX_ATTR);
|
||||||
const std::shared_ptr<ContextAttribute>& attr = attrs_[key];
|
const std::unique_ptr<ContextAttribute>& attr = attrs_[key];
|
||||||
if(attr) {
|
if(attr) {
|
||||||
return attr;
|
return attr.get();
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX(fmt("No attribute named %s",
|
throw DL_ABORT_EX(fmt("No attribute named %s",
|
||||||
strContextAttributeType(key)));
|
strContextAttributeType(key)));
|
||||||
|
|
|
@ -78,7 +78,7 @@ private:
|
||||||
|
|
||||||
RequestGroup* ownerRequestGroup_;
|
RequestGroup* ownerRequestGroup_;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<ContextAttribute> > attrs_;
|
std::vector<std::unique_ptr<ContextAttribute> > attrs_;
|
||||||
|
|
||||||
NetStat netStat_;
|
NetStat netStat_;
|
||||||
|
|
||||||
|
@ -204,9 +204,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAttribute
|
void setAttribute
|
||||||
(ContextAttributeType key, const std::shared_ptr<ContextAttribute>& value);
|
(ContextAttributeType key, std::unique_ptr<ContextAttribute>&& value);
|
||||||
|
|
||||||
const std::shared_ptr<ContextAttribute>& getAttribute(ContextAttributeType key);
|
ContextAttribute* getAttribute(ContextAttributeType key);
|
||||||
|
|
||||||
bool hasAttribute(ContextAttributeType key) const;
|
bool hasAttribute(ContextAttributeType key) const;
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ void HandshakeExtensionMessage::doReceivedAction()
|
||||||
peer_->setExtension(i, id);
|
peer_->setExtension(i, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
|
auto attrs = bittorrent::getTorrentAttrs(dctx_);
|
||||||
if(attrs->metadata.empty()) {
|
if(attrs->metadata.empty()) {
|
||||||
if(!peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA)) {
|
if(!peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA)) {
|
||||||
// TODO In metadataGetMode, if peer don't support metadata
|
// TODO In metadataGetMode, if peer don't support metadata
|
||||||
|
|
|
@ -114,7 +114,7 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs =
|
||||||
bittorrent::getTorrentAttrs(requestGroup_->getDownloadContext());
|
bittorrent::getTorrentAttrs(requestGroup_->getDownloadContext());
|
||||||
bool metadataGetMode = torrentAttrs->metadata.empty();
|
bool metadataGetMode = torrentAttrs->metadata.empty();
|
||||||
|
|
||||||
|
|
|
@ -287,8 +287,7 @@ void RequestGroup::createInitialCommand
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
{
|
{
|
||||||
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_);
|
||||||
bittorrent::getTorrentAttrs(downloadContext_);
|
|
||||||
bool metadataGetMode = torrentAttrs->metadata.empty();
|
bool metadataGetMode = torrentAttrs->metadata.empty();
|
||||||
if(option_->getAsBool(PREF_DRY_RUN)) {
|
if(option_->getAsBool(PREF_DRY_RUN)) {
|
||||||
throw DOWNLOAD_FAILURE_EXCEPTION
|
throw DOWNLOAD_FAILURE_EXCEPTION
|
||||||
|
@ -1207,8 +1206,7 @@ void RequestGroup::reportDownloadFinished()
|
||||||
int64_t completedLength = getCompletedLength();
|
int64_t completedLength = getCompletedLength();
|
||||||
double shareRatio = completedLength == 0 ? 0.0 :
|
double shareRatio = completedLength == 0 ? 0.0 :
|
||||||
1.0*stat.allTimeUploadLength/completedLength;
|
1.0*stat.allTimeUploadLength/completedLength;
|
||||||
std::shared_ptr<TorrentAttribute> attrs =
|
auto attrs = bittorrent::getTorrentAttrs(downloadContext_);
|
||||||
bittorrent::getTorrentAttrs(downloadContext_);
|
|
||||||
if(!attrs->metadata.empty()) {
|
if(!attrs->metadata.empty()) {
|
||||||
A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
|
A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
|
||||||
shareRatio,
|
shareRatio,
|
||||||
|
|
|
@ -697,8 +697,7 @@ void gatherProgressCommon
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
void gatherBitTorrentMetadata
|
void gatherBitTorrentMetadata
|
||||||
(const std::shared_ptr<Dict>& btDict,
|
(const std::shared_ptr<Dict>& btDict, TorrentAttribute* torrentAttrs)
|
||||||
const std::shared_ptr<TorrentAttribute>& torrentAttrs)
|
|
||||||
{
|
{
|
||||||
if(!torrentAttrs->comment.empty()) {
|
if(!torrentAttrs->comment.empty()) {
|
||||||
btDict->put(KEY_COMMENT, torrentAttrs->comment);
|
btDict->put(KEY_COMMENT, torrentAttrs->comment);
|
||||||
|
@ -731,7 +730,7 @@ void gatherBitTorrentMetadata
|
||||||
namespace {
|
namespace {
|
||||||
void gatherProgressBitTorrent
|
void gatherProgressBitTorrent
|
||||||
(const std::shared_ptr<Dict>& entryDict,
|
(const std::shared_ptr<Dict>& entryDict,
|
||||||
const std::shared_ptr<TorrentAttribute>& torrentAttrs,
|
TorrentAttribute* torrentAttrs,
|
||||||
const std::shared_ptr<BtObject>& btObject,
|
const std::shared_ptr<BtObject>& btObject,
|
||||||
const std::vector<std::string>& keys)
|
const std::vector<std::string>& keys)
|
||||||
{
|
{
|
||||||
|
@ -801,7 +800,7 @@ void gatherProgress
|
||||||
gatherProgressCommon(entryDict, group, keys);
|
gatherProgressCommon(entryDict, group, keys);
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
|
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs =
|
||||||
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
||||||
const std::shared_ptr<BtObject>& btObject =
|
const std::shared_ptr<BtObject>& btObject =
|
||||||
e->getBtRegistry()->get(group->getGID());
|
e->getBtRegistry()->get(group->getGID());
|
||||||
|
|
|
@ -599,8 +599,7 @@ void gatherProgressCommon
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
// Helper function to store BitTorrent metadata from torrentAttrs.
|
// Helper function to store BitTorrent metadata from torrentAttrs.
|
||||||
void gatherBitTorrentMetadata
|
void gatherBitTorrentMetadata
|
||||||
(const std::shared_ptr<Dict>& btDict,
|
(const std::shared_ptr<Dict>& btDict, TorrentAttribute* torrentAttrs);
|
||||||
const std::shared_ptr<TorrentAttribute>& torrentAttrs);
|
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
} // namespace rpc
|
} // namespace rpc
|
||||||
|
|
|
@ -328,8 +328,7 @@ namespace {
|
||||||
bool backupTrackerIsAvailable
|
bool backupTrackerIsAvailable
|
||||||
(const std::shared_ptr<DownloadContext>& context)
|
(const std::shared_ptr<DownloadContext>& context)
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs = bittorrent::getTorrentAttrs(context);
|
||||||
bittorrent::getTorrentAttrs(context);
|
|
||||||
if(torrentAttrs->announceList.size() >= 2) {
|
if(torrentAttrs->announceList.size() >= 2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ bool UTMetadataPostDownloadHandler::Criteria::match
|
||||||
const std::shared_ptr<DownloadContext>& dctx =
|
const std::shared_ptr<DownloadContext>& dctx =
|
||||||
requestGroup->getDownloadContext();
|
requestGroup->getDownloadContext();
|
||||||
if(dctx->hasAttribute(CTX_ATTR_BT)) {
|
if(dctx->hasAttribute(CTX_ATTR_BT)) {
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
|
auto attrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
if(attrs->metadata.empty()) {
|
if(attrs->metadata.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
|
||||||
(std::vector<std::shared_ptr<RequestGroup> >& groups, RequestGroup* requestGroup)
|
(std::vector<std::shared_ptr<RequestGroup> >& groups, RequestGroup* requestGroup)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<DownloadContext>& dctx =requestGroup->getDownloadContext();
|
const std::shared_ptr<DownloadContext>& dctx =requestGroup->getDownloadContext();
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx);
|
auto attrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
std::string metadata =
|
std::string metadata =
|
||||||
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||||
std::string torrent = bittorrent::metadata2Torrent(metadata, attrs);
|
std::string torrent = bittorrent::metadata2Torrent(metadata, attrs);
|
||||||
|
|
|
@ -76,7 +76,7 @@ std::string UTMetadataRequestExtensionMessage::toString() const
|
||||||
|
|
||||||
void UTMetadataRequestExtensionMessage::doReceivedAction()
|
void UTMetadataRequestExtensionMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
|
auto attrs = bittorrent::getTorrentAttrs(dctx_);
|
||||||
uint8_t id = peer_->getExtensionMessageID
|
uint8_t id = peer_->getExtensionMessageID
|
||||||
(ExtensionMessageRegistry::UT_METADATA);
|
(ExtensionMessageRegistry::UT_METADATA);
|
||||||
if(attrs->metadata.empty()) {
|
if(attrs->metadata.empty()) {
|
||||||
|
|
|
@ -129,17 +129,16 @@ void extractPieceHash(const std::shared_ptr<DownloadContext>& ctx,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void extractUrlList
|
void extractUrlList
|
||||||
(const std::shared_ptr<TorrentAttribute>& torrent, std::vector<std::string>& uris,
|
(TorrentAttribute* torrent, std::vector<std::string>& uris,
|
||||||
const ValueBase* v)
|
const ValueBase* v)
|
||||||
{
|
{
|
||||||
class UrlListVisitor:public ValueBaseVisitor {
|
class UrlListVisitor:public ValueBaseVisitor {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string>& uris_;
|
std::vector<std::string>& uris_;
|
||||||
const std::shared_ptr<TorrentAttribute>& torrent_;
|
TorrentAttribute* torrent_;
|
||||||
public:
|
public:
|
||||||
UrlListVisitor
|
UrlListVisitor
|
||||||
(std::vector<std::string>& uris,
|
(std::vector<std::string>& uris, TorrentAttribute* torrent):
|
||||||
const std::shared_ptr<TorrentAttribute>& torrent):
|
|
||||||
uris_(uris), torrent_(torrent) {}
|
uris_(uris), torrent_(torrent) {}
|
||||||
|
|
||||||
virtual void visit(const String& v)
|
virtual void visit(const String& v)
|
||||||
|
@ -195,7 +194,7 @@ OutputIterator createUri
|
||||||
namespace {
|
namespace {
|
||||||
void extractFileEntries
|
void extractFileEntries
|
||||||
(const std::shared_ptr<DownloadContext>& ctx,
|
(const std::shared_ptr<DownloadContext>& ctx,
|
||||||
const std::shared_ptr<TorrentAttribute>& torrent,
|
TorrentAttribute* torrent,
|
||||||
const Dict* infoDict,
|
const Dict* infoDict,
|
||||||
const std::shared_ptr<Option>& option,
|
const std::shared_ptr<Option>& option,
|
||||||
const std::string& defaultName,
|
const std::string& defaultName,
|
||||||
|
@ -341,8 +340,7 @@ void extractFileEntries
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void extractAnnounce
|
void extractAnnounce(TorrentAttribute* torrent, const Dict* rootDict)
|
||||||
(const std::shared_ptr<TorrentAttribute>& torrent, const Dict* rootDict)
|
|
||||||
{
|
{
|
||||||
const List* announceList = downcast<List>(rootDict->get(C_ANNOUNCE_LIST));
|
const List* announceList = downcast<List>(rootDict->get(C_ANNOUNCE_LIST));
|
||||||
if(announceList) {
|
if(announceList) {
|
||||||
|
@ -376,8 +374,7 @@ void extractAnnounce
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void extractNodes
|
void extractNodes(TorrentAttribute* torrent, const ValueBase* nodesListSrc)
|
||||||
(const std::shared_ptr<TorrentAttribute>& torrent, const ValueBase* nodesListSrc)
|
|
||||||
{
|
{
|
||||||
const List* nodesList = downcast<List>(nodesListSrc);
|
const List* nodesList = downcast<List>(nodesListSrc);
|
||||||
if(nodesList) {
|
if(nodesList) {
|
||||||
|
@ -425,7 +422,7 @@ void processRootDictionary
|
||||||
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_INFO.c_str()),
|
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_INFO.c_str()),
|
||||||
error_code::BITTORRENT_PARSE_ERROR);
|
error_code::BITTORRENT_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
std::shared_ptr<TorrentAttribute> torrent(new TorrentAttribute());
|
std::unique_ptr<TorrentAttribute> torrent(new TorrentAttribute());
|
||||||
|
|
||||||
// retrieve infoHash
|
// retrieve infoHash
|
||||||
std::string encodedInfoDict = bencode2::encode(infoDict);
|
std::string encodedInfoDict = bencode2::encode(infoDict);
|
||||||
|
@ -478,22 +475,22 @@ void processRootDictionary
|
||||||
// This implemantation obeys HTTP-Seeding specification:
|
// This implemantation obeys HTTP-Seeding specification:
|
||||||
// see http://www.getright.com/seedtorrent.html
|
// see http://www.getright.com/seedtorrent.html
|
||||||
std::vector<std::string> urlList;
|
std::vector<std::string> urlList;
|
||||||
extractUrlList(torrent, urlList, rootDict->get(C_URL_LIST).get());
|
extractUrlList(torrent.get(), urlList, rootDict->get(C_URL_LIST).get());
|
||||||
urlList.insert(urlList.end(), uris.begin(), uris.end());
|
urlList.insert(urlList.end(), uris.begin(), uris.end());
|
||||||
std::sort(urlList.begin(), urlList.end());
|
std::sort(urlList.begin(), urlList.end());
|
||||||
urlList.erase(std::unique(urlList.begin(), urlList.end()), urlList.end());
|
urlList.erase(std::unique(urlList.begin(), urlList.end()), urlList.end());
|
||||||
|
|
||||||
// retrieve file entries
|
// retrieve file entries
|
||||||
extractFileEntries
|
extractFileEntries
|
||||||
(ctx, torrent, infoDict, option, defaultName, overrideName, urlList);
|
(ctx, torrent.get(), infoDict, option, defaultName, overrideName, urlList);
|
||||||
if((ctx->getTotalLength()+pieceLength-1)/pieceLength != numPieces) {
|
if((ctx->getTotalLength()+pieceLength-1)/pieceLength != numPieces) {
|
||||||
throw DL_ABORT_EX2("Too few/many piece hash.",
|
throw DL_ABORT_EX2("Too few/many piece hash.",
|
||||||
error_code::BITTORRENT_PARSE_ERROR);
|
error_code::BITTORRENT_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
// retrieve announce
|
// retrieve announce
|
||||||
extractAnnounce(torrent, rootDict);
|
extractAnnounce(torrent.get(), rootDict);
|
||||||
// retrieve nodes
|
// retrieve nodes
|
||||||
extractNodes(torrent, rootDict->get(C_NODES).get());
|
extractNodes(torrent.get(), rootDict->get(C_NODES).get());
|
||||||
|
|
||||||
const Integer* creationDate = downcast<Integer>(rootDict->get(C_CREATION_DATE));
|
const Integer* creationDate = downcast<Integer>(rootDict->get(C_CREATION_DATE));
|
||||||
if(creationDate) {
|
if(creationDate) {
|
||||||
|
@ -513,7 +510,7 @@ void processRootDictionary
|
||||||
torrent->createdBy = util::encodeNonUtf8(createdBy->s());
|
torrent->createdBy = util::encodeNonUtf8(createdBy->s());
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->setAttribute(CTX_ATTR_BT, torrent);
|
ctx->setAttribute(CTX_ATTR_BT, std::move(torrent));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -621,16 +618,15 @@ void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
|
||||||
uris);
|
uris);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
TorrentAttribute* getTorrentAttrs
|
||||||
(const std::shared_ptr<DownloadContext>& dctx)
|
(const std::shared_ptr<DownloadContext>& dctx)
|
||||||
{
|
{
|
||||||
return getTorrentAttrs(dctx.get());
|
return getTorrentAttrs(dctx.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx)
|
TorrentAttribute* getTorrentAttrs(DownloadContext* dctx)
|
||||||
{
|
{
|
||||||
return std::static_pointer_cast<TorrentAttribute>
|
return static_cast<TorrentAttribute*>(dctx->getAttribute(CTX_ATTR_BT));
|
||||||
(dctx->getAttribute(CTX_ATTR_BT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* getInfoHash
|
const unsigned char* getInfoHash
|
||||||
|
@ -907,7 +903,7 @@ void assertID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet)
|
std::unique_ptr<TorrentAttribute> parseMagnet(const std::string& magnet)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Dict> r = magnet::parse(magnet);
|
std::shared_ptr<Dict> r = magnet::parse(magnet);
|
||||||
if(!r) {
|
if(!r) {
|
||||||
|
@ -919,7 +915,7 @@ std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet)
|
||||||
throw DL_ABORT_EX2("Missing xt parameter in Magnet URI.",
|
throw DL_ABORT_EX2("Missing xt parameter in Magnet URI.",
|
||||||
error_code::MAGNET_PARSE_ERROR);
|
error_code::MAGNET_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
auto attrs = make_unique<TorrentAttribute>();
|
||||||
std::string infoHash;
|
std::string infoHash;
|
||||||
for(List::ValueType::const_iterator xtiter = xts->begin(),
|
for(List::ValueType::const_iterator xtiter = xts->begin(),
|
||||||
eoi = xts->end(); xtiter != eoi && infoHash.empty(); ++xtiter) {
|
eoi = xts->end(); xtiter != eoi && infoHash.empty(); ++xtiter) {
|
||||||
|
@ -969,12 +965,11 @@ std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet)
|
||||||
void loadMagnet
|
void loadMagnet
|
||||||
(const std::string& magnet, const std::shared_ptr<DownloadContext>& dctx)
|
(const std::string& magnet, const std::shared_ptr<DownloadContext>& dctx)
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> attrs = parseMagnet(magnet);
|
dctx->setAttribute(CTX_ATTR_BT, parseMagnet(magnet));
|
||||||
dctx->setAttribute(CTX_ATTR_BT, attrs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string metadata2Torrent
|
std::string metadata2Torrent
|
||||||
(const std::string& metadata, const std::shared_ptr<TorrentAttribute>& attrs)
|
(const std::string& metadata, const TorrentAttribute* attrs)
|
||||||
{
|
{
|
||||||
std::string torrent = "d";
|
std::string torrent = "d";
|
||||||
|
|
||||||
|
@ -1001,7 +996,7 @@ std::string metadata2Torrent
|
||||||
return torrent;
|
return torrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string torrent2Magnet(const std::shared_ptr<TorrentAttribute>& attrs)
|
std::string torrent2Magnet(const TorrentAttribute* attrs)
|
||||||
{
|
{
|
||||||
std::string uri = "magnet:?";
|
std::string uri = "magnet:?";
|
||||||
if(!attrs->infoHash.empty()) {
|
if(!attrs->infoHash.empty()) {
|
||||||
|
@ -1038,8 +1033,7 @@ int getCompactLength(int family)
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeAnnounceUri
|
void removeAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::vector<std::string>& uris)
|
||||||
const std::vector<std::string>& uris)
|
|
||||||
{
|
{
|
||||||
if(uris.empty()) {
|
if(uris.empty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1066,8 +1060,7 @@ void removeAnnounceUri
|
||||||
}
|
}
|
||||||
|
|
||||||
void addAnnounceUri
|
void addAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::vector<std::string>& uris)
|
||||||
const std::vector<std::string>& uris)
|
|
||||||
{
|
{
|
||||||
for(std::vector<std::string>::const_iterator i = uris.begin(),
|
for(std::vector<std::string>::const_iterator i = uris.begin(),
|
||||||
eoi = uris.end(); i != eoi; ++i) {
|
eoi = uris.end(); i != eoi; ++i) {
|
||||||
|
@ -1078,8 +1071,7 @@ void addAnnounceUri
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjustAnnounceUri
|
void adjustAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::shared_ptr<Option>& option)
|
||||||
const std::shared_ptr<Option>& option)
|
|
||||||
{
|
{
|
||||||
std::vector<std::string> excludeUris;
|
std::vector<std::string> excludeUris;
|
||||||
std::vector<std::string> addUris;
|
std::vector<std::string> addUris;
|
||||||
|
|
|
@ -117,7 +117,7 @@ void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
|
||||||
// magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>
|
// magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>
|
||||||
// <info-hash> comes in 2 flavors: 40bytes hexadecimal ascii string,
|
// <info-hash> comes in 2 flavors: 40bytes hexadecimal ascii string,
|
||||||
// or 32bytes Base32 encoded string.
|
// or 32bytes Base32 encoded string.
|
||||||
std::shared_ptr<TorrentAttribute> parseMagnet(const std::string& magnet);
|
std::unique_ptr<TorrentAttribute> parseMagnet(const std::string& magnet);
|
||||||
|
|
||||||
// Parses BitTorrent Magnet URI and set them in ctx as a
|
// Parses BitTorrent Magnet URI and set them in ctx as a
|
||||||
// bittorrent::BITTORRENT attibute. If parsing operation failed, an
|
// bittorrent::BITTORRENT attibute. If parsing operation failed, an
|
||||||
|
@ -149,8 +149,8 @@ void computeFastSet
|
||||||
(std::vector<size_t>& fastSet, const std::string& ipaddr,
|
(std::vector<size_t>& fastSet, const std::string& ipaddr,
|
||||||
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
|
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx);
|
TorrentAttribute* getTorrentAttrs(DownloadContext* dctx);
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
TorrentAttribute* getTorrentAttrs
|
||||||
(const std::shared_ptr<DownloadContext>& dctx);
|
(const std::shared_ptr<DownloadContext>& dctx);
|
||||||
|
|
||||||
// Returns the value associated with INFO_HASH key in BITTORRENT
|
// Returns the value associated with INFO_HASH key in BITTORRENT
|
||||||
|
@ -240,22 +240,20 @@ void assertID
|
||||||
// Converts attrs into torrent data. This function does not guarantee
|
// Converts attrs into torrent data. This function does not guarantee
|
||||||
// the returned string is valid torrent data.
|
// the returned string is valid torrent data.
|
||||||
std::string metadata2Torrent
|
std::string metadata2Torrent
|
||||||
(const std::string& metadata, const std::shared_ptr<TorrentAttribute>& attrs);
|
(const std::string& metadata, const TorrentAttribute* attrs);
|
||||||
|
|
||||||
// Constructs BitTorrent Magnet URI using attrs.
|
// Constructs BitTorrent Magnet URI using attrs.
|
||||||
std::string torrent2Magnet(const std::shared_ptr<TorrentAttribute>& attrs);
|
std::string torrent2Magnet(const TorrentAttribute* attrs);
|
||||||
|
|
||||||
// Removes announce URI in uris from attrs. If uris contains '*', all
|
// Removes announce URI in uris from attrs. If uris contains '*', all
|
||||||
// announce URIs are removed.
|
// announce URIs are removed.
|
||||||
void removeAnnounceUri
|
void removeAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::vector<std::string>& uris);
|
||||||
const std::vector<std::string>& uris);
|
|
||||||
|
|
||||||
// Adds announce URI in uris to attrs. Each URI in uris creates its
|
// Adds announce URI in uris to attrs. Each URI in uris creates its
|
||||||
// own tier.
|
// own tier.
|
||||||
void addAnnounceUri
|
void addAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::vector<std::string>& uris);
|
||||||
const std::vector<std::string>& uris);
|
|
||||||
|
|
||||||
// This helper function uses 2 option values: PREF_BT_TRACKER and
|
// This helper function uses 2 option values: PREF_BT_TRACKER and
|
||||||
// PREF_BT_EXCLUDE_TRACKER. First, the value of
|
// PREF_BT_EXCLUDE_TRACKER. First, the value of
|
||||||
|
@ -263,8 +261,7 @@ void addAnnounceUri
|
||||||
// and call removeAnnounceUri(). Then the value of PREF_BT_TRACKER is
|
// and call removeAnnounceUri(). Then the value of PREF_BT_TRACKER is
|
||||||
// converted to std::vector<std::string> and call addAnnounceUri().
|
// converted to std::vector<std::string> and call addAnnounceUri().
|
||||||
void adjustAnnounceUri
|
void adjustAnnounceUri
|
||||||
(const std::shared_ptr<TorrentAttribute>& attrs,
|
(TorrentAttribute* attrs, const std::shared_ptr<Option>& option);
|
||||||
const std::shared_ptr<Option>& option);
|
|
||||||
|
|
||||||
template<typename OutputIterator>
|
template<typename OutputIterator>
|
||||||
void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
|
void extractPeer(const ValueBase* peerData, int family, OutputIterator dest)
|
||||||
|
@ -346,7 +343,7 @@ const char* getModeString(BtFileMode mode);
|
||||||
template<typename Output>
|
template<typename Output>
|
||||||
void print(Output& o, const std::shared_ptr<DownloadContext>& dctx)
|
void print(Output& o, const std::shared_ptr<DownloadContext>& dctx)
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs = getTorrentAttrs(dctx);
|
TorrentAttribute* torrentAttrs = getTorrentAttrs(dctx);
|
||||||
o.write("*** BitTorrent File Information ***\n");
|
o.write("*** BitTorrent File Information ***\n");
|
||||||
if(!torrentAttrs->comment.empty()) {
|
if(!torrentAttrs->comment.empty()) {
|
||||||
o.printf("Comment: %s\n", torrentAttrs->comment.c_str());
|
o.printf("Comment: %s\n", torrentAttrs->comment.c_str());
|
||||||
|
|
|
@ -244,8 +244,7 @@ createBtMagnetRequestGroup
|
||||||
rg->setFileAllocationEnabled(false);
|
rg->setFileAllocationEnabled(false);
|
||||||
rg->setPreLocalFileCheckEnabled(false);
|
rg->setPreLocalFileCheckEnabled(false);
|
||||||
bittorrent::loadMagnet(magnetLink, dctx);
|
bittorrent::loadMagnet(magnetLink, dctx);
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs =
|
auto torrentAttrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
bittorrent::getTorrentAttrs(dctx);
|
|
||||||
bittorrent::adjustAnnounceUri(torrentAttrs, option);
|
bittorrent::adjustAnnounceUri(torrentAttrs, option);
|
||||||
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
|
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
|
||||||
rg->setDownloadContext(dctx);
|
rg->setDownloadContext(dctx);
|
||||||
|
|
|
@ -260,7 +260,7 @@ void BittorrentHelperTest::testOverrideName()
|
||||||
void BittorrentHelperTest::testGetAnnounceTier() {
|
void BittorrentHelperTest::testGetAnnounceTier() {
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
load(A2_TEST_DIR"/single.torrent", dctx, option_);
|
load(A2_TEST_DIR"/single.torrent", dctx, option_);
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
// There is 1 tier.
|
// There is 1 tier.
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList.size());
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ void BittorrentHelperTest::testGetAnnounceTier() {
|
||||||
void BittorrentHelperTest::testGetAnnounceTierAnnounceList() {
|
void BittorrentHelperTest::testGetAnnounceTierAnnounceList() {
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
load(A2_TEST_DIR"/test.torrent", dctx, option_);
|
load(A2_TEST_DIR"/test.torrent", dctx, option_);
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
// There are 3 tiers.
|
// There are 3 tiers.
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)3, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)3, attrs->announceList.size());
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->nodes.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), attrs->nodes[0].first);
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), attrs->nodes[0].first);
|
||||||
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, attrs->nodes[0].second);
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, attrs->nodes[0].second);
|
||||||
|
@ -554,7 +554,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
||||||
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
||||||
|
@ -572,7 +572,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
||||||
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
||||||
|
@ -590,7 +590,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
||||||
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
||||||
|
@ -607,7 +607,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)0, attrs->nodes.size());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -623,7 +623,7 @@ void BittorrentHelperTest::testGetNodes()
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
loadFromMemory(memory, dctx, option_, "default");
|
loadFromMemory(memory, dctx, option_, "default");
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), attrs->nodes[0].first);
|
||||||
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, attrs->nodes[0].second);
|
||||||
|
@ -749,7 +749,7 @@ void BittorrentHelperTest::testMetadata() {
|
||||||
std::shared_ptr<ValueBase> tr = bencode2::decode(torrentData);
|
std::shared_ptr<ValueBase> tr = bencode2::decode(torrentData);
|
||||||
std::shared_ptr<ValueBase> infoDic = downcast<Dict>(tr)->get("info");
|
std::shared_ptr<ValueBase> infoDic = downcast<Dict>(tr)->get("info");
|
||||||
std::string metadata = bencode2::encode(infoDic);
|
std::string metadata = bencode2::encode(infoDic);
|
||||||
std::shared_ptr<TorrentAttribute> attrs = getTorrentAttrs(dctx);
|
auto attrs = getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT(metadata == attrs->metadata);
|
CPPUNIT_ASSERT(metadata == attrs->metadata);
|
||||||
CPPUNIT_ASSERT_EQUAL(metadata.size(), attrs->metadataSize);
|
CPPUNIT_ASSERT_EQUAL(metadata.size(), attrs->metadataSize);
|
||||||
}
|
}
|
||||||
|
@ -759,7 +759,7 @@ void BittorrentHelperTest::testParseMagnet()
|
||||||
std::string magnet =
|
std::string magnet =
|
||||||
"magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"
|
"magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"
|
||||||
"&tr=http://tracker1&tr=http://tracker2";
|
"&tr=http://tracker1&tr=http://tracker2";
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::parseMagnet(magnet);
|
auto attrs = bittorrent::parseMagnet(magnet);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
||||||
util::toHex(attrs->infoHash));
|
util::toHex(attrs->infoHash));
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("[METADATA]aria2"), attrs->name);
|
CPPUNIT_ASSERT_EQUAL(std::string("[METADATA]aria2"), attrs->name);
|
||||||
|
@ -788,7 +788,7 @@ void BittorrentHelperTest::testParseMagnet_base32()
|
||||||
std::string infoHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
std::string infoHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
||||||
std::string base32InfoHash = base32::encode(fromHex(infoHash));
|
std::string base32InfoHash = base32::encode(fromHex(infoHash));
|
||||||
std::string magnet = "magnet:?xt=urn:btih:"+base32InfoHash+"&dn=aria2";
|
std::string magnet = "magnet:?xt=urn:btih:"+base32InfoHash+"&dn=aria2";
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::parseMagnet(magnet);
|
auto attrs = bittorrent::parseMagnet(magnet);
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
||||||
util::toHex(attrs->infoHash));
|
util::toHex(attrs->infoHash));
|
||||||
|
@ -796,19 +796,19 @@ void BittorrentHelperTest::testParseMagnet_base32()
|
||||||
|
|
||||||
void BittorrentHelperTest::testMetadata2Torrent()
|
void BittorrentHelperTest::testMetadata2Torrent()
|
||||||
{
|
{
|
||||||
|
TorrentAttribute attrs;
|
||||||
std::string metadata = "METADATA";
|
std::string metadata = "METADATA";
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(std::string("d4:infoMETADATAe"), metadata2Torrent(metadata, attrs));
|
(std::string("d4:infoMETADATAe"), metadata2Torrent(metadata, &attrs));
|
||||||
attrs->announceList.push_back(std::vector<std::string>());
|
attrs.announceList.push_back(std::vector<std::string>());
|
||||||
attrs->announceList[0].push_back("http://localhost/announce");
|
attrs.announceList[0].push_back("http://localhost/announce");
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(std::string("d"
|
(std::string("d"
|
||||||
"13:announce-list"
|
"13:announce-list"
|
||||||
"ll25:http://localhost/announceee"
|
"ll25:http://localhost/announceee"
|
||||||
"4:infoMETADATA"
|
"4:infoMETADATA"
|
||||||
"e"),
|
"e"),
|
||||||
metadata2Torrent(metadata, attrs));
|
metadata2Torrent(metadata, &attrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testTorrent2Magnet()
|
void BittorrentHelperTest::testTorrent2Magnet()
|
||||||
|
@ -927,78 +927,78 @@ void BittorrentHelperTest::testUnpackcompact()
|
||||||
|
|
||||||
void BittorrentHelperTest::testRemoveAnnounceUri()
|
void BittorrentHelperTest::testRemoveAnnounceUri()
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
TorrentAttribute attrs;
|
||||||
std::vector<std::string> tier1;
|
std::vector<std::string> tier1;
|
||||||
tier1.push_back("http://host1/announce");
|
tier1.push_back("http://host1/announce");
|
||||||
std::vector<std::string> tier2;
|
std::vector<std::string> tier2;
|
||||||
tier2.push_back("http://host2/announce");
|
tier2.push_back("http://host2/announce");
|
||||||
tier2.push_back("http://host3/announce");
|
tier2.push_back("http://host3/announce");
|
||||||
attrs->announceList.push_back(tier1);
|
attrs.announceList.push_back(tier1);
|
||||||
attrs->announceList.push_back(tier2);
|
attrs.announceList.push_back(tier2);
|
||||||
|
|
||||||
std::vector<std::string> removeUris;
|
std::vector<std::string> removeUris;
|
||||||
removeUris.push_back(tier1[0]);
|
removeUris.push_back(tier1[0]);
|
||||||
removeUris.push_back(tier2[0]);
|
removeUris.push_back(tier2[0]);
|
||||||
removeAnnounceUri(attrs, removeUris);
|
removeAnnounceUri(&attrs, removeUris);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host3/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host3/announce"),
|
||||||
attrs->announceList[0][0]);
|
attrs.announceList[0][0]);
|
||||||
|
|
||||||
removeUris.clear();
|
removeUris.clear();
|
||||||
removeUris.push_back("*");
|
removeUris.push_back("*");
|
||||||
|
|
||||||
removeAnnounceUri(attrs, removeUris);
|
removeAnnounceUri(&attrs, removeUris);
|
||||||
CPPUNIT_ASSERT(attrs->announceList.empty());
|
CPPUNIT_ASSERT(attrs.announceList.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testAddAnnounceUri()
|
void BittorrentHelperTest::testAddAnnounceUri()
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
TorrentAttribute attrs;
|
||||||
std::vector<std::string> addUris;
|
std::vector<std::string> addUris;
|
||||||
addUris.push_back("http://host1/announce");
|
addUris.push_back("http://host1/announce");
|
||||||
addUris.push_back("http://host2/announce");
|
addUris.push_back("http://host2/announce");
|
||||||
addAnnounceUri(attrs, addUris);
|
addAnnounceUri(&attrs, addUris);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs.announceList.size());
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList[0].size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList[0].size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host1/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host1/announce"),
|
||||||
attrs->announceList[0][0]);
|
attrs.announceList[0][0]);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList[1].size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList[1].size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host2/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host2/announce"),
|
||||||
attrs->announceList[1][0]);
|
attrs.announceList[1][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testAdjustAnnounceUri()
|
void BittorrentHelperTest::testAdjustAnnounceUri()
|
||||||
{
|
{
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
TorrentAttribute attrs;
|
||||||
std::vector<std::string> tier1;
|
std::vector<std::string> tier1;
|
||||||
tier1.push_back("http://host1/announce");
|
tier1.push_back("http://host1/announce");
|
||||||
std::vector<std::string> tier2;
|
std::vector<std::string> tier2;
|
||||||
tier2.push_back("http://host2/announce");
|
tier2.push_back("http://host2/announce");
|
||||||
tier2.push_back("http://host3/announce");
|
tier2.push_back("http://host3/announce");
|
||||||
attrs->announceList.push_back(tier1);
|
attrs.announceList.push_back(tier1);
|
||||||
attrs->announceList.push_back(tier2);
|
attrs.announceList.push_back(tier2);
|
||||||
|
|
||||||
std::shared_ptr<Option> option(new Option());
|
std::shared_ptr<Option> option(new Option());
|
||||||
option->put(PREF_BT_TRACKER, "http://host1/announce,http://host4/announce");
|
option->put(PREF_BT_TRACKER, "http://host1/announce,http://host4/announce");
|
||||||
option->put(PREF_BT_EXCLUDE_TRACKER,
|
option->put(PREF_BT_EXCLUDE_TRACKER,
|
||||||
"http://host1/announce,http://host2/announce");
|
"http://host1/announce,http://host2/announce");
|
||||||
adjustAnnounceUri(attrs, option);
|
adjustAnnounceUri(&attrs, option);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)3, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)3, attrs.announceList.size());
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList[0].size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList[0].size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host3/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host3/announce"),
|
||||||
attrs->announceList[0][0]);
|
attrs.announceList[0][0]);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList[1].size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList[1].size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host1/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host1/announce"),
|
||||||
attrs->announceList[1][0]);
|
attrs.announceList[1][0]);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList[2].size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs.announceList[2].size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://host4/announce"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host4/announce"),
|
||||||
attrs->announceList[2][0]);
|
attrs.announceList[2][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace bittorrent
|
} // namespace bittorrent
|
||||||
|
|
|
@ -192,9 +192,8 @@ void BtDependencyTest::testResolve_metadata()
|
||||||
pieceStorage->setDiskAdaptor(diskAdaptor);
|
pieceStorage->setDiskAdaptor(diskAdaptor);
|
||||||
pieceStorage->setDownloadFinished(true);
|
pieceStorage->setDownloadFinished(true);
|
||||||
dependee->setPieceStorage(pieceStorage);
|
dependee->setPieceStorage(pieceStorage);
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
dependee->getDownloadContext()->setAttribute(CTX_ATTR_BT,
|
||||||
dependee->getDownloadContext()->setAttribute(CTX_ATTR_BT, attrs);
|
make_unique<TorrentAttribute>());
|
||||||
|
|
||||||
BtDependency dep(dependant.get(), dependee);
|
BtDependency dep(dependant.get(), dependee);
|
||||||
CPPUNIT_ASSERT(dep.resolve());
|
CPPUNIT_ASSERT(dep.resolve());
|
||||||
|
|
||||||
|
|
|
@ -66,13 +66,16 @@ void BtRegistryTest::testGetDownloadContext_infoHash()
|
||||||
{
|
{
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
addTwoDownloadContext(btRegistry);
|
addTwoDownloadContext(btRegistry);
|
||||||
std::shared_ptr<TorrentAttribute> attrs1(new TorrentAttribute());
|
{
|
||||||
attrs1->infoHash = "hash1";
|
auto attrs1 = make_unique<TorrentAttribute>();
|
||||||
std::shared_ptr<TorrentAttribute> attrs2(new TorrentAttribute());
|
attrs1->infoHash = "hash1";
|
||||||
attrs2->infoHash = "hash2";
|
auto attrs2 = make_unique<TorrentAttribute>();
|
||||||
btRegistry.getDownloadContext(1)->setAttribute(CTX_ATTR_BT, attrs1);
|
attrs2->infoHash = "hash2";
|
||||||
btRegistry.getDownloadContext(2)->setAttribute(CTX_ATTR_BT, attrs2);
|
btRegistry.getDownloadContext(1)->setAttribute(CTX_ATTR_BT,
|
||||||
|
std::move(attrs1));
|
||||||
|
btRegistry.getDownloadContext(2)->setAttribute(CTX_ATTR_BT,
|
||||||
|
std::move(attrs2));
|
||||||
|
}
|
||||||
CPPUNIT_ASSERT(btRegistry.getDownloadContext("hash1"));
|
CPPUNIT_ASSERT(btRegistry.getDownloadContext("hash1"));
|
||||||
CPPUNIT_ASSERT(btRegistry.getDownloadContext("hash1").get() ==
|
CPPUNIT_ASSERT(btRegistry.getDownloadContext("hash1").get() ==
|
||||||
btRegistry.getDownloadContext(1).get());
|
btRegistry.getDownloadContext(1).get());
|
||||||
|
|
|
@ -61,9 +61,11 @@ public:
|
||||||
std::string peerId = "-aria2-ultrafastdltl";
|
std::string peerId = "-aria2-ultrafastdltl";
|
||||||
|
|
||||||
dctx_.reset(new DownloadContext(pieceLength, totalLength));
|
dctx_.reset(new DownloadContext(pieceLength, totalLength));
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs(new TorrentAttribute());
|
{
|
||||||
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
auto torrentAttrs = make_unique<TorrentAttribute>();
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, torrentAttrs);
|
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
||||||
|
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
|
||||||
|
}
|
||||||
dctx_->getNetStat().updateDownloadLength(pieceLength*5);
|
dctx_->getNetStat().updateDownloadLength(pieceLength*5);
|
||||||
dctx_->getNetStat().updateUploadLength(pieceLength*6);
|
dctx_->getNetStat().updateUploadLength(pieceLength*6);
|
||||||
bittorrent::setStaticPeerId(peerId);
|
bittorrent::setStaticPeerId(peerId);
|
||||||
|
|
|
@ -70,9 +70,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
dctx_.reset(new DownloadContext());
|
dctx_.reset(new DownloadContext());
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs(new TorrentAttribute());
|
{
|
||||||
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
auto torrentAttrs = make_unique<TorrentAttribute>();
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, torrentAttrs);
|
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
||||||
|
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
|
||||||
|
}
|
||||||
const std::shared_ptr<FileEntry> fileEntries[] = {
|
const std::shared_ptr<FileEntry> fileEntries[] = {
|
||||||
std::shared_ptr<FileEntry>(new FileEntry("/path/to/file",totalLength,0))
|
std::shared_ptr<FileEntry>(new FileEntry("/path/to/file",totalLength,0))
|
||||||
};
|
};
|
||||||
|
|
|
@ -336,8 +336,7 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
||||||
CPPUNIT_ASSERT_EQUAL(array[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
|
CPPUNIT_ASSERT_EQUAL(array[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT_EQUAL(5, group->getNumConcurrentCommand());
|
CPPUNIT_ASSERT_EQUAL(5, group->getNumConcurrentCommand());
|
||||||
std::shared_ptr<TorrentAttribute> attrs =
|
auto attrs = bittorrent::getTorrentAttrs(group->getDownloadContext());
|
||||||
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
|
||||||
// http://tracker1 was deleted.
|
// http://tracker1 was deleted.
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->announceList.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->announceList.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,7 @@ void HandshakeExtensionMessageTest::testDoReceivedAction()
|
||||||
RequestGroup rg(GroupId::create(), op);
|
RequestGroup rg(GroupId::create(), op);
|
||||||
rg.setDownloadContext(dctx);
|
rg.setDownloadContext(dctx);
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
dctx->setAttribute(CTX_ATTR_BT, make_unique<TorrentAttribute>());
|
||||||
dctx->setAttribute(CTX_ATTR_BT, attrs);
|
|
||||||
dctx->markTotalLengthIsUnknown();
|
dctx->markTotalLengthIsUnknown();
|
||||||
|
|
||||||
std::shared_ptr<Peer> peer(new Peer("192.168.0.1", 0));
|
std::shared_ptr<Peer> peer(new Peer("192.168.0.1", 0));
|
||||||
|
@ -122,6 +121,7 @@ void HandshakeExtensionMessageTest::testDoReceivedAction()
|
||||||
peer->getExtensionMessageID
|
peer->getExtensionMessageID
|
||||||
(ExtensionMessageRegistry::UT_METADATA));
|
(ExtensionMessageRegistry::UT_METADATA));
|
||||||
CPPUNIT_ASSERT(peer->isSeeder());
|
CPPUNIT_ASSERT(peer->isSeeder());
|
||||||
|
auto attrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, attrs->metadataSize);
|
CPPUNIT_ASSERT_EQUAL((size_t)1024, attrs->metadataSize);
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)1024, dctx->getTotalLength());
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024, dctx->getTotalLength());
|
||||||
CPPUNIT_ASSERT(dctx->knowsTotalLength());
|
CPPUNIT_ASSERT(dctx->knowsTotalLength());
|
||||||
|
|
|
@ -33,9 +33,11 @@ public:
|
||||||
dctx_.reset(new DownloadContext());
|
dctx_.reset(new DownloadContext());
|
||||||
unsigned char infoHash[20];
|
unsigned char infoHash[20];
|
||||||
memset(infoHash, 0, sizeof(infoHash));
|
memset(infoHash, 0, sizeof(infoHash));
|
||||||
std::shared_ptr<TorrentAttribute> torrentAttrs(new TorrentAttribute());
|
{
|
||||||
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
auto torrentAttrs = make_unique<TorrentAttribute>();
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, torrentAttrs);
|
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
||||||
|
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testHandshake();
|
void testHandshake();
|
||||||
|
|
|
@ -949,7 +949,7 @@ void RpcMethodTest::testGatherBitTorrentMetadata()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker3"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker3"),
|
||||||
downcast<String>(downcast<List>(announceList->get(2))->get(0))->s());
|
downcast<String>(downcast<List>(announceList->get(2))->get(0))->s());
|
||||||
// Remove some keys
|
// Remove some keys
|
||||||
std::shared_ptr<TorrentAttribute> modBtAttrs = bittorrent::getTorrentAttrs(dctx);
|
auto modBtAttrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
modBtAttrs->comment.clear();
|
modBtAttrs->comment.clear();
|
||||||
modBtAttrs->creationDate = 0;
|
modBtAttrs->creationDate = 0;
|
||||||
modBtAttrs->mode = BT_FILE_MODE_NONE;
|
modBtAttrs->mode = BT_FILE_MODE_NONE;
|
||||||
|
|
|
@ -73,7 +73,6 @@ void UTMetadataDataExtensionMessageTest::testDoReceivedAction()
|
||||||
std::shared_ptr<UTMetadataRequestTracker> tracker
|
std::shared_ptr<UTMetadataRequestTracker> tracker
|
||||||
(new UTMetadataRequestTracker());
|
(new UTMetadataRequestTracker());
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
|
||||||
|
|
||||||
std::string piece0 = std::string(METADATA_PIECE_SIZE, '0');
|
std::string piece0 = std::string(METADATA_PIECE_SIZE, '0');
|
||||||
std::string piece1 = std::string(METADATA_PIECE_SIZE, '1');
|
std::string piece1 = std::string(METADATA_PIECE_SIZE, '1');
|
||||||
|
@ -83,9 +82,11 @@ void UTMetadataDataExtensionMessageTest::testDoReceivedAction()
|
||||||
message_digest::digest(infoHash, INFO_HASH_LENGTH,
|
message_digest::digest(infoHash, INFO_HASH_LENGTH,
|
||||||
MessageDigest::sha1(),
|
MessageDigest::sha1(),
|
||||||
metadata.data(), metadata.size());
|
metadata.data(), metadata.size());
|
||||||
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
{
|
||||||
dctx->setAttribute(CTX_ATTR_BT, attrs);
|
auto attrs = make_unique<TorrentAttribute>();
|
||||||
|
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
||||||
|
dctx->setAttribute(CTX_ATTR_BT, std::move(attrs));
|
||||||
|
}
|
||||||
UTMetadataDataExtensionMessage m(1);
|
UTMetadataDataExtensionMessage m(1);
|
||||||
m.setPieceStorage(pieceStorage);
|
m.setPieceStorage(pieceStorage);
|
||||||
m.setUTMetadataRequestTracker(tracker.get());
|
m.setUTMetadataRequestTracker(tracker.get());
|
||||||
|
|
|
@ -52,11 +52,11 @@ void UTMetadataPostDownloadHandlerTest::testCanHandle()
|
||||||
|
|
||||||
CPPUNIT_ASSERT(!handler.canHandle(requestGroup_.get()));
|
CPPUNIT_ASSERT(!handler.canHandle(requestGroup_.get()));
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
dctx_->setAttribute(CTX_ATTR_BT, make_unique<TorrentAttribute>());
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, attrs);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT(handler.canHandle(requestGroup_.get()));
|
CPPUNIT_ASSERT(handler.canHandle(requestGroup_.get()));
|
||||||
|
|
||||||
|
auto attrs = bittorrent::getTorrentAttrs(dctx_);
|
||||||
// Only checks whether metadata is empty or not
|
// Only checks whether metadata is empty or not
|
||||||
attrs->metadata = "metadata";
|
attrs->metadata = "metadata";
|
||||||
|
|
||||||
|
@ -77,14 +77,16 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
||||||
(infoHash, sizeof(infoHash), MessageDigest::sha1(),
|
(infoHash, sizeof(infoHash), MessageDigest::sha1(),
|
||||||
reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size());
|
reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size());
|
||||||
dctx_->getFirstFileEntry()->setLength(metadata.size());
|
dctx_->getFirstFileEntry()->setLength(metadata.size());
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
|
||||||
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
|
||||||
std::vector<std::vector<std::string> > announceList;
|
std::vector<std::vector<std::string> > announceList;
|
||||||
std::vector<std::string> announceTier;
|
std::vector<std::string> announceTier;
|
||||||
announceTier.push_back("http://tracker");
|
announceTier.push_back("http://tracker");
|
||||||
announceList.push_back(announceTier);
|
announceList.push_back(announceTier);
|
||||||
attrs->announceList = announceList;
|
{
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, attrs);
|
auto attrs = make_unique<TorrentAttribute>();
|
||||||
|
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
||||||
|
attrs->announceList = announceList;
|
||||||
|
dctx_->setAttribute(CTX_ATTR_BT, std::move(attrs));
|
||||||
|
}
|
||||||
requestGroup_->setDiskWriterFactory
|
requestGroup_->setDiskWriterFactory
|
||||||
(std::shared_ptr<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
|
(std::shared_ptr<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
|
||||||
requestGroup_->initPieceStorage();
|
requestGroup_->initPieceStorage();
|
||||||
|
@ -99,8 +101,7 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, results.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, results.size());
|
||||||
std::shared_ptr<RequestGroup> newRg = results.front();
|
std::shared_ptr<RequestGroup> newRg = results.front();
|
||||||
std::shared_ptr<DownloadContext> newDctx = newRg->getDownloadContext();
|
std::shared_ptr<DownloadContext> newDctx = newRg->getDownloadContext();
|
||||||
std::shared_ptr<TorrentAttribute> newAttrs =
|
auto newAttrs = bittorrent::getTorrentAttrs(newDctx);
|
||||||
bittorrent::getTorrentAttrs(newDctx);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bittorrent::getInfoHashString(dctx_),
|
CPPUNIT_ASSERT_EQUAL(bittorrent::getInfoHashString(dctx_),
|
||||||
bittorrent::getInfoHashString(newDctx));
|
bittorrent::getInfoHashString(newDctx));
|
||||||
const std::vector<std::vector<std::string> >& newAnnounceList =
|
const std::vector<std::vector<std::string> >& newAnnounceList =
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
dispatcher_.reset(new MockBtMessageDispatcher());
|
dispatcher_.reset(new MockBtMessageDispatcher());
|
||||||
dctx_.reset(new DownloadContext());
|
dctx_.reset(new DownloadContext());
|
||||||
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
std::shared_ptr<TorrentAttribute> attrs(new TorrentAttribute());
|
||||||
dctx_->setAttribute(CTX_ATTR_BT, attrs);
|
dctx_->setAttribute(CTX_ATTR_BT, make_unique<TorrentAttribute>());
|
||||||
peer_.reset(new Peer("host", 6880));
|
peer_.reset(new Peer("host", 6880));
|
||||||
peer_->allocateSessionResource(0, 0);
|
peer_->allocateSessionResource(0, 0);
|
||||||
peer_->setExtension(ExtensionMessageRegistry::UT_METADATA, 1);
|
peer_->setExtension(ExtensionMessageRegistry::UT_METADATA, 1);
|
||||||
|
@ -125,7 +125,7 @@ void UTMetadataRequestExtensionMessageTest::testDoReceivedAction_data()
|
||||||
msg.setBtMessageDispatcher(dispatcher_.get());
|
msg.setBtMessageDispatcher(dispatcher_.get());
|
||||||
|
|
||||||
size_t metadataSize = METADATA_PIECE_SIZE*2;
|
size_t metadataSize = METADATA_PIECE_SIZE*2;
|
||||||
std::shared_ptr<TorrentAttribute> attrs = bittorrent::getTorrentAttrs(dctx_);
|
auto attrs = bittorrent::getTorrentAttrs(dctx_);
|
||||||
std::string first(METADATA_PIECE_SIZE, '0');
|
std::string first(METADATA_PIECE_SIZE, '0');
|
||||||
std::string second(METADATA_PIECE_SIZE, '1');
|
std::string second(METADATA_PIECE_SIZE, '1');
|
||||||
attrs->metadata = first+second;
|
attrs->metadata = first+second;
|
||||||
|
|
Loading…
Reference in New Issue