mirror of https://github.com/aria2/aria2
Changed interface of BtRegistry.
BtRegistry now uses SharedHandle<BtObject> instead of BtObject.pull/2/head
parent
a88a8b4ed1
commit
9a51cc356b
|
@ -42,6 +42,7 @@
|
||||||
#include "BtProgressInfoFile.h"
|
#include "BtProgressInfoFile.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "LpdMessageReceiver.h"
|
#include "LpdMessageReceiver.h"
|
||||||
|
#include "NullHandle.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -51,37 +52,41 @@ BtRegistry::BtRegistry()
|
||||||
|
|
||||||
BtRegistry::~BtRegistry() {}
|
BtRegistry::~BtRegistry() {}
|
||||||
|
|
||||||
SharedHandle<DownloadContext>
|
const SharedHandle<DownloadContext>&
|
||||||
BtRegistry::getDownloadContext(a2_gid_t gid) const
|
BtRegistry::getDownloadContext(a2_gid_t gid) const
|
||||||
{
|
{
|
||||||
return get(gid).downloadContext_;
|
const SharedHandle<BtObject>& res = get(gid);
|
||||||
|
if(res) {
|
||||||
|
return res->downloadContext;
|
||||||
|
} else {
|
||||||
|
return getNull<DownloadContext>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<DownloadContext>
|
const SharedHandle<DownloadContext>&
|
||||||
BtRegistry::getDownloadContext(const std::string& infoHash) const
|
BtRegistry::getDownloadContext(const std::string& infoHash) const
|
||||||
{
|
{
|
||||||
SharedHandle<DownloadContext> dctx;
|
for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
|
||||||
for(std::map<a2_gid_t, BtObject>::const_iterator i = pool_.begin(),
|
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
|
||||||
eoi = pool_.end(); i != eoi; ++i) {
|
if(bittorrent::getTorrentAttrs((*i).second->downloadContext)->infoHash ==
|
||||||
if(bittorrent::getTorrentAttrs((*i).second.downloadContext_)->infoHash ==
|
|
||||||
infoHash) {
|
infoHash) {
|
||||||
dctx = (*i).second.downloadContext_;
|
return (*i).second->downloadContext;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dctx;
|
return getNull<DownloadContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistry::put(a2_gid_t gid, const BtObject& obj)
|
void BtRegistry::put(a2_gid_t gid, const SharedHandle<BtObject>& obj)
|
||||||
{
|
{
|
||||||
pool_[gid] = obj;
|
pool_[gid] = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
BtObject BtRegistry::get(a2_gid_t gid) const
|
const SharedHandle<BtObject>& BtRegistry::get(a2_gid_t gid) const
|
||||||
{
|
{
|
||||||
std::map<a2_gid_t, BtObject>::const_iterator i = pool_.find(gid);
|
std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
|
||||||
|
pool_.find(gid);
|
||||||
if(i == pool_.end()) {
|
if(i == pool_.end()) {
|
||||||
return BtObject();
|
return getNull<BtObject>();
|
||||||
} else {
|
} else {
|
||||||
return (*i).second;
|
return (*i).second;
|
||||||
}
|
}
|
||||||
|
@ -109,23 +114,23 @@ BtObject::BtObject
|
||||||
const SharedHandle<BtAnnounce>& btAnnounce,
|
const SharedHandle<BtAnnounce>& btAnnounce,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
|
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
|
||||||
: downloadContext_(downloadContext),
|
: downloadContext(downloadContext),
|
||||||
pieceStorage_(pieceStorage),
|
pieceStorage(pieceStorage),
|
||||||
peerStorage_(peerStorage),
|
peerStorage(peerStorage),
|
||||||
btAnnounce_(btAnnounce),
|
btAnnounce(btAnnounce),
|
||||||
btRuntime_(btRuntime),
|
btRuntime(btRuntime),
|
||||||
btProgressInfoFile_(btProgressInfoFile)
|
btProgressInfoFile(btProgressInfoFile)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BtObject::BtObject() {}
|
BtObject::BtObject() {}
|
||||||
|
|
||||||
BtObject::BtObject(const BtObject& c)
|
BtObject::BtObject(const BtObject& c)
|
||||||
: downloadContext_(c.downloadContext_),
|
: downloadContext(c.downloadContext),
|
||||||
pieceStorage_(c.pieceStorage_),
|
pieceStorage(c.pieceStorage),
|
||||||
peerStorage_(c.peerStorage_),
|
peerStorage(c.peerStorage),
|
||||||
btAnnounce_(c.btAnnounce_),
|
btAnnounce(c.btAnnounce),
|
||||||
btRuntime_(c.btRuntime_),
|
btRuntime(c.btRuntime),
|
||||||
btProgressInfoFile_(c.btProgressInfoFile_)
|
btProgressInfoFile(c.btProgressInfoFile)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BtObject::~BtObject() {}
|
BtObject::~BtObject() {}
|
||||||
|
@ -133,24 +138,14 @@ BtObject::~BtObject() {}
|
||||||
BtObject& BtObject::operator=(const BtObject& c)
|
BtObject& BtObject::operator=(const BtObject& c)
|
||||||
{
|
{
|
||||||
if(this != &c) {
|
if(this != &c) {
|
||||||
downloadContext_ = c.downloadContext_;
|
downloadContext = c.downloadContext;
|
||||||
pieceStorage_ = c.pieceStorage_;
|
pieceStorage = c.pieceStorage;
|
||||||
peerStorage_ = c.peerStorage_;
|
peerStorage = c.peerStorage;
|
||||||
btAnnounce_ = c.btAnnounce_;
|
btAnnounce = c.btAnnounce;
|
||||||
btRuntime_ = c.btRuntime_;
|
btRuntime = c.btRuntime;
|
||||||
btProgressInfoFile_ = c.btProgressInfoFile_;
|
btProgressInfoFile = c.btProgressInfoFile;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BtObject::isNull() const
|
|
||||||
{
|
|
||||||
return !downloadContext_ &&
|
|
||||||
!pieceStorage_ &&
|
|
||||||
!peerStorage_ &&
|
|
||||||
!btAnnounce_ &&
|
|
||||||
!btRuntime_ &&
|
|
||||||
!btProgressInfoFile_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -53,12 +53,12 @@ class DownloadContext;
|
||||||
class LpdMessageReceiver;
|
class LpdMessageReceiver;
|
||||||
|
|
||||||
struct BtObject {
|
struct BtObject {
|
||||||
SharedHandle<DownloadContext> downloadContext_;
|
SharedHandle<DownloadContext> downloadContext;
|
||||||
SharedHandle<PieceStorage> pieceStorage_;
|
SharedHandle<PieceStorage> pieceStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage_;
|
SharedHandle<PeerStorage> peerStorage;
|
||||||
SharedHandle<BtAnnounce> btAnnounce_;
|
SharedHandle<BtAnnounce> btAnnounce;
|
||||||
SharedHandle<BtRuntime> btRuntime_;
|
SharedHandle<BtRuntime> btRuntime;
|
||||||
SharedHandle<BtProgressInfoFile> btProgressInfoFile_;
|
SharedHandle<BtProgressInfoFile> btProgressInfoFile;
|
||||||
|
|
||||||
BtObject(const SharedHandle<DownloadContext>& downloadContext,
|
BtObject(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
const SharedHandle<PieceStorage>& pieceStorage,
|
const SharedHandle<PieceStorage>& pieceStorage,
|
||||||
|
@ -74,35 +74,33 @@ struct BtObject {
|
||||||
~BtObject();
|
~BtObject();
|
||||||
|
|
||||||
BtObject& operator=(const BtObject& c);
|
BtObject& operator=(const BtObject& c);
|
||||||
|
|
||||||
bool isNull() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BtRegistry {
|
class BtRegistry {
|
||||||
private:
|
private:
|
||||||
std::map<a2_gid_t, BtObject> pool_;
|
std::map<a2_gid_t, SharedHandle<BtObject> > pool_;
|
||||||
uint16_t tcpPort_;
|
uint16_t tcpPort_;
|
||||||
SharedHandle<LpdMessageReceiver> lpdMessageReceiver_;
|
SharedHandle<LpdMessageReceiver> lpdMessageReceiver_;
|
||||||
public:
|
public:
|
||||||
BtRegistry();
|
BtRegistry();
|
||||||
~BtRegistry();
|
~BtRegistry();
|
||||||
|
|
||||||
SharedHandle<DownloadContext>
|
const SharedHandle<DownloadContext>&
|
||||||
getDownloadContext(a2_gid_t gid) const;
|
getDownloadContext(a2_gid_t gid) const;
|
||||||
|
|
||||||
SharedHandle<DownloadContext>
|
const SharedHandle<DownloadContext>&
|
||||||
getDownloadContext(const std::string& infoHash) const;
|
getDownloadContext(const std::string& infoHash) const;
|
||||||
|
|
||||||
void put(a2_gid_t gid, const BtObject& obj);
|
void put(a2_gid_t gid, const SharedHandle<BtObject>& obj);
|
||||||
|
|
||||||
BtObject get(a2_gid_t gid) const;
|
const SharedHandle<BtObject>& get(a2_gid_t gid) const;
|
||||||
|
|
||||||
template<typename OutputIterator>
|
template<typename OutputIterator>
|
||||||
OutputIterator getAllDownloadContext(OutputIterator dest)
|
OutputIterator getAllDownloadContext(OutputIterator dest)
|
||||||
{
|
{
|
||||||
for(std::map<a2_gid_t, BtObject>::const_iterator i = pool_.begin(),
|
for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
|
||||||
eoi = pool_.end(); i != eoi; ++i) {
|
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
|
||||||
*dest++ = (*i).second.downloadContext_;
|
*dest++ = (*i).second->downloadContext;
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,11 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
||||||
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
|
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
|
||||||
bool metadataGetMode = torrentAttrs->metadata.empty();
|
bool metadataGetMode = torrentAttrs->metadata.empty();
|
||||||
const SharedHandle<BtRegistry>& btReg = e->getBtRegistry();
|
const SharedHandle<BtRegistry>& btReg = e->getBtRegistry();
|
||||||
BtObject btObject = btReg->get(requestGroup->getGID());
|
const SharedHandle<BtObject>& btObject = btReg->get(requestGroup->getGID());
|
||||||
SharedHandle<PieceStorage> pieceStorage = btObject.pieceStorage_;
|
const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage = btObject.peerStorage_;
|
const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
|
||||||
SharedHandle<BtRuntime> btRuntime = btObject.btRuntime_;
|
const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime;
|
||||||
SharedHandle<BtAnnounce> btAnnounce = btObject.btAnnounce_;
|
const SharedHandle<BtAnnounce>& btAnnounce = btObject->btAnnounce;
|
||||||
// commands
|
// commands
|
||||||
{
|
{
|
||||||
TrackerWatcherCommand* c =
|
TrackerWatcherCommand* c =
|
||||||
|
|
|
@ -140,11 +140,10 @@ void printProgress
|
||||||
<< "CN:"
|
<< "CN:"
|
||||||
<< rg->getNumConnection();
|
<< rg->getNumConnection();
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
SharedHandle<PeerStorage> ps =
|
const SharedHandle<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
|
||||||
e->getBtRegistry()->get(rg->getGID()).peerStorage_;
|
if(btObj) {
|
||||||
if(ps) {
|
|
||||||
std::vector<SharedHandle<Peer> > peers;
|
std::vector<SharedHandle<Peer> > peers;
|
||||||
ps->getActivePeers(peers);
|
btObj->peerStorage->getActivePeers(peers);
|
||||||
o << " " << "SEED:"
|
o << " " << "SEED:"
|
||||||
<< countSeeder(peers.begin(), peers.end());
|
<< countSeeder(peers.begin(), peers.end());
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,9 +94,9 @@ bool LpdReceiveMessageCommand::execute()
|
||||||
}
|
}
|
||||||
RequestGroup* group = dctx->getOwnerRequestGroup();
|
RequestGroup* group = dctx->getOwnerRequestGroup();
|
||||||
assert(group);
|
assert(group);
|
||||||
BtObject btobj = reg->get(group->getGID());
|
const SharedHandle<BtObject>& btobj = reg->get(group->getGID());
|
||||||
assert(!btobj.isNull());
|
assert(btobj);
|
||||||
SharedHandle<PeerStorage> peerStorage = btobj.peerStorage_;
|
const SharedHandle<PeerStorage>& peerStorage = btobj->peerStorage;
|
||||||
assert(peerStorage);
|
assert(peerStorage);
|
||||||
SharedHandle<Peer> peer = m->peer;
|
SharedHandle<Peer> peer = m->peer;
|
||||||
if(peerStorage->addPeer(peer)) {
|
if(peerStorage->addPeer(peer)) {
|
||||||
|
|
|
@ -229,7 +229,8 @@ SRCS = Socket.h\
|
||||||
NullOutputFile.h\
|
NullOutputFile.h\
|
||||||
console.cc console.h\
|
console.cc console.h\
|
||||||
BufferedFile.cc BufferedFile.h\
|
BufferedFile.cc BufferedFile.h\
|
||||||
SegList.h
|
SegList.h\
|
||||||
|
NullHandle.h
|
||||||
|
|
||||||
if MINGW_BUILD
|
if MINGW_BUILD
|
||||||
SRCS += WinConsoleFile.cc WinConsoleFile.h
|
SRCS += WinConsoleFile.cc WinConsoleFile.h
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* <!-- copyright */
|
||||||
|
/*
|
||||||
|
* aria2 - The high speed download utility
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give
|
||||||
|
* permission to link the code of portions of this program with the
|
||||||
|
* OpenSSL library under certain conditions as described in each
|
||||||
|
* individual source file, and distribute linked combinations
|
||||||
|
* including the two.
|
||||||
|
* You must obey the GNU General Public License in all respects
|
||||||
|
* for all of the code used other than OpenSSL. If you modify
|
||||||
|
* file(s) with this exception, you may extend this exception to your
|
||||||
|
* version of the file(s), but you are not obligated to do so. If you
|
||||||
|
* do not wish to do so, delete this exception statement from your
|
||||||
|
* version. If you delete this exception statement from all source
|
||||||
|
* files in the program, then also delete it here.
|
||||||
|
*/
|
||||||
|
/* copyright --> */
|
||||||
|
#ifndef D_NULL_HANDLE_H
|
||||||
|
#define D_NULL_HANDLE_H
|
||||||
|
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
// Returns const reference of SharedHandle<T>(). Static variable null
|
||||||
|
// is shared by all instantiation of this function template.
|
||||||
|
template<typename T>
|
||||||
|
const SharedHandle<T>& getNull()
|
||||||
|
{
|
||||||
|
static SharedHandle<T> null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
|
#endif // D_NULL_HANDLE_H
|
|
@ -109,11 +109,12 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
||||||
(fmt("Unknown info hash %s",
|
(fmt("Unknown info hash %s",
|
||||||
util::toHex(infoHash).c_str()));
|
util::toHex(infoHash).c_str()));
|
||||||
}
|
}
|
||||||
BtObject btObject = getDownloadEngine()->getBtRegistry()->get
|
const SharedHandle<BtObject>& btObject =
|
||||||
|
getDownloadEngine()->getBtRegistry()->get
|
||||||
(downloadContext->getOwnerRequestGroup()->getGID());
|
(downloadContext->getOwnerRequestGroup()->getGID());
|
||||||
SharedHandle<BtRuntime> btRuntime = btObject.btRuntime_;
|
const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime;
|
||||||
SharedHandle<PieceStorage> pieceStorage = btObject.pieceStorage_;
|
const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage = btObject.peerStorage_;
|
const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
|
||||||
if(!btRuntime->ready()) {
|
if(!btRuntime->ready()) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("Unknown info hash %s",
|
(fmt("Unknown info hash %s",
|
||||||
|
|
|
@ -354,9 +354,10 @@ void RequestGroup::createInitialCommand
|
||||||
(option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
|
(option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
|
||||||
btAnnounce->shuffleAnnounce();
|
btAnnounce->shuffleAnnounce();
|
||||||
|
|
||||||
assert(btRegistry->get(gid_).isNull());
|
assert(!btRegistry->get(gid_));
|
||||||
btRegistry->put
|
btRegistry->put
|
||||||
(gid_, BtObject
|
(gid_, SharedHandle<BtObject>
|
||||||
|
(new BtObject
|
||||||
(downloadContext_,
|
(downloadContext_,
|
||||||
pieceStorage_,
|
pieceStorage_,
|
||||||
peerStorage,
|
peerStorage,
|
||||||
|
@ -364,7 +365,7 @@ void RequestGroup::createInitialCommand
|
||||||
btRuntime,
|
btRuntime,
|
||||||
(progressInfoFile ?
|
(progressInfoFile ?
|
||||||
SharedHandle<BtProgressInfoFile>(progressInfoFile) :
|
SharedHandle<BtProgressInfoFile>(progressInfoFile) :
|
||||||
progressInfoFile_)));
|
progressInfoFile_))));
|
||||||
if(metadataGetMode) {
|
if(metadataGetMode) {
|
||||||
if(option_->getAsBool(PREF_ENABLE_DHT) ||
|
if(option_->getAsBool(PREF_ENABLE_DHT) ||
|
||||||
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
||||||
|
|
|
@ -753,7 +753,7 @@ namespace {
|
||||||
void gatherProgressBitTorrent
|
void gatherProgressBitTorrent
|
||||||
(const SharedHandle<Dict>& entryDict,
|
(const SharedHandle<Dict>& entryDict,
|
||||||
const SharedHandle<TorrentAttribute>& torrentAttrs,
|
const SharedHandle<TorrentAttribute>& torrentAttrs,
|
||||||
const BtObject& btObject,
|
const SharedHandle<BtObject>& btObject,
|
||||||
const std::vector<std::string>& keys)
|
const std::vector<std::string>& keys)
|
||||||
{
|
{
|
||||||
if(requested_key(keys, KEY_INFO_HASH)) {
|
if(requested_key(keys, KEY_INFO_HASH)) {
|
||||||
|
@ -765,10 +765,10 @@ void gatherProgressBitTorrent
|
||||||
entryDict->put(KEY_BITTORRENT, btDict);
|
entryDict->put(KEY_BITTORRENT, btDict);
|
||||||
}
|
}
|
||||||
if(requested_key(keys, KEY_NUM_SEEDERS)) {
|
if(requested_key(keys, KEY_NUM_SEEDERS)) {
|
||||||
if(btObject.isNull()) {
|
if(!btObject) {
|
||||||
entryDict->put(KEY_NUM_SEEDERS, VLB_ZERO);
|
entryDict->put(KEY_NUM_SEEDERS, VLB_ZERO);
|
||||||
} else {
|
} else {
|
||||||
SharedHandle<PeerStorage> peerStorage = btObject.peerStorage_;
|
const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
|
||||||
assert(peerStorage);
|
assert(peerStorage);
|
||||||
std::vector<SharedHandle<Peer> > peers;
|
std::vector<SharedHandle<Peer> > peers;
|
||||||
peerStorage->getActivePeers(peers);
|
peerStorage->getActivePeers(peers);
|
||||||
|
@ -822,7 +822,8 @@ void gatherProgress
|
||||||
if(group->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) {
|
if(group->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) {
|
||||||
SharedHandle<TorrentAttribute> torrentAttrs =
|
SharedHandle<TorrentAttribute> torrentAttrs =
|
||||||
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
||||||
BtObject btObject = e->getBtRegistry()->get(group->getGID());
|
const SharedHandle<BtObject>& btObject =
|
||||||
|
e->getBtRegistry()->get(group->getGID());
|
||||||
gatherProgressBitTorrent(entryDict, torrentAttrs, btObject, keys);
|
gatherProgressBitTorrent(entryDict, torrentAttrs, btObject, keys);
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
@ -981,10 +982,11 @@ SharedHandle<ValueBase> GetPeersRpcMethod::process
|
||||||
util::itos(gid).c_str()));
|
util::itos(gid).c_str()));
|
||||||
}
|
}
|
||||||
SharedHandle<List> peers = List::g();
|
SharedHandle<List> peers = List::g();
|
||||||
BtObject btObject = e->getBtRegistry()->get(group->getGID());
|
const SharedHandle<BtObject>& btObject =
|
||||||
if(!btObject.isNull()) {
|
e->getBtRegistry()->get(group->getGID());
|
||||||
assert(btObject.peerStorage_);
|
if(btObject) {
|
||||||
gatherPeer(peers, btObject.peerStorage_);
|
assert(btObject->peerStorage);
|
||||||
|
gatherPeer(peers, btObject->peerStorage);
|
||||||
}
|
}
|
||||||
return peers;
|
return peers;
|
||||||
}
|
}
|
||||||
|
@ -1153,10 +1155,11 @@ void changeOption
|
||||||
group->setMaxUploadSpeedLimit(option.getAsInt(PREF_MAX_UPLOAD_LIMIT));
|
group->setMaxUploadSpeedLimit(option.getAsInt(PREF_MAX_UPLOAD_LIMIT));
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
BtObject btObject = e->getBtRegistry()->get(group->getGID());
|
const SharedHandle<BtObject>& btObject =
|
||||||
if(!btObject.isNull()) {
|
e->getBtRegistry()->get(group->getGID());
|
||||||
|
if(btObject) {
|
||||||
if(option.defined(PREF_BT_MAX_PEERS)) {
|
if(option.defined(PREF_BT_MAX_PEERS)) {
|
||||||
btObject.btRuntime_->setMaxPeers(option.getAsInt(PREF_BT_MAX_PEERS));
|
btObject->btRuntime->setMaxPeers(option.getAsInt(PREF_BT_MAX_PEERS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
|
@ -41,8 +41,8 @@ void BtRegistryTest::testGetDownloadContext()
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
CPPUNIT_ASSERT(!btRegistry.getDownloadContext(1));
|
CPPUNIT_ASSERT(!btRegistry.getDownloadContext(1));
|
||||||
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
||||||
BtObject btObject;
|
SharedHandle<BtObject> btObject(new BtObject());
|
||||||
btObject.downloadContext_ = dctx;
|
btObject->downloadContext = dctx;
|
||||||
btRegistry.put(1, btObject);
|
btRegistry.put(1, btObject);
|
||||||
CPPUNIT_ASSERT_EQUAL(dctx.get(), btRegistry.getDownloadContext(1).get());
|
CPPUNIT_ASSERT_EQUAL(dctx.get(), btRegistry.getDownloadContext(1).get());
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,10 @@ void addTwoDownloadContext(BtRegistry& btRegistry)
|
||||||
{
|
{
|
||||||
SharedHandle<DownloadContext> dctx1(new DownloadContext());
|
SharedHandle<DownloadContext> dctx1(new DownloadContext());
|
||||||
SharedHandle<DownloadContext> dctx2(new DownloadContext());
|
SharedHandle<DownloadContext> dctx2(new DownloadContext());
|
||||||
BtObject btObject1;
|
SharedHandle<BtObject> btObject1(new BtObject());
|
||||||
btObject1.downloadContext_ = dctx1;
|
btObject1->downloadContext = dctx1;
|
||||||
BtObject btObject2;
|
SharedHandle<BtObject> btObject2(new BtObject());
|
||||||
btObject2.downloadContext_ = dctx2;
|
btObject2->downloadContext = dctx2;
|
||||||
btRegistry.put(1, btObject1);
|
btRegistry.put(1, btObject1);
|
||||||
btRegistry.put(2, btObject2);
|
btRegistry.put(2, btObject2);
|
||||||
}
|
}
|
||||||
|
@ -95,8 +95,8 @@ void BtRegistryTest::testRemove()
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
addTwoDownloadContext(btRegistry);
|
addTwoDownloadContext(btRegistry);
|
||||||
CPPUNIT_ASSERT(btRegistry.remove(1));
|
CPPUNIT_ASSERT(btRegistry.remove(1));
|
||||||
CPPUNIT_ASSERT(btRegistry.get(1).isNull());
|
CPPUNIT_ASSERT(!btRegistry.get(1));
|
||||||
CPPUNIT_ASSERT(!btRegistry.get(2).isNull());
|
CPPUNIT_ASSERT(btRegistry.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistryTest::testRemoveAll()
|
void BtRegistryTest::testRemoveAll()
|
||||||
|
@ -104,8 +104,8 @@ void BtRegistryTest::testRemoveAll()
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
addTwoDownloadContext(btRegistry);
|
addTwoDownloadContext(btRegistry);
|
||||||
btRegistry.removeAll();
|
btRegistry.removeAll();
|
||||||
CPPUNIT_ASSERT(btRegistry.get(1).isNull());
|
CPPUNIT_ASSERT(!btRegistry.get(1));
|
||||||
CPPUNIT_ASSERT(btRegistry.get(2).isNull());
|
CPPUNIT_ASSERT(!btRegistry.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -452,8 +452,8 @@ void RpcMethodTest::testChangeOption()
|
||||||
opt->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT->k, "300K");
|
opt->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT->k, "300K");
|
||||||
opt->put(PREF_MAX_UPLOAD_LIMIT->k, "50K");
|
opt->put(PREF_MAX_UPLOAD_LIMIT->k, "50K");
|
||||||
|
|
||||||
BtObject btObject;
|
SharedHandle<BtObject> btObject(new BtObject());
|
||||||
btObject.btRuntime_ = SharedHandle<BtRuntime>(new BtRuntime());
|
btObject->btRuntime = SharedHandle<BtRuntime>(new BtRuntime());
|
||||||
e_->getBtRegistry()->put(group->getGID(), btObject);
|
e_->getBtRegistry()->put(group->getGID(), btObject);
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
req.params->append(opt);
|
req.params->append(opt);
|
||||||
|
@ -471,7 +471,7 @@ void RpcMethodTest::testChangeOption()
|
||||||
option->get(PREF_BT_REQUEST_PEER_SPEED_LIMIT));
|
option->get(PREF_BT_REQUEST_PEER_SPEED_LIMIT));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("100"), option->get(PREF_BT_MAX_PEERS));
|
CPPUNIT_ASSERT_EQUAL(std::string("100"), option->get(PREF_BT_MAX_PEERS));
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)100, btObject.btRuntime_->getMaxPeers());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)100, btObject->btRuntime->getMaxPeers());
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024,
|
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024,
|
||||||
group->getMaxUploadSpeedLimit());
|
group->getMaxUploadSpeedLimit());
|
||||||
|
|
Loading…
Reference in New Issue