File indexing completed on 2025-01-05 04:37:24
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTPEERSOURCEMANAGER_H 0007 #define BTPEERSOURCEMANAGER_H 0008 0009 #include <interfaces/torrentinterface.h> 0010 #include <tracker/tracker.h> 0011 #include <tracker/trackermanager.h> 0012 #include <util/constants.h> 0013 #include <util/waitjob.h> 0014 0015 namespace dht 0016 { 0017 class DHTPeerSource; 0018 } 0019 0020 namespace bt 0021 { 0022 class Torrent; 0023 class TorrentControl; 0024 class PeerSource; 0025 0026 /** 0027 * @author Joris Guisson <joris.guisson@gmail.com> 0028 * 0029 * This class manages all PeerSources. 0030 */ 0031 class PeerSourceManager : public TrackerManager 0032 { 0033 QList<PeerSource *> additional; 0034 dht::DHTPeerSource *m_dht; 0035 0036 public: 0037 PeerSourceManager(TorrentControl *tor, PeerManager *pman); 0038 ~PeerSourceManager() override; 0039 0040 /** 0041 * Add a PeerSource, the difference between PeerSource and Tracker 0042 * is that only one Tracker can be used at the same time, 0043 * PeerSource can always be used. 0044 * @param ps The PeerSource 0045 */ 0046 void addPeerSource(PeerSource *ps); 0047 0048 /** 0049 * Remove a Tracker or PeerSource. 0050 * @param ps 0051 */ 0052 void removePeerSource(PeerSource *ps); 0053 0054 /** 0055 * See if the PeerSourceManager has been started 0056 */ 0057 bool isStarted() const 0058 { 0059 return started; 0060 } 0061 0062 void start() override; 0063 void stop(WaitJob *wjob = nullptr) override; 0064 void completed() override; 0065 void manualUpdate() override; 0066 0067 /// Adds DHT as PeerSource for this torrent 0068 void addDHT(); 0069 /// Removes DHT from PeerSourceManager for this torrent. 0070 void removeDHT(); 0071 /// Checks if DHT is enabled 0072 bool dhtStarted(); 0073 }; 0074 0075 } 0076 0077 #endif