summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BtRegistry.cc69
-rw-r--r--src/BtRegistry.h18
-rw-r--r--src/BtSetup.cc2
-rw-r--r--src/ConsoleStatCalc.cc2
-rw-r--r--src/LpdReceiveMessageCommand.cc2
-rw-r--r--src/PeerReceiveHandshakeCommand.cc3
-rw-r--r--src/RequestGroup.cc18
-rw-r--r--src/RpcMethodImpl.cc18
8 files changed, 46 insertions, 86 deletions
diff --git a/src/BtRegistry.cc b/src/BtRegistry.cc
index f38fd19f..84dfd9a8 100644
--- a/src/BtRegistry.cc
+++ b/src/BtRegistry.cc
@@ -48,16 +48,14 @@
namespace aria2 {
BtRegistry::BtRegistry()
- : tcpPort_(0),
- udpPort_(0)
+ : tcpPort_{0},
+ udpPort_{0}
{}
-BtRegistry::~BtRegistry() {}
-
const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(a2_gid_t gid) const
{
- const std::shared_ptr<BtObject>& res = get(gid);
+ auto res = get(gid);
if(res) {
return res->downloadContext;
} else {
@@ -68,29 +66,27 @@ BtRegistry::getDownloadContext(a2_gid_t gid) const
const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(const std::string& infoHash) const
{
- for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
- pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
- if(bittorrent::getTorrentAttrs((*i).second->downloadContext)->infoHash ==
+ for(auto& kv : pool_) {
+ if(bittorrent::getTorrentAttrs(kv.second->downloadContext)->infoHash ==
infoHash) {
- return (*i).second->downloadContext;
+ return kv.second->downloadContext;
}
}
return getNull<DownloadContext>();
}
-void BtRegistry::put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj)
+void BtRegistry::put(a2_gid_t gid, std::unique_ptr<BtObject> obj)
{
- pool_[gid] = obj;
+ pool_[gid] = std::move(obj);
}
-const std::shared_ptr<BtObject>& BtRegistry::get(a2_gid_t gid) const
+BtObject* BtRegistry::get(a2_gid_t gid) const
{
- std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
- pool_.find(gid);
- if(i == pool_.end()) {
- return getNull<BtObject>();
+ auto i = pool_.find(gid);
+ if(i == std::end(pool_)) {
+ return nullptr;
} else {
- return (*i).second;
+ return (*i).second.get();
}
}
@@ -99,7 +95,8 @@ bool BtRegistry::remove(a2_gid_t gid)
return pool_.erase(gid);
}
-void BtRegistry::removeAll() {
+void BtRegistry::removeAll()
+{
pool_.clear();
}
@@ -122,38 +119,14 @@ BtObject::BtObject
const std::shared_ptr<BtAnnounce>& btAnnounce,
const std::shared_ptr<BtRuntime>& btRuntime,
const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile)
- : downloadContext(downloadContext),
- pieceStorage(pieceStorage),
- peerStorage(peerStorage),
- btAnnounce(btAnnounce),
- btRuntime(btRuntime),
- btProgressInfoFile(btProgressInfoFile)
+ : downloadContext{downloadContext},
+ pieceStorage{pieceStorage},
+ peerStorage{peerStorage},
+ btAnnounce{btAnnounce},
+ btRuntime{btRuntime},
+ btProgressInfoFile{btProgressInfoFile}
{}
BtObject::BtObject() {}
-BtObject::BtObject(const BtObject& c)
- : downloadContext(c.downloadContext),
- pieceStorage(c.pieceStorage),
- peerStorage(c.peerStorage),
- btAnnounce(c.btAnnounce),
- btRuntime(c.btRuntime),
- btProgressInfoFile(c.btProgressInfoFile)
-{}
-
-BtObject::~BtObject() {}
-
-BtObject& BtObject::operator=(const BtObject& c)
-{
- if(this != &c) {
- downloadContext = c.downloadContext;
- pieceStorage = c.pieceStorage;
- peerStorage = c.peerStorage;
- btAnnounce = c.btAnnounce;
- btRuntime = c.btRuntime;
- btProgressInfoFile = c.btProgressInfoFile;
- }
- return *this;
-}
-
} // namespace aria2
diff --git a/src/BtRegistry.h b/src/BtRegistry.h
index 052bcd16..dc4cab90 100644
--- a/src/BtRegistry.h
+++ b/src/BtRegistry.h
@@ -69,17 +69,11 @@ struct BtObject {
const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile);
BtObject();
-
- BtObject(const BtObject& c);
-
- ~BtObject();
-
- BtObject& operator=(const BtObject& c);
};
class BtRegistry {
private:
- std::map<a2_gid_t, std::shared_ptr<BtObject> > pool_;
+ std::map<a2_gid_t, std::unique_ptr<BtObject>> pool_;
uint16_t tcpPort_;
// This is UDP port for DHT and UDP tracker. But currently UDP
// tracker is not supported in IPv6.
@@ -88,7 +82,6 @@ private:
std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
public:
BtRegistry();
- ~BtRegistry();
const std::shared_ptr<DownloadContext>&
getDownloadContext(a2_gid_t gid) const;
@@ -96,16 +89,15 @@ public:
const std::shared_ptr<DownloadContext>&
getDownloadContext(const std::string& infoHash) const;
- void put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj);
+ void put(a2_gid_t gid, std::unique_ptr<BtObject> obj);
- const std::shared_ptr<BtObject>& get(a2_gid_t gid) const;
+ BtObject* get(a2_gid_t gid) const;
template<typename OutputIterator>
OutputIterator getAllDownloadContext(OutputIterator dest)
{
- for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
- pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
- *dest++ = (*i).second->downloadContext;
+ for(auto& kv : pool_) {
+ *dest++ = kv.second->downloadContext;
}
return dest;
}
diff --git a/src/BtSetup.cc b/src/BtSetup.cc
index 31ee458e..438df6be 100644
--- a/src/BtSetup.cc
+++ b/src/BtSetup.cc
@@ -102,7 +102,7 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
bool metadataGetMode = torrentAttrs->metadata.empty();
auto& btReg = e->getBtRegistry();
- auto& btObject = btReg->get(requestGroup->getGID());
+ auto btObject = btReg->get(requestGroup->getGID());
auto& pieceStorage = btObject->pieceStorage;
auto& peerStorage = btObject->peerStorage;
auto& btRuntime = btObject->btRuntime;
diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc
index 362f91c5..8fb20a96 100644
--- a/src/ConsoleStatCalc.cc
+++ b/src/ConsoleStatCalc.cc
@@ -171,7 +171,7 @@ void printProgress
o << " CN:"
<< rg->getNumConnection();
#ifdef ENABLE_BITTORRENT
- const std::shared_ptr<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
+ auto btObj = e->getBtRegistry()->get(rg->getGID());
if(btObj) {
const PeerSet& peers = btObj->peerStorage->getUsedPeers();
o << " SD:"
diff --git a/src/LpdReceiveMessageCommand.cc b/src/LpdReceiveMessageCommand.cc
index a685e8a3..f17eff84 100644
--- a/src/LpdReceiveMessageCommand.cc
+++ b/src/LpdReceiveMessageCommand.cc
@@ -90,7 +90,7 @@ bool LpdReceiveMessageCommand::execute()
}
RequestGroup* group = dctx->getOwnerRequestGroup();
assert(group);
- auto& btobj = reg->get(group->getGID());
+ auto btobj = reg->get(group->getGID());
assert(btobj);
auto& peerStorage = btobj->peerStorage;
assert(peerStorage);
diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc
index 283ca4d7..6d69629b 100644
--- a/src/PeerReceiveHandshakeCommand.cc
+++ b/src/PeerReceiveHandshakeCommand.cc
@@ -109,8 +109,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
(fmt("Unknown info hash %s",
util::toHex(infoHash).c_str()));
}
- const std::shared_ptr<BtObject>& btObject =
- getDownloadEngine()->getBtRegistry()->get
+ auto btObject = getDownloadEngine()->getBtRegistry()->get
(downloadContext->getOwnerRequestGroup()->getGID());
const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index aa548611..aef696ec 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -350,16 +350,14 @@ void RequestGroup::createInitialCommand
btAnnouncePtr->shuffleAnnounce();
assert(!btRegistry->get(gid_->getNumericId()));
- btRegistry->put
- (gid_->getNumericId(), std::shared_ptr<BtObject>
- (new BtObject
- (downloadContext_,
- pieceStorage_,
- peerStorage,
- btAnnounce,
- btRuntime,
- (progressInfoFile ?
- progressInfoFile : progressInfoFile_))));
+ btRegistry->put(gid_->getNumericId(), make_unique<BtObject>
+ (downloadContext_,
+ pieceStorage_,
+ peerStorage,
+ btAnnounce,
+ btRuntime,
+ (progressInfoFile ?
+ progressInfoFile : progressInfoFile_)));
if(metadataGetMode) {
if(option_->getAsBool(PREF_ENABLE_DHT) ||
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index dd189563..53ddf1ea 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -731,7 +731,7 @@ namespace {
void gatherProgressBitTorrent
(const std::shared_ptr<Dict>& entryDict,
TorrentAttribute* torrentAttrs,
- const std::shared_ptr<BtObject>& btObject,
+ BtObject* btObject,
const std::vector<std::string>& keys)
{
if(requested_key(keys, KEY_INFO_HASH)) {
@@ -800,11 +800,11 @@ void gatherProgress
gatherProgressCommon(entryDict, group, keys);
#ifdef ENABLE_BITTORRENT
if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
- auto torrentAttrs =
- bittorrent::getTorrentAttrs(group->getDownloadContext());
- const std::shared_ptr<BtObject>& btObject =
- e->getBtRegistry()->get(group->getGID());
- gatherProgressBitTorrent(entryDict, torrentAttrs, btObject, keys);
+ gatherProgressBitTorrent(entryDict,
+ bittorrent::getTorrentAttrs
+ (group->getDownloadContext()),
+ e->getBtRegistry()->get(group->getGID()),
+ keys);
}
#endif // ENABLE_BITTORRENT
}
@@ -956,8 +956,7 @@ std::shared_ptr<ValueBase> GetPeersRpcMethod::process
GroupId::toHex(gid).c_str()));
}
std::shared_ptr<List> peers = List::g();
- const std::shared_ptr<BtObject>& btObject =
- e->getBtRegistry()->get(group->getGID());
+ auto btObject = e->getBtRegistry()->get(group->getGID());
if(btObject) {
assert(btObject->peerStorage);
gatherPeer(peers, btObject->peerStorage);
@@ -1506,8 +1505,7 @@ void changeOption
group->setMaxUploadSpeedLimit(grOption->getAsInt(PREF_MAX_UPLOAD_LIMIT));
}
#ifdef ENABLE_BITTORRENT
- const std::shared_ptr<BtObject>& btObject =
- e->getBtRegistry()->get(group->getGID());
+ auto btObject = e->getBtRegistry()->get(group->getGID());
if(btObject) {
if(option.defined(PREF_BT_MAX_PEERS)) {
btObject->btRuntime->setMaxPeers(grOption->getAsInt(PREF_BT_MAX_PEERS));