From 3c41ea24bf2f4fc53c26f226db7c31a5e9b44fef Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 18 Feb 2008 17:11:44 +0000 Subject: [PATCH] 2008-02-19 Tatsuhiro Tsujikawa Determin _threadtholdSpeed in each constructor for ActivePeerConnectionCommand and PeerReceiveHandshakeCommand. * src/ActivePeerConnectionCommand.{h, cc} * src/PeerReceiveHandshakeCommand.{h, cc} * src/BtSetup.cc * src/BtConstants.h --- ChangeLog | 9 +++++++++ src/ActivePeerConnectionCommand.cc | 15 +++++++++++---- src/ActivePeerConnectionCommand.h | 3 +-- src/BtConstants.h | 2 ++ src/BtSetup.cc | 14 ++++---------- src/PeerReceiveHandshakeCommand.cc | 11 +++++++++-- src/PeerReceiveHandshakeCommand.h | 2 +- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e54184a..5391c84c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-02-19 Tatsuhiro Tsujikawa + + Determin _threadtholdSpeed in each constructor for + ActivePeerConnectionCommand and PeerReceiveHandshakeCommand. + * src/ActivePeerConnectionCommand.{h, cc} + * src/PeerReceiveHandshakeCommand.{h, cc} + * src/BtSetup.cc + * src/BtConstants.h + 2008-02-18 Tatsuhiro Tsujikawa Added --bt-min-crypto-level and --bt-require-crypto options. diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index cae26834..f6049ba3 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -43,6 +43,9 @@ #include "BtRuntime.h" #include "Peer.h" #include "Logger.h" +#include "prefs.h" +#include "Option.h" +#include "BtConstants.h" namespace aria2 { @@ -50,16 +53,20 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const BtContextHandle& btContext, - int32_t interval, - int32_t thresholdSpeed) + int32_t interval) :Command(cuid), BtContextAwareCommand(btContext), RequestGroupAware(requestGroup), interval(interval), e(e), - _thresholdSpeed(thresholdSpeed), + _thresholdSpeed(SLOW_SPEED_THRESHOLD), _numNewConnection(5) -{} +{ + int32_t maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); + if(maxDownloadSpeed > 0) { + _thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed); + } +} ActivePeerConnectionCommand::~ActivePeerConnectionCommand() {} diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h index b8acff85..7d78c3f2 100644 --- a/src/ActivePeerConnectionCommand.h +++ b/src/ActivePeerConnectionCommand.h @@ -60,8 +60,7 @@ public: RequestGroup* requestGroup, DownloadEngine* e, const SharedHandle& btContext, - int32_t interval, - int32_t thresholdSpeed); + int32_t interval); virtual ~ActivePeerConnectionCommand(); diff --git a/src/BtConstants.h b/src/BtConstants.h index b3995bca..57c45d28 100644 --- a/src/BtConstants.h +++ b/src/BtConstants.h @@ -50,4 +50,6 @@ typedef std::map Extensions; #define DEFAULT_LATENCY 1500 +#define SLOW_SPEED_THRESHOLD (50*1024) + #endif // _D_BT_CONSTANTS_ diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 089960cc..c1eea18c 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -80,16 +80,10 @@ Commands BtSetup::setup(RequestGroup* requestGroup, e, btContext, 10)); - { - int32_t thresholdSpeed = 50*1024; - int32_t maxDownloadSpeed = option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); - if(maxDownloadSpeed > 0) { - thresholdSpeed = std::min(maxDownloadSpeed, thresholdSpeed); - } - commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(), - requestGroup, e, btContext, 10, - thresholdSpeed)); - } + + commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(), + requestGroup, e, btContext, 10)); + if(!btContext->isPrivate() && DHTSetup::initialized()) { DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext); DHTGetPeersCommand* command = new DHTGetPeersCommand(CUIDCounterSingletonHolder::instance()->newID(), diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc index 34b261de..598f1c92 100644 --- a/src/PeerReceiveHandshakeCommand.cc +++ b/src/PeerReceiveHandshakeCommand.cc @@ -49,6 +49,8 @@ #include "message.h" #include "Socket.h" #include "Logger.h" +#include "prefs.h" +#include "Option.h" namespace aria2 { @@ -59,11 +61,15 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand(int32_t cuid, const SharedHandle& peerConnection): PeerAbstractCommand(cuid, peer, e, s), _peerConnection(peerConnection), - _lowestSpeedLimit(20*1024) + _thresholdSpeed(SLOW_SPEED_THRESHOLD) { if(_peerConnection.isNull()) { _peerConnection = new PeerConnection(cuid, socket, e->option); } + int32_t maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); + if(maxDownloadSpeed > 0) { + _thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed); + } } PeerReceiveHandshakeCommand::~PeerReceiveHandshakeCommand() {} @@ -89,7 +95,8 @@ bool PeerReceiveHandshakeCommand::executeInternal() throw new DlAbortEx("Unknown info hash %s", infoHash.c_str()); } TransferStat tstat = PEER_STORAGE(btContext)->calculateStat(); - if(!PIECE_STORAGE(btContext)->downloadFinished() && tstat.getDownloadSpeed() < _lowestSpeedLimit || + if((!PIECE_STORAGE(btContext)->downloadFinished() && + tstat.getDownloadSpeed() < _thresholdSpeed) || BT_RUNTIME(btContext)->getConnections() < MAX_PEERS) { if(PEER_STORAGE(btContext)->addPeer(peer)) { diff --git a/src/PeerReceiveHandshakeCommand.h b/src/PeerReceiveHandshakeCommand.h index 2ab0ab80..87f5c46a 100644 --- a/src/PeerReceiveHandshakeCommand.h +++ b/src/PeerReceiveHandshakeCommand.h @@ -48,7 +48,7 @@ class PeerReceiveHandshakeCommand:public PeerAbstractCommand private: SharedHandle _peerConnection; - int32_t _lowestSpeedLimit; + int32_t _thresholdSpeed; protected: virtual bool executeInternal();