From 46d9f2de6373007895e84f577aa8ae413cd4e861 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 25 Nov 2009 15:49:20 +0000 Subject: [PATCH] 2009-11-26 Tatsuhiro Tsujikawa 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 --- ChangeLog | 20 +++++++++++++ src/BtRegistry.cc | 33 ++++++++++++++++------ src/BtRegistry.h | 14 ++++++---- src/BtSetup.cc | 3 +- src/ConsoleStatCalc.cc | 4 +-- src/InitiatorMSEHandshakeCommand.cc | 3 +- src/PeerInitiateConnectionCommand.cc | 3 +- src/PeerInteractionCommand.cc | 12 ++------ src/PeerInteractionCommand.h | 3 +- src/PeerReceiveHandshakeCommand.cc | 23 +++++++++------ src/RequestGroup.cc | 19 ++----------- src/XmlRpcMethodImpl.cc | 31 ++++++++++---------- test/BtRegistryTest.cc | 42 +++++++++++++++++++++------- test/XmlRpcMethodTest.cc | 11 +++++++- 14 files changed, 133 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48364bae..141c4b95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2009-11-26 Tatsuhiro Tsujikawa + + 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 + 2009-11-25 Tatsuhiro Tsujikawa Updated man page for changeOption XML-RPC method. 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 +BtRegistry::getDownloadContext(int32_t gid) const +{ + return get(gid)._downloadContext; +} + SharedHandle BtRegistry::getDownloadContext(const std::string& infoHash) const { - return get(infoHash)._downloadContext; + SharedHandle dctx; + for(std::map::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::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::const_iterator i = _pool.find(infoHash); + std::map::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() { diff --git a/src/BtRegistry.h b/src/BtRegistry.h index 3b3858f8..3fc642ee 100644 --- a/src/BtRegistry.h +++ b/src/BtRegistry.h @@ -37,7 +37,6 @@ #include "common.h" -#include #include #include "SharedHandle.h" @@ -87,19 +86,22 @@ struct BtObject { class BtRegistry { private: - std::map _pool; + std::map _pool; public: + SharedHandle + getDownloadContext(int32_t gid) const; + SharedHandle getDownloadContext(const std::string& infoHash) const; - void put(const std::string& infoHash, const BtObject& obj); + void put(int32_t gid, const BtObject& obj); - BtObject get(const std::string& infoHash) const; + BtObject get(int32_t gid) const; template OutputIterator getAllDownloadContext(OutputIterator dest) { - for(std::map::const_iterator i = _pool.begin(); + for(std::map::const_iterator i = _pool.begin(); i != _pool.end(); ++i) { *dest++ = (*i).second._downloadContext; } @@ -108,7 +110,7 @@ public: void removeAll(); - bool remove(const std::string& infoHash); + bool remove(int32_t gid); }; } // namespace aria2 diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 2bd12719..1ebb7476 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -76,8 +76,7 @@ void BtSetup::setup(std::deque& commands, const BDE& torrentAttrs = requestGroup->getDownloadContext()->getAttribute(bittorrent::BITTORRENT); bool metadataGetMode = !torrentAttrs.containsKey(bittorrent::METADATA); - BtObject btObject = - e->getBtRegistry()->get(torrentAttrs[bittorrent::INFO_HASH].s()); + BtObject btObject = e->getBtRegistry()->get(requestGroup->getGID()); SharedHandle pieceStorage = btObject._pieceStorage; SharedHandle peerStorage = btObject._peerStorage; SharedHandle btRuntime = btObject._btRuntime; diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index 25449ce5..10dc5140 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -116,10 +116,8 @@ static void printProgress << rg->getNumConnection(); #ifdef ENABLE_BITTORRENT if(rg->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) { - const BDE& torrentAttrs = - rg->getDownloadContext()->getAttribute(bittorrent::BITTORRENT); SharedHandle ps = - e->getBtRegistry()->get(torrentAttrs[bittorrent::INFO_HASH].s())._peerStorage; + e->getBtRegistry()->get(rg->getGID())._peerStorage; std::deque > peers; ps->getActivePeers(peers); o << " " << "SEED:" diff --git a/src/InitiatorMSEHandshakeCommand.cc b/src/InitiatorMSEHandshakeCommand.cc index 7afeab6e..87717751 100644 --- a/src/InitiatorMSEHandshakeCommand.cc +++ b/src/InitiatorMSEHandshakeCommand.cc @@ -152,11 +152,10 @@ bool InitiatorMSEHandshakeCommand::executeInternal() { } PeerInteractionCommand* c = new PeerInteractionCommand - (cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, + (cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, _peerStorage, socket, PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE, peerConnection); - c->setPeerStorage(_peerStorage); e->commands.push_back(c); return true; } diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index bd16a354..a05cc4e0 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/src/PeerInitiateConnectionCommand.cc @@ -89,9 +89,8 @@ bool PeerInitiateConnectionCommand::executeInternal() { } else { PeerInteractionCommand* command = new PeerInteractionCommand - (cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, + (cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, _peerStorage, socket, PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE); - command->setPeerStorage(_peerStorage); e->commands.push_back(command); } return true; diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 5cbf025f..5255fe0e 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -45,7 +45,6 @@ #include "Socket.h" #include "Option.h" #include "DownloadContext.h" -#include "BtRegistry.h" #include "Peer.h" #include "BtMessage.h" #include "BtRuntime.h" @@ -83,6 +82,7 @@ PeerInteractionCommand::PeerInteractionCommand DownloadEngine* e, const SharedHandle& btRuntime, const SharedHandle& pieceStorage, + const SharedHandle& peerStorage, const SocketHandle& s, Seq sequence, const PeerConnectionHandle& passedPeerConnection) @@ -90,6 +90,7 @@ PeerInteractionCommand::PeerInteractionCommand _requestGroup(requestGroup), _btRuntime(btRuntime), _pieceStorage(pieceStorage), + _peerStorage(peerStorage), sequence(sequence) { // TODO move following bunch of processing to separate method, like init() @@ -101,9 +102,6 @@ PeerInteractionCommand::PeerInteractionCommand const BDE& torrentAttrs = _requestGroup->getDownloadContext()->getAttribute(bittorrent::BITTORRENT); - SharedHandle btRegistry = e->getBtRegistry(); - SharedHandle peerStorage = - btRegistry->get(torrentAttrs[bittorrent::INFO_HASH].s())._peerStorage; bool metadataGetMode = !torrentAttrs.containsKey(bittorrent::METADATA); @@ -354,12 +352,6 @@ bool PeerInteractionCommand::exitBeforeExecute() return _btRuntime->isHalt(); } -void PeerInteractionCommand::setPeerStorage -(const SharedHandle& peerStorage) -{ - _peerStorage = peerStorage; -} - const SharedHandle