libktorrent  2.2.0
tracker.h
1 /***************************************************************************
2  * Copyright (C) 2005 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 #ifndef BTTRACKER_H
21 #define BTTRACKER_H
22 
23 #include <QUrl>
24 #include <util/sha1hash.h>
25 #include <interfaces/peersource.h>
26 #include <interfaces/trackerinterface.h>
27 #include <peer/peerid.h>
28 #include <ktorrent_export.h>
29 #include <QTimer>
30 
31 class QUrl;
32 
33 namespace bt
34 {
39  class KTORRENT_EXPORT TrackerDataSource
40  {
41  public:
42  virtual ~TrackerDataSource() {}
43 
44  virtual Uint64 bytesDownloaded() const = 0;
45  virtual Uint64 bytesUploaded() const = 0;
46  virtual Uint64 bytesLeft() const = 0;
47  virtual const SHA1Hash & infoHash() const = 0;
48  virtual bool isPartialSeed() const = 0;
49  };
50 
54  class KTORRENT_EXPORT Tracker : public PeerSource,public TrackerInterface
55  {
56  Q_OBJECT
57  public:
58  Tracker(const QUrl &url,TrackerDataSource* tds,const PeerID & id,int tier);
59  ~Tracker() override;
60 
65  static void setCustomIP(const QString & str);
66 
68  QUrl trackerURL() const {return url;}
69 
74  void timedDelete(int ms);
75 
80  virtual Uint32 failureCount() const = 0;
81 
86  virtual void scrape() = 0;
87 
89  int getTier() const {return tier;}
90 
92  static QString getCustomIP();
93 
95  void handleFailure();
96  protected:
99 
101  Uint64 bytesDownloaded() const;
102 
104  Uint64 bytesUploaded() const;
105 
107  void failed(const QString & err);
108 
109  public Q_SLOTS:
110  void manualUpdate() override = 0;
111 
112  Q_SIGNALS:
117  void requestFailed(const QString & failure_reason);
118 
122  void stopDone();
123 
127  void requestOK();
128 
133 
137  void scrapeDone();
138 
139  protected:
140  int tier;
141  PeerID peer_id;
142  TrackerDataSource* tds;
143  Uint32 key;
144  QTimer reannounce_timer;
145  Uint64 bytes_downloaded_at_start;
146  Uint64 bytes_uploaded_at_start;
147  };
148 
149 }
150 
151 #endif
bt::Tracker::requestPending
void requestPending()
bt::Tracker::getCustomIP
static QString getCustomIP()
Get the custom ip to use, null if none is set.
bt::Tracker::resetTrackerStats
void resetTrackerStats()
Reset the tracker stats.
bt::Tracker::scrape
virtual void scrape()=0
bt::Tracker::failureCount
virtual Uint32 failureCount() const =0
bt::TrackerInterface
Definition: trackerinterface.h:57
bt::PeerSource
Definition: peersource.h:60
bt::TrackerDataSource
Definition: tracker.h:40
bt::Tracker::failed
void failed(const QString &err)
Emit the failure signal, and set the error.
bt::Tracker::requestOK
void requestOK()
bt::Tracker::stopDone
void stopDone()
bt::Tracker::handleFailure
void handleFailure()
Handle a failure.
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::Tracker::timedDelete
void timedDelete(int ms)
bt::Tracker
Definition: tracker.h:55
bt::Tracker::requestFailed
void requestFailed(const QString &failure_reason)
bt::Tracker::getTier
int getTier() const
Get the trackers tier.
Definition: tracker.h:89
bt::Tracker::bytesUploaded
Uint64 bytesUploaded() const
Calculates the bytes uploaded to send with the request.
bt::Tracker::setCustomIP
static void setCustomIP(const QString &str)
bt::Tracker::bytesDownloaded
Uint64 bytesDownloaded() const
Calculates the bytes downloaded to send with the request.
bt::PeerID
Definition: peerid.h:51
bt::Tracker::scrapeDone
void scrapeDone()
bt::Tracker::trackerURL
QUrl trackerURL() const
get the tracker url
Definition: tracker.h:68