25 #include <util/timer.h>
26 #include <interfaces/peerinterface.h>
27 #include <util/ptrmap.h>
28 #include <mse/encryptedpacketsocket.h>
29 #include <ktorrent_export.h>
31 #include "peerprotocolextension.h"
32 #include "connectionlimit.h"
74 Peer(mse::EncryptedPacketSocket::Ptr sock,
80 ConnectionLimit::Token::Ptr token,
86 Uint32
getID()
const {
return id;}
312 typedef QSharedPointer<Peer> Ptr;
313 typedef QWeakPointer<Peer> WPtr;
316 void resolved(
const QString & hinfo);
319 void handleChoke(Uint32 len);
320 void handleUnchoke(Uint32 len);
321 void handleInterested(Uint32 len);
322 void handleNotInterested(Uint32 len);
323 void handleHave(
const Uint8* packet,Uint32 len);
324 void handleHaveAll(Uint32 len);
325 void handleHaveNone(Uint32 len);
326 void handleBitField(
const Uint8* packet,Uint32 len);
327 void handleRequest(
const Uint8* packet,Uint32 len);
328 void handlePiece(
const Uint8* packet,Uint32 len);
329 void handleCancel(
const Uint8* packet,Uint32 len);
330 void handleReject(
const Uint8* packet,Uint32 len);
331 void handlePort(
const Uint8* packet,Uint32 len);
332 void handleExtendedPacket(
const Uint8* packet,Uint32 size);
333 void handleExtendedHandshake(
const Uint8* packet,Uint32 size);
342 mse::EncryptedPacketSocket::Ptr sock;
343 ConnectionLimit::Token::Ptr token;
360 Uint64 bytes_downloaded_since_unchoke;
362 static bool resolve_hostname;
Class which downloads pieces from a Peer.
Simple implementation of a BitSet.
void metadataDownloaded(const QByteArray &data)
PeerDownloader * getPeerDownloader() const
Get the PeerDownloader.
Uint32 getTimeSinceLastPiece() const
Get the time in milliseconds since the last time a piece was received.
Uint32 getUploadRate() const
Get the upload rate in bytes per sec.
bool hasWantedChunks(const BitSet &wanted_chunks) const
Check if the peer has wanted chunks.
static void setResolveHostnames(bool on)
Enable or disable hostname resolving.
bool sendChunk(Uint32 index, Uint32 begin, Uint32 len, Chunk *ch)
void sendCancel(const Request &r)
const QTime & getConnectTime() const
Get the time the peer connection was established.
QString getIPAddresss() const
Get the IP address of the Peer.
void choke()
Choke the peer.
void setPexEnabled(bool on)
Disable or enable pex.
Keep track of a piece of the file.
Uint32 sendData(const Uint8 *data, Uint32 len)
void clearPendingPieceUploads()
Peer(mse::EncryptedPacketSocket::Ptr sock, const PeerID &peer_id, Uint32 num_chunks, Uint32 chunk_size, Uint32 support, bool local, ConnectionLimit::Token::Ptr token, PeerManager *pman)
Manages the connection with a peer.
void setGroupIDs(Uint32 up_gid, Uint32 down_gid)
void handlePacket(const bt::Uint8 *packet, bt::Uint32 size) override
Handle a received packet.
Uint32 bytesAvailable() const
Get the number of bytes available to read.
void sendHave(Uint32 index)
void sendRequest(const Request &r)
bool isSnubbed() const
Are we being snubbed by the Peer.
Uint16 getPort() const
Get the port of the Peer.
PeerUploader * getPeerUploader() const
Get the PeerUploader.
void chunkAllowed(Uint32 chunk) override
Peer is allowed to download chunk (used for superseeding)
void sendHaveAll()
Send a have all message.
void sendPort(Uint16 port)
void emitMetadataDownloaded(const QByteArray &data)
Request of a piece sent to other peers.
bt::Uint32 averageDownloadSpeed() const override
void unpause()
Unpause the peer connection.
void sendSuggestPiece(Uint32 index)
bool isStalled() const
See if the peer is stalled.
net::Address getAddress() const
Get the address of the peer.
Uint32 getDownloadRate() const
Get the download rate in bytes per sec.
float percentAvailable() const
void sendAllowedFast(Uint32 index)
void sendHaveNone()
Send a have none message.
void sendBitSet(const BitSet &bs)
void update()
Update the up- and down- speed and handle incoming packets.
void sendExtProtMsg(Uint8 id, const QByteArray &data)
Send an extended protocol message.
Uint32 getID() const
Get the peer's unique ID.
PeerManager * getPeerManager()
Get the PeerManager.
void setACAScore(double s)
Set the ACA score.
Uint32 readData(Uint8 *buf, Uint32 len)
void emitPex(const QByteArray &data)
void pause()
Pause the peer connection.
void sendExtProtHandshake(Uint16 port, Uint32 metadata_size, bool partial_seed)
Send an extended protocol handshake.
void sendReject(const Request &r)
Uploads pieces to a Peer.