libktorrent  2.2.0
peerinterface.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 BTPEERINTERFACE_H
21 #define BTPEERINTERFACE_H
22 
23 #include <ktorrent_export.h>
24 #include <util/constants.h>
25 #include <util/bitset.h>
26 #include <peer/peerid.h>
27 
28 
29 namespace bt
30 {
31 
39  class KTORRENT_EXPORT PeerInterface
40  {
41  public:
47  PeerInterface(const PeerID & peer_id, Uint32 num_chunks);
48  virtual ~PeerInterface();
49 
50  struct Stats
51  {
53  QString ip_address;
55  QString hostname;
57  QString client;
59  bt::Uint32 download_rate;
61  bt::Uint32 upload_rate;
63  bool choked;
65  bool snubbed;
67  float perc_of_file;
69  bool dht_support;
71  bt::Uint64 bytes_uploaded;
73  bt::Uint64 bytes_downloaded;
75  double aca_score;
77  bool has_upload_slot;
79  bool interested;
81  bool am_interested;
83  bool encrypted;
85  bt::Uint32 num_up_requests;
87  bt::Uint32 num_down_requests;
89  bool fast_extensions;
91  bool local;
93  bool extension_protocol;
95  bt::Uint32 max_request_queue;
97  TimeStamp time_choked;
99  TimeStamp time_unchoked;
101  bt::TransportProtocol transport_protocol;
103  bool partial_seed;
104 
106  QString address() const {return hostname.isEmpty() ? ip_address : hostname;}
107  };
108 
110  const Stats & getStats() const {return stats;}
111 
115  virtual void kill() = 0;
116 
118  bool isKilled() const {return killed;}
119 
123  virtual bt::Uint32 averageDownloadSpeed() const = 0;
124 
126  const BitSet & getBitSet() const {return pieces;}
127 
129  const PeerID & getPeerID() const {return peer_id;}
130 
132  bool isChoked() const {return stats.choked;}
133 
135  bool isInterested() const {return stats.interested;}
136 
138  bool areWeInterested() const {return stats.am_interested;}
139 
141  bool areWeChoked() const {return !stats.has_upload_slot || paused;}
142 
144  bool isDHTSupported() const {return stats.dht_support;}
145 
147  TimeStamp getChokeTime() const {return stats.time_choked;}
148 
150  TimeStamp getUnchokeTime() const {return stats.time_unchoked;}
151 
153  bool isSeeder() const {return pieces.allOn();}
154 
156  virtual void chunkAllowed(bt::Uint32 chunk) = 0;
157 
159  virtual void handlePacket(const bt::Uint8* packet, bt::Uint32 size) = 0;
160 
161 
162  protected:
163  mutable PeerInterface::Stats stats;
164  bool paused;
165  bool killed;
166  PeerID peer_id;
167  BitSet pieces;
168  };
169 
170 }
171 
172 #endif
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:55
bt::PeerInterface::Stats
Definition: peerinterface.h:87
bt::PeerID
Definition: peerid.h:51