libktorrent  2.1.1
choker.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 BTCHOKER_H
21 #define BTCHOKER_H
22 
23 #include <qlist.h>
24 #include <util/constants.h>
25 #include <peer/peer.h>
26 #include <ktorrent_export.h>
27 
28 
29 namespace bt
30 {
31  const Uint32 UNDEFINED_ID = 0xFFFFFFFF;
32 
33  class PeerManager;
34  class ChunkManager;
35  struct TorrentStats;
36 
40  class ChokeAlgorithm
41  {
42  protected:
43  Uint32 opt_unchoked_peer_id;
44  public:
45  ChokeAlgorithm();
46  virtual ~ChokeAlgorithm();
47 
54  virtual void doChokingLeechingState(PeerManager & pman,ChunkManager & cman,const TorrentStats & stats) = 0;
55 
62  virtual void doChokingSeedingState(PeerManager & pman,ChunkManager & cman,const TorrentStats & stats) = 0;
63 
65  Uint32 getOptimisticlyUnchokedPeerID() const {return opt_unchoked_peer_id;}
66  };
67 
68 
69 
77  class KTORRENT_EXPORT Choker
78  {
79  ChokeAlgorithm* choke;
80  PeerManager & pman;
81  ChunkManager & cman;
82  static Uint32 num_upload_slots;
83  public:
84  Choker(PeerManager & pman,ChunkManager & cman);
85  virtual ~Choker();
86 
92  void update(bool have_all,const TorrentStats & stats);
93 
95  Uint32 getOptimisticlyUnchokedPeerID() const {return choke->getOptimisticlyUnchokedPeerID();}
96 
98  static void setNumUploadSlots(Uint32 n) {num_upload_slots = n;}
99 
101  static Uint32 getNumUploadSlots() {return num_upload_slots;}
102  };
103 
104 }
105 
106 #endif
bt::ChokeAlgorithm::doChokingSeedingState
virtual void doChokingSeedingState(PeerManager &pman, ChunkManager &cman, const TorrentStats &stats)=0
bt::ChokeAlgorithm::doChokingLeechingState
virtual void doChokingLeechingState(PeerManager &pman, ChunkManager &cman, const TorrentStats &stats)=0
bt::ChunkManager
Definition: chunkmanager.h:61
bt::Choker
Handles the choking.
Definition: choker.h:96
bt::PeerManager
Manages all the Peers.
Definition: peermanager.h:67
bt::TorrentStats
Definition: torrentstats.h:73
bt::ChokeAlgorithm::getOptimisticlyUnchokedPeerID
Uint32 getOptimisticlyUnchokedPeerID() const
Get the optimisticly unchoked peer ID.
Definition: choker.h:83