~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to libbtcore/torrent/torrentcontrol.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-08 19:17:41 UTC
  • mfrom: (1.2.1 upstream) (0.7.12 sid)
  • Revision ID: james.westby@ubuntu.com-20091208191741-lqlq0xvnlv8ki19u
Tags: 3.3.1+dfsg.1-1ubuntu1
* Merge with Debian Testing remaining changes:
  - Build-depend directly on libboost-serialization1.40-dev since
    libboost-serialization-dev from boost-defaults is not in Main
  - Add in rules: include /usr/lib/kubuntu-desktop-i18n/debhelper/kubuntu.mk
  - Don't use dpkg-source 3.0 format
  - Add quilt to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        class Peer;
49
49
        class BitSet;
50
50
        class QueueManagerInterface;
51
 
        class PreallocationThread;
52
51
        class TimeEstimator;
53
 
        class DataCheckerThread;
54
52
        class WaitJob;
55
53
        class MonitorInterface;
56
54
        class ChunkSelectorFactoryInterface;
57
55
        class CacheFactory;
 
56
        class JobQueue;
58
57
        
59
58
        /**
60
59
         * @author Joris Guisson
98
97
                 * @param tmpdir The directory to store temporary data
99
98
                 * @param datadir The directory to store the actual file(s)
100
99
                 *              (only used the first time we load a torrent)
101
 
                 * @param default_save_dir Default save directory (null if not set)
102
100
                 * @throw Error when something goes wrong
103
101
                 */
104
102
                void init(QueueManagerInterface* qman,
105
103
                                const QString & torrent,
106
104
                                const QString & tmpdir,
107
 
                                const QString & datadir,
108
 
                                const QString & default_save_dir);
 
105
                                const QString & datadir);
109
106
                
110
107
                /**
111
108
                 * Initialize the TorrentControl. 
114
111
                 * @param tmpdir The directory to store temporary data
115
112
                 * @param datadir The directory to store the actual file(s)
116
113
                 *              (only used the first time we load a torrent)
117
 
                 * @param default_save_dir Default save directory (null if not set)
118
114
                 * @throw Error when something goes wrong
119
115
                 */
120
116
                void init(QueueManagerInterface* qman,
121
117
                                  const QByteArray & data,
122
118
                                  const QString & tmpdir,
123
 
                                  const QString & datadir,
124
 
                                  const QString & default_save_dir);
 
119
                                  const QString & datadir);
125
120
 
126
121
                /**
127
122
                 * Change to a new data dir. If this fails
178
173
                 * @return Uint32 - time in seconds
179
174
                 */
180
175
                Uint32 getRunningTimeUL() const;
181
 
 
182
 
                /// Get the time to the next tracker update in seconds.
183
 
                Uint32 getTimeToNextTrackerUpdate() const;
184
 
 
185
 
                /// Get a short error message
186
 
                QString getShortErrorMessage() const {return error_msg;}
187
176
                
188
177
                virtual Uint32 getNumFiles() const;
189
178
                virtual TorrentFileInterface & getTorrentFile(Uint32 index);
197
186
                virtual void changeTextCodec(QTextCodec* tc);
198
187
                virtual Uint32 getNumWebSeeds() const;
199
188
                virtual const WebSeedInterface* getWebSeed(Uint32 i) const;
 
189
                virtual WebSeedInterface* getWebSeed(Uint32 i);
200
190
                virtual bool addWebSeed(const KUrl & url);
201
191
                virtual bool removeWebSeed(const KUrl & url);
202
192
                virtual bool readyForPreview() const;
204
194
                virtual void markExistingFilesAsDownloaded();
205
195
                virtual int getPriority() const { return istats.priority; }
206
196
                virtual void setPriority(int p);
207
 
                virtual bool isUserControlled() const {return stats.user_controlled;}
208
 
                virtual void setUserControlled(bool uc);
209
197
                virtual bool overMaxRatio();            
210
198
                virtual void setMaxShareRatio(float ratio);
211
199
                virtual float getMaxShareRatio() const { return stats.max_share_ratio; }
212
200
                virtual bool overMaxSeedTime();
213
201
                virtual void setMaxSeedTime(float hours);
214
202
                virtual float getMaxSeedTime() const {return stats.max_seed_time;}
 
203
                virtual void setAllowedToStart(bool on);
 
204
                virtual void setQueued(bool queued);
215
205
        
216
206
                /// Tell the TorrentControl obj to preallocate diskspace in the next update
217
207
                void setPreallocateDiskSpace(bool pa) {prealloc = pa;}
218
208
                
219
 
                /// Make a string out of the status message
220
 
                virtual QString statusToString() const;
221
 
                
222
209
                /// Checks if tracker announce is allowed (minimum interval 60 seconds)
223
210
                bool announceAllowed();
224
211
                
238
225
                virtual const DHTNode & getDHTNode(Uint32 i) const;
239
226
                virtual void deleteDataFiles();
240
227
                virtual const bt::PeerID & getOwnPeerID() const;
241
 
                virtual bool updateNeeded() const;
242
 
                
243
 
                /**
244
 
                 * Called by the PeerSourceManager when it is going to start a new tracker.
245
 
                 */
246
 
                void resetTrackerStats();
 
228
                virtual QString getComments() const;
 
229
                virtual const JobQueue* getJobQueue() const {return job_queue;}
247
230
                
248
231
                /**
249
232
                 * Returns estimated time left for finishing download. Returned value is in seconds.
272
255
        
273
256
                /// Get the PeerManager
274
257
                const PeerManager * getPeerMgr() const;
275
 
 
276
 
                /// Are we in the process of moving files
277
 
                bool isMovingFiles() const {return moving_files;}
278
258
                
279
259
                /// Set a custom chunk selector factory (needs to be done for init is called)
280
260
                void setChunkSelectorFactory(ChunkSelectorFactoryInterface* csfi);
295
275
                
296
276
                /**
297
277
                 * Stop the download, closes all connections.
298
 
                 * @param user whether or not the user did this explicitly
299
278
                 * @param wjob WaitJob to wait at exit for the completion of stopped requests
300
279
                 */
301
 
                void stop(bool user,WaitJob* wjob = 0);
 
280
                void stop(WaitJob* wjob = 0);
302
281
                        
303
282
                /**
304
283
                 * Update the tracker, this should normally handled internally.
312
291
                void scrapeTracker();
313
292
 
314
293
                /**
315
 
                 * The tracker status has changed.
316
 
                 * @param s The tracker status
317
 
                 * @param ns New status
318
 
                 */
319
 
                void trackerStatusChanged(TrackerStatus s,const QString & ns);
320
 
 
321
 
                /**
322
294
                 * A scrape has finished on the tracker.
323
295
                 * */
324
296
                void trackerScrapeDone();
353
325
                 */
354
326
                static void setNumCorruptedForRecheck(Uint32 m) {num_corrupted_for_recheck = m;}
355
327
                
 
328
        protected:
 
329
                /// Called when a data check is finished by DataCheckerJob
 
330
                void afterDataCheck(DataCheckerListener* lst,const BitSet & result,const QString & error);
 
331
                void beforeDataCheck();
 
332
                void preallocFinished(const QString & error,bool completed);
 
333
                void allJobsDone();
 
334
                
356
335
        private slots:
357
336
                void onNewPeer(Peer* p);
358
337
                void onPeerRemoved(Peer* p);
359
338
                void doChoking();
360
339
                void onIOError(const QString & msg);
361
 
                void onPortPacket(const QString & ip,Uint16 port);
362
340
                /// Update the stats of the torrent.
363
341
                void updateStats();
364
342
                void corrupted(Uint32 chunk);
365
343
                void moveDataFilesFinished(KJob* j);
 
344
                void moveDataFilesWithMapFinished(KJob* j);
366
345
                void downloaded(Uint32 chunk);
367
 
                void afterDataCheck();
368
 
                void preallocThreadDone();
369
346
                void moveToCompletedDir();
370
347
                
371
348
        private:        
377
354
                void loadEncoding();
378
355
                void getSeederInfo(Uint32 & total,Uint32 & connected_to) const;
379
356
                void getLeecherInfo(Uint32 & total,Uint32 & connected_to) const;
380
 
                void migrateTorrent(const QString & default_save_dir);
381
357
                void continueStart();
382
358
                virtual void handleError(const QString & err);
383
 
 
384
 
                void initInternal(QueueManagerInterface* qman,const QString & tmpdir,
385
 
                                                  const QString & ddir,const QString & default_save_dir,bool first_time);
386
 
                
 
359
                void initInternal(QueueManagerInterface* qman,const QString & tmpdir,const QString & ddir);
387
360
                void checkExisting(QueueManagerInterface* qman);
388
361
                void setupDirs(const QString & tmpdir,const QString & ddir);
389
362
                void setupStats();
390
363
                void setupData();
391
 
                virtual bool isCheckingData(bool & finished) const;
392
 
                
393
364
                void setUploadProps(Uint32 limit,Uint32 rate);
394
365
                void setDownloadProps(Uint32 limit,Uint32 rate);
395
366
                
 
367
                
396
368
        signals:
397
369
                void dataCheckFinished();
398
370
                
399
371
        private:
 
372
                JobQueue* job_queue;
400
373
                Torrent* tor;
401
374
                PeerSourceManager* psman;
402
375
                ChunkManager* cman;
408
381
                MonitorInterface* tmon;
409
382
                ChunkSelectorFactoryInterface* custom_selector_factory;
410
383
                CacheFactory* cache_factory;
411
 
                
412
384
                QString move_data_files_destination_path;
413
 
                bool restart_torrent_after_move_data_files;
414
 
                
415
385
                Timer choker_update_timer;
416
386
                Timer stats_save_timer;
417
387
                Timer stalled_timer;
418
388
                Timer wanted_update_timer;
419
 
                
420
389
                QString tordir;
421
390
                QString old_tordir;
422
391
                QString outputdir;
423
392
                QString error_msg;
424
 
                
425
393
                bool prealloc;
426
 
                PreallocationThread* prealloc_thread;
427
 
                DataCheckerThread* dcheck_thread;
428
394
                TimeStamp last_diskspace_check;
429
 
                bool moving_files;
430
395
                
431
396
                struct InternalStats
432
397
                {
436
401
                        Uint32 running_time_ul;
437
402
                        Uint64 prev_bytes_dl;
438
403
                        Uint64 prev_bytes_ul;
439
 
                        Uint64 trk_prev_bytes_dl;
440
 
                        Uint64 trk_prev_bytes_ul;
441
404
                        Uint64 session_bytes_uploaded;
442
405
                        bool io_error;
443
406
                        bool custom_output_name;
444
407
                        Uint16 port;
445
408
                        int priority;
446
409
                        bool dht_on;
447
 
                        TimeStamp last_announce;
448
410
                        bool diskspace_warning_emitted;
449
411
                };
450
412
                
463
425
                static Uint32 min_diskspace;
464
426
                static bool auto_recheck;
465
427
                static Uint32 num_corrupted_for_recheck;
 
428
                
 
429
                friend class DataCheckerJob;
 
430
                friend class PreallocationJob;
 
431
                friend class JobQueue;
466
432
        };
467
433
        
468
434