libktorrent  2.2.0
trackermanager.h
1 /***************************************************************************
2  * Copyright (C) 2009 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef BT_TRACKERMANAGER_H
22 #define BT_TRACKERMANAGER_H
23 
24 #include <QTimer>
25 #include <QDateTime>
26 #include <ktorrent_export.h>
27 #include <util/ptrmap.h>
28 #include <util/constants.h>
29 #include <tracker/tracker.h>
30 #include <interfaces/trackerslist.h>
31 
32 
33 namespace bt
34 {
35  class TorrentControl;
36  class WaitJob;
37  class PeerManager;
38 
42  class KTORRENT_EXPORT TrackerManager : public QObject,public bt::TrackersList,public TrackerDataSource
43  {
44  Q_OBJECT
45  public:
46  TrackerManager(TorrentControl* tor,PeerManager* pman);
47  ~TrackerManager() override;
48 
49  TrackerInterface* getCurrentTracker() const override;
50  void setCurrentTracker(TrackerInterface* t) override;
51  void setCurrentTracker(const QUrl &url) override;
52  QList<TrackerInterface*> getTrackers() override;
53  TrackerInterface* addTracker(const QUrl &url, bool custom = true,int tier = 1) override;
54  bool removeTracker(TrackerInterface* t) override;
55  bool removeTracker(const QUrl &url) override;
56  bool canRemoveTracker(TrackerInterface* t) override;
57  void restoreDefault() override;
58  void setTrackerEnabled(const QUrl &url,bool on) override;
59  bool noTrackersReachable() const override;
60  TrackersStatusInfo getTrackersStatusInfo() const override;
61 
63  Uint32 getNumSeeders() const;
64 
66  Uint32 getNumLeechers() const;
67 
71  virtual void start();
72 
77  virtual void stop(WaitJob* wjob = 0);
78 
82  virtual void completed();
83 
87  virtual void manualUpdate();
88 
92  virtual void scrape();
93 
94  protected:
95  void saveCustomURLs();
96  void loadCustomURLs();
97  void saveTrackerStatus();
98  void loadTrackerStatus();
99  void addTracker(Tracker* trk);
100  void switchTracker(Tracker* trk);
101  Tracker* selectTracker();
102 
103  Uint64 bytesDownloaded() const override;
104  Uint64 bytesUploaded() const override;
105  Uint64 bytesLeft() const override;
106  const SHA1Hash & infoHash() const override;
107  bool isPartialSeed() const override;
108 
109  private Q_SLOTS:
114  void onTrackerError(const QString & err);
115 
120  void onTrackerOK();
121 
125  void updateCurrentManually();
126 
127  protected:
128  TorrentControl* tor;
129  PtrMap<QUrl,Tracker> trackers;
130  bool no_save_custom_trackers;
131  PeerManager* pman;
132  Tracker* curr;
133  QList<QUrl> custom_trackers;
134  bool started;
135  };
136 
137 }
138 
139 #endif // BT_TRACKERMANAGER_H
bt::PtrMap
Map of pointers.
Definition: ptrmap.h:56
bt::WaitJob
Definition: waitjob.h:57
bt::PeerManager
Manages all the Peers.
Definition: peermanager.h:67
bt::TrackersList
Definition: trackerslist.h:62
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::Tracker
Definition: tracker.h:55
bt::TrackersStatusInfo
Definition: trackerslist.h:49
bt::TorrentControl
Controls just about everything.
Definition: torrentcontrol.h:69