2009-11-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added --bt-max-peers option to changeOption XML-RPC method.
	* src/XmlRpcMethod.cc
	* src/XmlRpcMethodImpl.cc
	* test/XmlRpcMethodTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2009-11-27 13:07:08 +00:00
parent 58f4e715e0
commit a8d4fbad51
4 changed files with 42 additions and 7 deletions

View file

@ -1,3 +1,10 @@
2009-11-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --bt-max-peers option to changeOption XML-RPC method.
* src/XmlRpcMethod.cc
* src/XmlRpcMethodImpl.cc
* test/XmlRpcMethodTest.cc
2009-11-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-11-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added test case for PREF_BT_REQUEST_PEER_SPEED_LIMIT Added test case for PREF_BT_REQUEST_PEER_SPEED_LIMIT

View file

@ -140,6 +140,7 @@ static void applyOption(InputIterator optNameFirst,
const std::set<std::string>& listChangeableOptions() const std::set<std::string>& listChangeableOptions()
{ {
static const std::string OPTIONS[] = { static const std::string OPTIONS[] = {
PREF_BT_MAX_PEERS,
PREF_BT_REQUEST_PEER_SPEED_LIMIT, PREF_BT_REQUEST_PEER_SPEED_LIMIT,
PREF_MAX_DOWNLOAD_LIMIT, PREF_MAX_DOWNLOAD_LIMIT,
PREF_MAX_UPLOAD_LIMIT PREF_MAX_UPLOAD_LIMIT

View file

@ -600,6 +600,14 @@ BDE ChangeOptionXmlRpcMethod::process
if(option->defined(PREF_MAX_UPLOAD_LIMIT)) { if(option->defined(PREF_MAX_UPLOAD_LIMIT)) {
group->setMaxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)); group->setMaxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
} }
#ifdef ENABLE_BITTORRENT
BtObject btObject = e->getBtRegistry()->get(group->getGID());
if(!btObject.isNull()) {
if(option->defined(PREF_BT_MAX_PEERS)) {
btObject._btRuntime->setMaxPeers(option->getAsInt(PREF_BT_MAX_PEERS));
}
}
#endif // ENABLE_BITTORRENT
} }
return BDE_OK; return BDE_OK;
} }

View file

@ -18,6 +18,14 @@
#include "TestUtil.h" #include "TestUtil.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "FeatureConfig.h" #include "FeatureConfig.h"
#ifdef ENABLE_BITTORRENT
# include "BtRegistry.h"
# include "BtRuntime.h"
# include "PieceStorage.h"
# include "PeerStorage.h"
# include "BtProgressInfoFile.h"
# include "BtAnnounce.h"
#endif // ENABLE_BITTORRENT
namespace aria2 { namespace aria2 {
@ -365,24 +373,35 @@ void XmlRpcMethodTest::testChangeOption()
BDE opt = BDE::dict(); BDE opt = BDE::dict();
opt[PREF_MAX_DOWNLOAD_LIMIT] = BDE("100K"); opt[PREF_MAX_DOWNLOAD_LIMIT] = BDE("100K");
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
opt[PREF_BT_MAX_PEERS] = BDE("100");
opt[PREF_BT_REQUEST_PEER_SPEED_LIMIT] = BDE("300K"); opt[PREF_BT_REQUEST_PEER_SPEED_LIMIT] = BDE("300K");
opt[PREF_MAX_UPLOAD_LIMIT] = BDE("50K"); opt[PREF_MAX_UPLOAD_LIMIT] = BDE("50K");
BtObject btObject;
btObject._btRuntime = SharedHandle<BtRuntime>(new BtRuntime());
_e->getBtRegistry()->put(group->getGID(), btObject);
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
req._params << opt; req._params << opt;
XmlRpcResponse res = m.execute(req, _e.get()); XmlRpcResponse res = m.execute(req, _e.get());
SharedHandle<Option> option = group->getOption();
CPPUNIT_ASSERT_EQUAL(0, res._code); CPPUNIT_ASSERT_EQUAL(0, res._code);
CPPUNIT_ASSERT_EQUAL((unsigned int)100*1024, CPPUNIT_ASSERT_EQUAL((unsigned int)100*1024,
group->getMaxDownloadSpeedLimit()); group->getMaxDownloadSpeedLimit());
CPPUNIT_ASSERT_EQUAL(std::string("102400"), CPPUNIT_ASSERT_EQUAL(std::string("102400"),
group->getOption()->get(PREF_MAX_DOWNLOAD_LIMIT)); option->get(PREF_MAX_DOWNLOAD_LIMIT));
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL(std::string("307200"),
(std::string("307200"), option->get(PREF_BT_REQUEST_PEER_SPEED_LIMIT));
group->getOption()->get(PREF_BT_REQUEST_PEER_SPEED_LIMIT));
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit()); CPPUNIT_ASSERT_EQUAL(std::string("100"), option->get(PREF_BT_MAX_PEERS));
CPPUNIT_ASSERT_EQUAL(std::string("51200"), CPPUNIT_ASSERT_EQUAL((unsigned int)100, btObject._btRuntime->getMaxPeers());
group->getOption()->get(PREF_MAX_UPLOAD_LIMIT));
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024,
group->getMaxUploadSpeedLimit());
CPPUNIT_ASSERT_EQUAL(std::string("51200"),
option->get(PREF_MAX_UPLOAD_LIMIT));
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
} }