This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Upload slots incorrectly distributed in KTorrent 3.3.3

Tags: None
(comma "," separated)
nybble41
Registered Member
Posts
1
Karma
0
While poking around in the KTorrent UI I noticed that the upload slots did not appear to be distributed in accordance with the score associated with each peer. Upon further investigation I discovered that the peer list is not, in fact, sorted according to each peers' aca_score statistic, but instead appears to be randomly ordered at the time of the call to doUnchoking(). As a result, upload slots are being distributed at random rather than being allocated to the peers with the highest scores, which can only have a negative impact on the efficiency of the network, not to mention end-users' download rates.

The original code attempted sort the peer list by first calling ppl.setCompareFunc(ACACmp) and then qSort(ppl.begin(), ppl.end()). The problem with this is that the two-argument qSort() function uses the operator<() defined for the element-type of the list, in this case Peer*, and thus sorts the items rather uselessly by memory address rather than score.

The following patch against libbtcore/torrent/advancedchokealgorithm.cpp achieves the expected behavior:

Code: Select all
--- advancedchokealgorithm.cpp.orig   2010-01-24 21:50:53.599579271 -0600
+++ advancedchokealgorithm.cpp   2010-01-24 21:51:29.706242125 -0600
@@ -118,12 +118,7 @@
    
    static int ACACmp(Peer* a,Peer* b)
    {
-      if (a->getStats().aca_score < b->getStats().aca_score)
-         return 1;
-      else if (a->getStats().aca_score > b->getStats().aca_score)
-         return -1;
-      else
-         return 0;
+      return a->getStats().aca_score > b->getStats().aca_score;
    }
    
 
@@ -146,8 +141,7 @@
       }
       
       // sort list by ACA score
-      ppl.setCompareFunc(ACACmp);
-      qSort(ppl.begin(), ppl.end());
+      qSort(ppl.begin(), ppl.end(), ACACmp);
       
       doUnchoking(ppl,updateOptimisticPeer(pman,ppl));
    }
George
Moderator
Posts
5421
Karma
1
You are right, this seems to be a porting error when KT was ported from KDE3 to KDE4.

Will fix it.
goodtorrents
Registered Member
Posts
8
Karma
0
Thank you nybble41 for investigating the problem and for the patch. And thanks Georges for ktorrent itself :)

This bug is actually quite critical. Despite a very massive upload bandwidth, I cannot download much because I keep uploading to the wrong people. This bug deserves its own release (ktorrent 3.3.4?).

I am trying to compile from source, with the patch above applied, because I can't download much until I do, and can't wait for a kubuntu package with the above fix.
George
Moderator
Posts
5421
Karma
1
goodtorrents wrote:Thank you nybble41 for investigating the problem and for the patch. And thanks Georges for ktorrent itself :)

This bug is actually quite critical. Despite a very massive upload bandwidth, I cannot download much because I keep uploading to the wrong people. This bug deserves its own release (ktorrent 3.3.4?).

I am trying to compile from source, with the patch above applied, because I can't download much until I do, and can't wait for a kubuntu package with the above fix.


There is probably going to be a 3.3.4 in the weekend, I'm hoping to get that out together with 4.0beta2.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]