libktorrent  2.1.1
chunkselector.h
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 BTCHUNKSELECTOR_H
21 #define BTCHUNKSELECTOR_H
22 
23 #include <list>
24 #include <util/timer.h>
25 #include <interfaces/chunkselectorinterface.h>
26 
27 
28 
29 namespace bt
30 {
31  class BitSet;
32  class ChunkManager;
33  class Downloader;
34  class PeerManager;
35  class PieceDownloader;
36 
42  class ChunkSelector : public ChunkSelectorInterface
43  {
44  std::list<Uint32> chunks;
45  Timer sort_timer;
46  public:
47  ChunkSelector();
48  ~ChunkSelector() override;
49 
50  void init(ChunkManager* cman, Downloader* downer, PeerManager* pman) override;
51 
58  bool select(PieceDownloader* pd,Uint32 & chunk) override;
59 
64  void dataChecked(const bt::BitSet& ok_chunks, bt::Uint32 from, bt::Uint32 to) override;
65 
71  void reincluded(Uint32 from, Uint32 to) override;
72 
77  void reinsert(Uint32 chunk) override;
78 
79  bool selectRange(Uint32 & from,Uint32 & to,Uint32 max_len) override;
80  protected:
81  Uint32 leastPeers(const std::list<Uint32> & lp,Uint32 alternative,Uint32 max_peers_per_chunk);
82  };
83 
84 }
85 
86 #endif
87 
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:55
bt::ChunkSelector::reincluded
void reincluded(Uint32 from, Uint32 to) override
bt::ChunkSelector::init
void init(ChunkManager *cman, Downloader *downer, PeerManager *pman) override
bt::ChunkSelector::select
bool select(PieceDownloader *pd, Uint32 &chunk) override
bt::ChunkSelector::reinsert
void reinsert(Uint32 chunk) override
bt::ChunkSelector::dataChecked
void dataChecked(const bt::BitSet &ok_chunks, bt::Uint32 from, bt::Uint32 to) override
bt::ChunkSelector::selectRange
bool selectRange(Uint32 &from, Uint32 &to, Uint32 max_len) override