File indexing completed on 2025-01-05 04:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2008 Joris Guisson <joris.guisson@gmail.com> 0003 SPDX-FileCopyrightText: 2008 Ivan Vasic <ivasic@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef BTCHUNKSELECTORINTERFACE_H 0008 #define BTCHUNKSELECTORINTERFACE_H 0009 0010 #include <ktorrent_export.h> 0011 #include <util/constants.h> 0012 0013 namespace bt 0014 { 0015 class BitSet; 0016 class Downloader; 0017 class PeerManager; 0018 class ChunkManager; 0019 class PieceDownloader; 0020 0021 /** 0022 * @author Joris Guisson 0023 * 0024 * Interface class for selecting chunks to download. 0025 */ 0026 class KTORRENT_EXPORT ChunkSelectorInterface 0027 { 0028 public: 0029 ChunkSelectorInterface(); 0030 virtual ~ChunkSelectorInterface(); 0031 0032 /** 0033 * Initialize the chunk selector, will be called automatically when 0034 * the ChunkSelector is set. 0035 * @param cman The ChunkManager 0036 * @param downer The Downloader 0037 * @param pman The PeerManager 0038 */ 0039 virtual void init(ChunkManager *cman, Downloader *downer, PeerManager *pman); 0040 0041 /** 0042 * Select which chunk to download for a PieceDownloader. 0043 * @param pd The PieceDownloader 0044 * @param chunk Index of chunk gets stored here 0045 * @return true upon succes, false otherwise 0046 */ 0047 virtual bool select(PieceDownloader *pd, Uint32 &chunk) = 0; 0048 0049 /** 0050 * Select a range of chunks to download from a webseeder. 0051 * @param from First chunk of the range 0052 * @param to Last chunk of the range 0053 * @param max_len Maximum length of range 0054 * @return true if everything is OK 0055 */ 0056 virtual bool selectRange(Uint32 &from, Uint32 &to, Uint32 max_len); 0057 0058 /** 0059 * Data has been checked, and these chunks are OK. 0060 * @param ok_chunks The ok_chunks 0061 * @param from First chunk of check 0062 * @param to Last chunk of check 0063 */ 0064 virtual void dataChecked(const BitSet &ok_chunks, Uint32 from, Uint32 to) = 0; 0065 0066 /** 0067 * A range of chunks has been reincluded. This is called when a user 0068 * reselects a file for download. 0069 * @param from The first chunk 0070 * @param to The last chunk 0071 */ 0072 virtual void reincluded(Uint32 from, Uint32 to) = 0; 0073 0074 /** 0075 * Reinsert a chunk. This is called when a chunk is corrupted or downloading it failed (hash doesn't match) 0076 * The selector should make sure that this is added again 0077 * @param chunk The chunk 0078 */ 0079 virtual void reinsert(Uint32 chunk) = 0; 0080 0081 protected: 0082 ChunkManager *cman; 0083 Downloader *downer; 0084 PeerManager *pman; 0085 }; 0086 } 0087 0088 #endif