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

« back to all changes in this revision

Viewing changes to libktorrent/torrent/peersourcemanager.h

  • Committer: Bazaar Package Importer
  • Author(s): Richard Birnie
  • Date: 2008-06-03 20:32:46 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: james.westby@ubuntu.com-20080603203246-dfyemn010uhsf433
Tags: 3.1~rc1+dfsg.1-1ubuntu1
* New upstream development release      
 - Dropped 01_support_external_libbtcore.diffm,
   97_fix_target_link_libraries.diff,
   99_libbtcore_scramble_soname.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 BTPEERSOURCEMANAGER_H
21
 
#define BTPEERSOURCEMANAGER_H
22
 
 
23
 
#include <qtimer.h>
24
 
#include <qdatetime.h>
25
 
#include <qptrlist.h>
26
 
#include <util/ptrmap.h>
27
 
#include <interfaces/trackerslist.h>
28
 
 
29
 
namespace kt
30
 
{
31
 
        class PeerSource;
32
 
}
33
 
 
34
 
namespace dht
35
 
{
36
 
        class DHTTrackerBackend;
37
 
}
38
 
 
39
 
namespace bt
40
 
{
41
 
        class Tracker;
42
 
        class PeerManager;
43
 
        class Torrent;
44
 
        class TorrentControl;
45
 
 
46
 
        /**
47
 
         * @author Joris Guisson <joris.guisson@gmail.com>
48
 
         * 
49
 
         * This class manages all PeerSources.
50
 
        */
51
 
        class PeerSourceManager : public QObject, public kt::TrackersList
52
 
        {
53
 
                Q_OBJECT
54
 
                                
55
 
                TorrentControl* tor;
56
 
                PeerManager* pman;
57
 
                PtrMap<KURL,Tracker> trackers;
58
 
                QPtrList<kt::PeerSource> additional;
59
 
                Tracker* curr;
60
 
                dht::DHTTrackerBackend* m_dht;
61
 
                bool started;
62
 
                bool pending;
63
 
                KURL::List custom_trackers;
64
 
                QDateTime request_time;
65
 
                QTimer timer;
66
 
                Uint32 failures;
67
 
                bool no_save_custom_trackers;
68
 
        public:
69
 
                PeerSourceManager(TorrentControl* tor,PeerManager* pman);
70
 
                virtual ~PeerSourceManager();
71
 
        
72
 
                                
73
 
                /**
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
78
 
                 */
79
 
                void addPeerSource(kt::PeerSource* ps);
80
 
 
81
 
                /**
82
 
                 * See if the PeerSourceManager has been started 
83
 
                 */
84
 
                bool isStarted() const {return started;}
85
 
                
86
 
                /**
87
 
                 * Start gathering peers
88
 
                 */
89
 
                void start();
90
 
                
91
 
                /**
92
 
                 * Stop gathering peers
93
 
                 * @param wjob WaitJob to wait at exit for the completion of stopped events to the trackers
94
 
                 */
95
 
                void stop(WaitJob* wjob = 0);
96
 
                
97
 
                /**
98
 
                 * Notify peersources and trackrs that the download is complete.
99
 
                 */
100
 
                void completed();
101
 
                
102
 
                /**
103
 
                 * Do a manual update on all peer sources and trackers.
104
 
                 */
105
 
                void manualUpdate();
106
 
                
107
 
                /**
108
 
                 * Remove a Tracker or PeerSource.
109
 
                 * @param ps 
110
 
                 */
111
 
                void removePeerSource(kt::PeerSource* ps);
112
 
                
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();
119
 
                
120
 
                /**
121
 
                 * Get the time to the next tracker update.
122
 
                 * @return The time in seconds
123
 
                 */
124
 
                Uint32 getTimeToNextUpdate() const;
125
 
                
126
 
                /// Get the number of potential seeders
127
 
                Uint32 getNumSeeders() const;
128
 
                
129
 
                /// Get the number of potential leechers
130
 
                Uint32 getNumLeechers() const;
131
 
                
132
 
                /// Get the number of failures
133
 
                Uint32 getNumFailures() const {return failures;}
134
 
                
135
 
                ///Adds DHT as PeerSource for this torrent
136
 
                void addDHT();
137
 
                ///Removes DHT from PeerSourceManager for this torrent.
138
 
                void removeDHT();
139
 
                ///Checks if DHT is enabled
140
 
                bool dhtStarted();
141
 
                
142
 
        private slots:
143
 
                /**
144
 
                 * The an error happened contacting the tracker.
145
 
                 * @param err The error
146
 
                 */
147
 
                void onTrackerError(const QString & err);
148
 
                
149
 
                /**
150
 
                 * Tracker update was OK.
151
 
                 * @param 
152
 
                 */
153
 
                void onTrackerOK();
154
 
                
155
 
                /**
156
 
                 * Tracker is doing a request.  
157
 
                 */
158
 
                void onTrackerRequestPending();
159
 
                
160
 
                /**
161
 
                 * Update the current tracker manually
162
 
                 */
163
 
                void updateCurrentManually();
164
 
                
165
 
        signals:
166
 
                /**
167
 
                 * Status has changed of the tracker.
168
 
                 * @param ns The new status
169
 
                 */
170
 
                void statusChanged(const QString & ns);
171
 
                
172
 
        private:
173
 
                void saveCustomURLs();
174
 
                void loadCustomURLs();
175
 
                void addTracker(Tracker* trk);
176
 
                void switchTracker(Tracker* trk);
177
 
                Tracker* selectTracker();
178
 
        };
179
 
 
180
 
}
181
 
 
182
 
#endif