File indexing completed on 2024-06-02 05:05:29
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTPEERUPLOADER_H 0007 #define BTPEERUPLOADER_H 0008 0009 #include <download/request.h> 0010 #include <qlist.h> 0011 0012 namespace bt 0013 { 0014 class Peer; 0015 class ChunkManager; 0016 0017 const Uint32 ALLOWED_FAST_SIZE = 8; 0018 0019 /** 0020 * @author Joris Guisson 0021 * @brief Uploads pieces to a Peer 0022 * 0023 * This class handles the uploading of pieces to a Peer. It keeps 0024 * track of a list of Request objects. All these Requests where sent 0025 * by the Peer. It will upload the pieces to the Peer, making sure 0026 * that the maximum upload rate isn't surpassed. 0027 */ 0028 class PeerUploader 0029 { 0030 Peer *peer; 0031 QList<Request> requests; 0032 Uint32 uploaded; 0033 0034 public: 0035 /** 0036 * Constructor. Set the Peer. 0037 * @param peer The Peer 0038 */ 0039 PeerUploader(Peer *peer); 0040 virtual ~PeerUploader(); 0041 0042 /** 0043 * Add a Request to the list of Requests. 0044 * @param r The Request 0045 */ 0046 void addRequest(const Request &r); 0047 0048 /** 0049 * Remove a Request from the list of Requests. 0050 * @param r The Request 0051 */ 0052 void removeRequest(const Request &r); 0053 0054 /** 0055 * Update the PeerUploader. This will check if there are Request, and 0056 * will try to handle them. 0057 * @param cman The ChunkManager 0058 * @return The number of bytes uploaded 0059 */ 0060 Uint32 handleRequests(bt::ChunkManager &cman); 0061 0062 /// Get the number of requests 0063 Uint32 getNumRequests() const; 0064 0065 void addUploadedBytes(Uint32 bytes) 0066 { 0067 uploaded += bytes; 0068 } 0069 0070 /** 0071 * Clear all pending requests. 0072 */ 0073 void clearAllRequests(); 0074 }; 0075 0076 } 0077 0078 #endif