summaryrefslogtreecommitdiff
path: root/src/BtRegistry.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-11-25 15:49:20 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-11-25 15:49:20 +0000
commit46d9f2de6373007895e84f577aa8ae413cd4e861 (patch)
tree5ab170329d937cb4fea2f04c76675062b832d0f5 /src/BtRegistry.cc
parenta26a44cb8ed28d59930bfaa4553fbd1fa7fbcb4d (diff)
2009-11-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug which causes segmentation fault with tellWaiting XML-RPC method when BitTorrent download is waiting. The key of BtRegistry is changed from info hash to GID, because it is registered per RequestGroup, not info hash. * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/ConsoleStatCalc.cc * src/InitiatorMSEHandshakeCommand.cc * src/PeerInitiateConnectionCommand.cc * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/RequestGroup.cc * src/XmlRpcMethodImpl.cc * test/BtRegistryTest.cc * test/XmlRpcMethodTest.cc
Diffstat (limited to 'src/BtRegistry.cc')
-rw-r--r--src/BtRegistry.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/BtRegistry.cc b/src/BtRegistry.cc
index 158da62b..2a94cafe 100644
--- a/src/BtRegistry.cc
+++ b/src/BtRegistry.cc
@@ -40,25 +40,40 @@
#include "BtAnnounce.h"
#include "BtRuntime.h"
#include "BtProgressInfoFile.h"
+#include "bittorrent_helper.h"
namespace aria2 {
SharedHandle<DownloadContext>
+BtRegistry::getDownloadContext(int32_t gid) const
+{
+ return get(gid)._downloadContext;
+}
+
+SharedHandle<DownloadContext>
BtRegistry::getDownloadContext(const std::string& infoHash) const
{
- return get(infoHash)._downloadContext;
+ SharedHandle<DownloadContext> dctx;
+ for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin();
+ i != _pool.end(); ++i) {
+ const BDE& attrs =
+ (*i).second._downloadContext->getAttribute(bittorrent::BITTORRENT);
+ if(attrs[bittorrent::INFO_HASH].s() == infoHash) {
+ dctx = (*i).second._downloadContext;
+ break;
+ }
+ }
+ return dctx;
}
-void BtRegistry::put(const std::string& infoHash, const BtObject& obj)
+void BtRegistry::put(int32_t gid, const BtObject& obj)
{
- remove(infoHash);
- std::map<std::string, BtObject>::value_type p(infoHash, obj);
- _pool.insert(p);
+ _pool[gid] = obj;
}
-BtObject BtRegistry::get(const std::string& infoHash) const
+BtObject BtRegistry::get(int32_t gid) const
{
- std::map<std::string, BtObject>::const_iterator i = _pool.find(infoHash);
+ std::map<int32_t, BtObject>::const_iterator i = _pool.find(gid);
if(i == _pool.end()) {
return BtObject();
} else {
@@ -66,9 +81,9 @@ BtObject BtRegistry::get(const std::string& infoHash) const
}
}
-bool BtRegistry::remove(const std::string& infoHash)
+bool BtRegistry::remove(int32_t gid)
{
- return _pool.erase(infoHash);
+ return _pool.erase(gid);
}
void BtRegistry::removeAll() {