/usr/include/libktorrent/interfaces/peerinterface.h is in libktorrent-dev 1.3.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /***************************************************************************
* Copyright (C) 2005 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef BTPEERINTERFACE_H
#define BTPEERINTERFACE_H
#include <ktorrent_export.h>
#include <util/constants.h>
#include <util/bitset.h>
#include <peer/peerid.h>
namespace bt
{
/**
* @author Joris Guisson
* @brief Interface for a Peer
*
* This is the interface for a Peer, it allows other classes to
* get statistics about a Peer, and provides some basic funtionality provided by a Peer.
*/
class KTORRENT_EXPORT PeerInterface
{
public:
/**
Constructor, initialize the PeerID and the number of chunks
@param peer_id The PeerID
@param num_chunks The number of chunks
*/
PeerInterface(const PeerID & peer_id, Uint32 num_chunks);
virtual ~PeerInterface();
struct Stats
{
/// IP address of peer (dotted notation)
QString ip_address;
/// Host name of the peer
QString hostname;
/// The client (Azureus, BitComet, ...)
QString client;
/// Download rate (bytes/s)
bt::Uint32 download_rate;
/// Upload rate (bytes/s)
bt::Uint32 upload_rate;
/// Choked or not
bool choked;
/// Snubbed or not (i.e. we haven't received a piece for a minute)
bool snubbed;
/// Percentage of file which the peer has
float perc_of_file;
/// Does this peer support DHT
bool dht_support;
/// Amount of data uploaded
bt::Uint64 bytes_uploaded;
/// Amount of data downloaded
bt::Uint64 bytes_downloaded;
/// Advanced choke algorithm score
double aca_score;
/// Flag to indicate if this peer has an upload slot
bool has_upload_slot;
/// Is the peer interested
bool interested;
/// Am I interested in the peer
bool am_interested;
/// Whether or not this connection is encrypted
bool encrypted;
/// Number of upload requests queued
bt::Uint32 num_up_requests;
/// Number of outstanding download requests queued
bt::Uint32 num_down_requests;
/// Supports the fast extensions
bool fast_extensions;
/// Is this a peer on the local network
bool local;
/// Whether or not the peer supports the extension protocol
bool extension_protocol;
/// Max number of outstanding requests (reqq in extended protocol handshake)
bt::Uint32 max_request_queue;
/// Time the peer choked us
TimeStamp time_choked;
/// Time the peer unchoked us
TimeStamp time_unchoked;
/// The transport protocol used by the peer
bt::TransportProtocol transport_protocol;
/// Is this a partial seed
bool partial_seed;
/// Get the address of the peer (hostname if it is valid, IP otherwise)
QString address() const {return hostname.isEmpty() ? ip_address : hostname;}
};
/// Get the Peer's statistics
const Stats & getStats() const {return stats;}
/**
Kill the Peer, will ensure the PeerManager closes the connection, and cleans things up.
*/
virtual void kill() = 0;
/// See if the peer has been killed.
bool isKilled() const {return killed;}
/**
Get the average download speed since the last unchoke in bytes/sec
*/
virtual bt::Uint32 averageDownloadSpeed() const = 0;
/// Get the Peer's BitSet
const BitSet & getBitSet() const {return pieces;}
/// Get the Peer's ID
const PeerID & getPeerID() const {return peer_id;}
/// Is the Peer choked
bool isChoked() const {return stats.choked;}
/// Is the Peer interested
bool isInterested() const {return stats.interested;}
/// Are we interested in the Peer
bool areWeInterested() const {return stats.am_interested;}
/// Are we choked for the Peer
bool areWeChoked() const {return !stats.has_upload_slot || paused;}
/// See if the peer supports DHT
bool isDHTSupported() const {return stats.dht_support;}
/// Get the time when this Peer choked us
TimeStamp getChokeTime() const {return stats.time_choked;}
/// Get the time when this Peer unchoked us
TimeStamp getUnchokeTime() const {return stats.time_unchoked;}
/// See if the peer is a seeder.
bool isSeeder() const {return pieces.allOn();}
/// Peer is allowed to download chunk (used for superseeding)
virtual void chunkAllowed(bt::Uint32 chunk) = 0;
/// Handle a received packet
virtual void handlePacket(const bt::Uint8* packet, bt::Uint32 size) = 0;
protected:
mutable PeerInterface::Stats stats;
bool paused;
bool killed;
PeerID peer_id;
BitSet pieces;
};
}
#endif
|