1
/***************************************************************************
2
* Copyright (C) 2005 by Joris Guisson *
3
* joris.guisson@gmail.com *
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. *
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. *
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 BTPEERSOURCEMANAGER_H
21
#define BTPEERSOURCEMANAGER_H
24
#include <qdatetime.h>
26
#include <util/ptrmap.h>
27
#include <interfaces/trackerslist.h>
36
class DHTTrackerBackend;
47
* @author Joris Guisson <joris.guisson@gmail.com>
49
* This class manages all PeerSources.
51
class PeerSourceManager : public QObject, public kt::TrackersList
57
PtrMap<KURL,Tracker> trackers;
58
QPtrList<kt::PeerSource> additional;
60
dht::DHTTrackerBackend* m_dht;
63
KURL::List custom_trackers;
64
QDateTime request_time;
67
bool no_save_custom_trackers;
69
PeerSourceManager(TorrentControl* tor,PeerManager* pman);
70
virtual ~PeerSourceManager();
74
* Add a PeerSource, the difference between PeerSource and Tracker
75
* is that only one Tracker can be used at the same time,
76
* PeerSource can always be used.
77
* @param ps The PeerSource
79
void addPeerSource(kt::PeerSource* ps);
82
* See if the PeerSourceManager has been started
84
bool isStarted() const {return started;}
87
* Start gathering peers
92
* Stop gathering peers
93
* @param wjob WaitJob to wait at exit for the completion of stopped events to the trackers
95
void stop(WaitJob* wjob = 0);
98
* Notify peersources and trackrs that the download is complete.
103
* Do a manual update on all peer sources and trackers.
108
* Remove a Tracker or PeerSource.
111
void removePeerSource(kt::PeerSource* ps);
113
virtual KURL getTrackerURL() const;
114
virtual KURL::List getTrackerURLs();
115
virtual void addTracker(KURL url, bool custom = true,int tier = 1);
116
virtual bool removeTracker(KURL url);
117
virtual void setTracker(KURL url);
118
virtual void restoreDefault();
121
* Get the time to the next tracker update.
122
* @return The time in seconds
124
Uint32 getTimeToNextUpdate() const;
126
/// Get the number of potential seeders
127
Uint32 getNumSeeders() const;
129
/// Get the number of potential leechers
130
Uint32 getNumLeechers() const;
132
/// Get the number of failures
133
Uint32 getNumFailures() const {return failures;}
135
///Adds DHT as PeerSource for this torrent
137
///Removes DHT from PeerSourceManager for this torrent.
139
///Checks if DHT is enabled
144
* The an error happened contacting the tracker.
145
* @param err The error
147
void onTrackerError(const QString & err);
150
* Tracker update was OK.
156
* Tracker is doing a request.
158
void onTrackerRequestPending();
161
* Update the current tracker manually
163
void updateCurrentManually();
167
* Status has changed of the tracker.
168
* @param ns The new status
170
void statusChanged(const QString & ns);
173
void saveCustomURLs();
174
void loadCustomURLs();
175
void addTracker(Tracker* trk);
176
void switchTracker(Tracker* trk);
177
Tracker* selectTracker();