20 #ifndef BTPEERINTERFACE_H
21 #define BTPEERINTERFACE_H
23 #include <ktorrent_export.h>
24 #include <util/constants.h>
25 #include <util/bitset.h>
26 #include <peer/peerid.h>
39 class KTORRENT_EXPORT PeerInterface
47 PeerInterface(
const PeerID & peer_id, Uint32 num_chunks);
48 virtual ~PeerInterface();
59 bt::Uint32 download_rate;
61 bt::Uint32 upload_rate;
71 bt::Uint64 bytes_uploaded;
73 bt::Uint64 bytes_downloaded;
85 bt::Uint32 num_up_requests;
87 bt::Uint32 num_down_requests;
93 bool extension_protocol;
95 bt::Uint32 max_request_queue;
97 TimeStamp time_choked;
99 TimeStamp time_unchoked;
101 bt::TransportProtocol transport_protocol;
106 QString address()
const {
return hostname.isEmpty() ? ip_address : hostname;}
110 const Stats & getStats()
const {
return stats;}
115 virtual void kill() = 0;
118 bool isKilled()
const {
return killed;}
123 virtual bt::Uint32 averageDownloadSpeed()
const = 0;
126 const BitSet & getBitSet()
const {
return pieces;}
129 const PeerID & getPeerID()
const {
return peer_id;}
132 bool isChoked()
const {
return stats.choked;}
135 bool isInterested()
const {
return stats.interested;}
138 bool areWeInterested()
const {
return stats.am_interested;}
141 bool areWeChoked()
const {
return !stats.has_upload_slot || paused;}
144 bool isDHTSupported()
const {
return stats.dht_support;}
147 TimeStamp getChokeTime()
const {
return stats.time_choked;}
150 TimeStamp getUnchokeTime()
const {
return stats.time_unchoked;}
153 bool isSeeder()
const {
return pieces.allOn();}
156 virtual void chunkAllowed(bt::Uint32 chunk) = 0;
159 virtual void handlePacket(
const bt::Uint8* packet, bt::Uint32 size) = 0;