瀏覽代碼

2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Use PREF_MAX_DOWNLOAD_LIMIT as a threshold for
	ActivePeerConnectionCommand when it is given and
	PREF_MAX_DOWNLOAD_LIMIT < default threshold.
	* src/ActivePeerConnectionCommand.{h, cc}
	* src/BtSetup.cc
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
7fdbd0e104
共有 3 個文件被更改,包括 19 次插入12 次删除
  1. 4 3
      src/ActivePeerConnectionCommand.cc
  2. 5 4
      src/ActivePeerConnectionCommand.h
  3. 10 5
      src/BtSetup.cc

+ 4 - 3
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);

+ 5 - 4
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>& btContext,
-			      int32_t interval);
+			      int32_t interval,
+			      int32_t thresholdSpeed);
      
   virtual ~ActivePeerConnectionCommand();
 
@@ -68,9 +69,9 @@ public:
 
   void connectToPeer(const SharedHandle<Peer>& peer);
 
-  void setLowestSpeedLimit(int32_t speed)
+  void setThresholdSpeed(int32_t speed)
   {
-    _lowestSpeedLimit = speed;
+    _thresholdSpeed = speed;
   }
 
   void setNumNewConnection(int32_t numNewConnection)

+ 10 - 5
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(),