]> granicus.if.org Git - transmission/commitdiff
(trunk libT) better throttling back of outgoing download requests when speed limits...
authorCharles Kerr <charles@transmissionbt.com>
Tue, 18 Aug 2009 01:57:17 +0000 (01:57 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 18 Aug 2009 01:57:17 +0000 (01:57 +0000)
libtransmission/peer-msgs.c

index 5c4e81147400218f6fec153618c7af67b3855cc3..4b39265c50c1da2feb49a0eb5afa51627d9fef46 100644 (file)
@@ -1673,12 +1673,24 @@ canRead( tr_peerIo * io, void * vmsgs, size_t * piece )
 static int
 ratePulse( tr_peermsgs * msgs, uint64_t now )
 {
-    const double rateToClient = tr_peerGetPieceSpeed( msgs->peer, now, TR_PEER_TO_CLIENT );
-    const int seconds = 10;
+    int irate;
     const int floor = 8;
-    const int estimatedBlocksInPeriod = ( rateToClient * seconds * 1024 ) / msgs->torrent->blockSize;
-
-    msgs->maxActiveRequests = floor + estimatedBlocksInPeriod;
+    const int seconds = 10;
+    double rate;
+    int estimatedBlocksInPeriod;
+    const tr_torrent * const torrent = msgs->torrent;
+
+    /* Get the rate limit we should use.
+     * FIXME: this needs to consider all the other peers as well... */
+    rate = tr_peerGetPieceSpeed( msgs->peer, now, TR_PEER_TO_CLIENT );
+    if( tr_torrentUsesSpeedLimit( torrent, TR_PEER_TO_CLIENT ) )
+        rate = MIN( rate, tr_torrentGetSpeedLimit( torrent, TR_PEER_TO_CLIENT ) );
+    if( tr_torrentUsesSessionLimits( torrent ) )
+        if( tr_sessionGetActiveSpeedLimit( torrent->session, TR_PEER_TO_CLIENT, &irate ) )
+            rate = MIN( rate, irate );
+
+    estimatedBlocksInPeriod = ( rate * seconds * 1024 ) / torrent->blockSize;
+    msgs->maxActiveRequests = MAX( floor, estimatedBlocksInPeriod );
 
     if( msgs->reqq > 0 )
         msgs->maxActiveRequests = MIN( msgs->maxActiveRequests, msgs->reqq );