File indexing completed on 2025-01-05 04:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTPEERSOURCE_H 0007 #define BTPEERSOURCE_H 0008 0009 #include <ktorrent_export.h> 0010 #include <net/address.h> 0011 #include <qlist.h> 0012 #include <qobject.h> 0013 #include <util/constants.h> 0014 0015 namespace bt 0016 { 0017 class WaitJob; 0018 0019 /** 0020 * @author Joris Guisson <joris.guisson@gmail.com> 0021 * 0022 * This class is the base class for all classes who which to provide potential peers 0023 * for torrents. PeerSources should work independently and should emit a signal when they 0024 * have peers ready. 0025 */ 0026 class KTORRENT_EXPORT PeerSource : public QObject 0027 { 0028 Q_OBJECT 0029 public: 0030 PeerSource(); 0031 ~PeerSource() override; 0032 0033 /** 0034 * Take the first peer from the list. The item 0035 * is removed from the list. 0036 * @param addr The address of the peer 0037 * @param local Is this is a peer on the local network 0038 * @return true If there was one available, false if not 0039 */ 0040 bool takePeer(net::Address &addr, bool &local); 0041 0042 /** 0043 * Add a peer to the list of peers. 0044 * @param addr The address of the peer 0045 * @param port The port 0046 * @param local Whether or not the peer is on the local network 0047 */ 0048 void addPeer(const net::Address &addr, bool local = false); 0049 0050 public Q_SLOTS: 0051 /** 0052 * Start gathering peers. 0053 */ 0054 virtual void start() = 0; 0055 0056 /** 0057 * Stop gathering peers. 0058 */ 0059 virtual void stop(bt::WaitJob *wjob = nullptr) = 0; 0060 0061 /** 0062 * The torrent has finished downloading. 0063 * This is optional and should be used by HTTP and UDP tracker sources 0064 * to notify the tracker. 0065 */ 0066 virtual void completed(); 0067 0068 /** 0069 * PeerSources wanting to implement a manual update, should implement this. 0070 */ 0071 virtual void manualUpdate(); 0072 0073 /** 0074 * The source is about to be destroyed. Subclasses can override this 0075 * to clean up some things. 0076 */ 0077 virtual void aboutToBeDestroyed(); 0078 Q_SIGNALS: 0079 /** 0080 * This signal should be emitted when a new batch of peers is ready. 0081 * @param ps The PeerSource 0082 */ 0083 void peersReady(PeerSource *ps); 0084 0085 private: 0086 /// List to keep the potential peers in. 0087 QList<QPair<net::Address, bool>> peers; 0088 }; 0089 0090 } 0091 0092 #endif