libktorrent  2.2.0
peerdownloader.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 BTPEERDOWNLOADER_H
21 #define BTPEERDOWNLOADER_H
22 
23 #include <qlist.h>
24 #include <qobject.h>
25 #include <interfaces/piecedownloader.h>
26 #include <download/request.h>
27 
28 namespace bt
29 {
30  class Peer;
31  class Request;
32  class Piece;
33 
38  {
39  Request req;
40  TimeStamp time_stamp;
41 
43 
49 
55 
58 
60  bool operator < (const TimeStampedRequest & t) const
61  {
62  return time_stamp < t.time_stamp;
63  }
64 
70  bool operator == (const Request & r);
71 
78 
85 
92  };
93 
94 
102  {
103  Q_OBJECT
104  public:
110  PeerDownloader(Peer* peer,Uint32 chunk_size);
111  ~PeerDownloader() override;
112 
114  bool canAddRequest() const override;
115  bool canDownloadChunk() const override;
116 
118  Uint32 getNumRequests() const;
119 
121  bool isChoked() const override;
122 
124  bool isNull() const {return peer == 0;}
125 
130  bool hasChunk(Uint32 idx) const override;
131 
133  const Peer* getPeer() const {return peer;}
134 
138  void checkTimeouts() override;
139 
141  Uint32 getMaxChunkDownloads() const;
142 
147  void choked();
148 
149  QString getName() const override;
150  Uint32 getDownloadRate() const override;
151 
156  void piece(const Piece & p);
157 
158  public Q_SLOTS:
165  void download(const Request & req) override;
166 
171  void cancel(const Request & req) override;
172 
176  void cancelAll() override;
177 
182  void onRejected(const Request & req);
183 
187  void update();
188 
189  private Q_SLOTS:
190  void peerDestroyed();
191 
192 
193  private:
194  Peer* peer;
195  QList<TimeStampedRequest> reqs;
196  QList<Request> wait_queue;
197  Uint32 max_wait_queue_size;
198  Uint32 chunk_size;
199  };
200 
201 }
202 
203 #endif
bt::PeerDownloader
Class which downloads pieces from a Peer.
Definition: peerdownloader.h:102
bt::TimeStampedRequest::TimeStampedRequest
TimeStampedRequest(const TimeStampedRequest &t)
bt::PeerDownloader::isNull
bool isNull() const
Is NULL (is the Peer set)
Definition: peerdownloader.h:124
bt::Piece
Definition: piece.h:32
bt::PeerDownloader::getPeer
const Peer * getPeer() const
Get the Peer.
Definition: peerdownloader.h:133
bt::PeerDownloader::getMaxChunkDownloads
Uint32 getMaxChunkDownloads() const
Get the maximum number of chunk downloads.
bt::PeerDownloader::download
void download(const Request &req) override
bt::PeerDownloader::piece
void piece(const Piece &p)
bt::PieceDownloader
Definition: piecedownloader.h:38
bt::TimeStampedRequest::TimeStampedRequest
TimeStampedRequest(const Request &r)
bt::PeerDownloader::choked
void choked()
bt::PeerDownloader::isChoked
bool isChoked() const override
Is the Peer choked.
bt::Peer
Manages the connection with a peer.
Definition: peer.h:59
bt::PeerDownloader::onRejected
void onRejected(const Request &req)
bt::TimeStampedRequest::operator<
bool operator<(const TimeStampedRequest &t) const
Smaller then operator, uses timestamps to compare.
Definition: peerdownloader.h:60
bt::PeerDownloader::hasChunk
bool hasChunk(Uint32 idx) const override
bt::PeerDownloader::canAddRequest
bool canAddRequest() const override
See if we can add a request to the wait_queue.
bt::Request
Request of a piece sent to other peers.
Definition: request.h:40
bt::PeerDownloader::cancelAll
void cancelAll() override
bt::PeerDownloader::getName
QString getName() const override
bt::PeerDownloader::canDownloadChunk
bool canDownloadChunk() const override
bt::PeerDownloader::checkTimeouts
void checkTimeouts() override
bt::TimeStampedRequest::~TimeStampedRequest
~TimeStampedRequest()
Destructor.
bt::PeerDownloader::getNumRequests
Uint32 getNumRequests() const
Get the number of active requests.
bt::PeerDownloader::update
void update()
bt::TimeStampedRequest
Definition: peerdownloader.h:38
bt::TimeStampedRequest::operator=
TimeStampedRequest & operator=(const Request &r)
bt::TimeStampedRequest::operator==
bool operator==(const Request &r)
bt::PeerDownloader::getDownloadRate
Uint32 getDownloadRate() const override
bt::PeerDownloader::cancel
void cancel(const Request &req) override
bt::PeerDownloader::PeerDownloader
PeerDownloader(Peer *peer, Uint32 chunk_size)