diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index a181bc80..360a06a2 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -50,13 +50,14 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const BtContextHandle& btContext, - int32_t interval) + int32_t interval, + int32_t thresholdSpeed) :Command(cuid), BtContextAwareCommand(btContext), RequestGroupAware(requestGroup), interval(interval), e(e), - _lowestSpeedLimit(50*1024), + _thresholdSpeed(thresholdSpeed), _numNewConnection(5) {} @@ -70,7 +71,7 @@ bool ActivePeerConnectionCommand::execute() { checkPoint.reset(); TransferStat tstat = peerStorage->calculateStat(); size_t numAdd = btRuntime->lessThanEqMinPeer() ? MIN_PEERS-btRuntime->getConnections():_numNewConnection; - if(tstat.getDownloadSpeed() < _lowestSpeedLimit || btRuntime->lessThanEqMinPeer()) { + if(tstat.getDownloadSpeed() < _thresholdSpeed || btRuntime->lessThanEqMinPeer()) { for(; numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) { PeerHandle peer = peerStorage->getUnusedPeer(); connectToPeer(peer); diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h index ac8d7503..b8acff85 100644 --- a/src/ActivePeerConnectionCommand.h +++ b/src/ActivePeerConnectionCommand.h @@ -53,14 +53,15 @@ private: int32_t interval; // UNIT: sec DownloadEngine* e; Time checkPoint; - int32_t _lowestSpeedLimit; // UNIT: byte/sec + int32_t _thresholdSpeed; // UNIT: byte/sec int32_t _numNewConnection; // the number of the connection to establish. public: ActivePeerConnectionCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const SharedHandle& btContext, - int32_t interval); + int32_t interval, + int32_t thresholdSpeed); virtual ~ActivePeerConnectionCommand(); @@ -68,9 +69,9 @@ public: void connectToPeer(const SharedHandle& peer); - void setLowestSpeedLimit(int32_t speed) + void setThresholdSpeed(int32_t speed) { - _lowestSpeedLimit = speed; + _thresholdSpeed = speed; } void setNumNewConnection(int32_t numNewConnection) diff --git a/src/BtSetup.cc b/src/BtSetup.cc index d6e3943d..089960cc 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -80,11 +80,16 @@ Commands BtSetup::setup(RequestGroup* requestGroup, e, btContext, 10)); - commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(), - 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)); + } if(!btContext->isPrivate() && DHTSetup::initialized()) { DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext); DHTGetPeersCommand* command = new DHTGetPeersCommand(CUIDCounterSingletonHolder::instance()->newID(),