~ubuntu-branches/ubuntu/trusty/ktorrent/trusty

« back to all changes in this revision

Viewing changes to libbtcore/torrent/advancedchokealgorithm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-28 23:22:08 UTC
  • mfrom: (0.7.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100228232208-6g2xwvd02kfv6lxf
Tags: 3.3.4+dfsg.1-1ubuntu1
* Merge with Debian, remaining changes:
  - Used versioned boost build-depend
  - Include /usr/lib/kubuntu-desktop-i18n/debhelper/kubuntu.mk in
    debian/rules for translations support
  - Add kubuntu_01_fix_videowidget_include.diff to fix FTBS

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
                return true;
117
117
        }
118
118
        
119
 
        static int ACACmp(Peer* a,Peer* b)
 
119
        static bool ACAGreaterThan(Peer* a,Peer* b)
120
120
        {
121
 
                if (a->getStats().aca_score < b->getStats().aca_score)
122
 
                        return 1;
123
 
                else if (a->getStats().aca_score > b->getStats().aca_score)
124
 
                        return -1;
125
 
                else
126
 
                        return 0;
 
121
                return a->getStats().aca_score > b->getStats().aca_score;
127
122
        }
128
123
        
129
124
 
130
125
        void AdvancedChokeAlgorithm::doChokingLeechingState(PeerManager & pman,ChunkManager & cman,const TorrentStats & stats)
131
126
        {
132
 
                PeerPtrList ppl;
 
127
                QList<Peer*> ppl;
133
128
                Uint32 np = pman.getNumConnectedPeers();
134
129
                // add all non seeders
135
130
                for (Uint32 i = 0;i < np;i++)
146
141
                }
147
142
                
148
143
                // sort list by ACA score
149
 
                ppl.setCompareFunc(ACACmp); 
150
 
                qSort(ppl.begin(), ppl.end());
 
144
                qSort(ppl.begin(), ppl.end(),ACAGreaterThan);
151
145
                
152
146
                doUnchoking(ppl,updateOptimisticPeer(pman,ppl));
153
147
        }
154
148
        
155
 
        void AdvancedChokeAlgorithm::doUnchoking(PeerPtrList & ppl,Peer* poup)
 
149
        void AdvancedChokeAlgorithm::doUnchoking(QList<Peer*> & ppl,Peer* poup)
156
150
        {
157
151
                // Get the number of upload slots
158
152
                Uint32 num_slots = Choker::getNumUploadSlots();
179
173
                }
180
174
        }
181
175
        
182
 
        static int UpRateCmp(Peer* a,Peer* b)
 
176
        static bool UploadRateGreaterThan(Peer* a,Peer* b)
183
177
        {
184
 
                if (a->getStats().upload_rate < b->getStats().upload_rate)
185
 
                        return -1;
186
 
                else if (a->getStats().upload_rate > b->getStats().upload_rate)
187
 
                        return 1;
188
 
                else
189
 
                        return 0;
 
178
                return a->getStats().upload_rate > b->getStats().upload_rate;
190
179
        }
191
180
 
192
181
        void AdvancedChokeAlgorithm::doChokingSeedingState(PeerManager & pman,ChunkManager & cman,const TorrentStats & stats)
193
182
        {
194
 
                PeerPtrList ppl;
 
183
                QList<Peer*> ppl;
195
184
                Uint32 np = pman.getNumConnectedPeers();
196
185
                // add all non seeders
197
186
                for (Uint32 i = 0;i < np;i++)
207
196
                                        p->choke();  
208
197
                        }
209
198
                }
210
 
                
211
 
                ppl.setCompareFunc(UpRateCmp);
212
 
                qSort(ppl.begin(), ppl.end());
 
199
                qSort(ppl.begin(), ppl.end(),UploadRateGreaterThan);
213
200
                
214
201
                doUnchoking(ppl,updateOptimisticPeer(pman,ppl));
215
202
        }
216
203
        
217
 
        static Uint32 FindPlannedOptimisticUnchokedPeer(PeerManager& pman,const PeerPtrList & ppl)
 
204
        static Uint32 FindPlannedOptimisticUnchokedPeer(PeerManager& pman,const QList<Peer*> & ppl)
218
205
        {
219
206
                Uint32 num_peers = pman.getNumConnectedPeers();
220
207
                if (num_peers == 0)
235
222
                return UNDEFINED_ID;
236
223
        }
237
224
        
238
 
        Peer* AdvancedChokeAlgorithm::updateOptimisticPeer(PeerManager & pman,const PeerPtrList & ppl)
 
225
        Peer* AdvancedChokeAlgorithm::updateOptimisticPeer(PeerManager & pman,const QList<Peer*> & ppl)
239
226
        {
240
227
                // get the planned optimistic unchoked peer and change it if necessary
241
228
                Peer* poup = pman.findPeer(opt_unchoked_peer_id);