libktorrent  2.2.0
Public Types | Signals | Public Member Functions | Static Public Member Functions | Friends | List of all members
bt::Peer Class Reference

Manages the connection with a peer. More...

#include <peer.h>

Inheritance diagram for bt::Peer:
Inheritance graph
[legend]

Public Types

typedef QSharedPointer< PeerPtr
 
typedef QWeakPointer< PeerWPtr
 

Signals

void metadataDownloaded (const QByteArray &data)
 

Public Member Functions

 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)
 
bt::Uint32 averageDownloadSpeed () const override
 
Uint32 bytesAvailable () const
 Get the number of bytes available to read.
 
void choke ()
 Choke the peer.
 
void chunkAllowed (Uint32 chunk) override
 Peer is allowed to download chunk (used for superseeding)
 
void clearPendingPieceUploads ()
 
void closeConnection ()
 
void emitMetadataDownloaded (const QByteArray &data)
 
void emitPex (const QByteArray &data)
 
void emitPortPacket ()
 
net::Address getAddress () const
 Get the address of the peer.
 
const QTime & getConnectTime () const
 Get the time the peer connection was established.
 
Uint32 getDownloadRate () const
 Get the download rate in bytes per sec.
 
Uint32 getID () const
 Get the peer's unique ID.
 
QString getIPAddresss () const
 Get the IP address of the Peer.
 
PeerDownloadergetPeerDownloader () const
 Get the PeerDownloader.
 
PeerManagergetPeerManager ()
 Get the PeerManager.
 
PeerUploadergetPeerUploader () const
 Get the PeerUploader.
 
Uint16 getPort () const
 Get the port of the Peer.
 
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.
 
void handlePacket (const bt::Uint8 *packet, bt::Uint32 size) override
 Handle a received packet.
 
bool hasWantedChunks (const BitSet &wanted_chunks) const
 Check if the peer has wanted chunks.
 
bool isSnubbed () const
 Are we being snubbed by the Peer.
 
bool isStalled () const
 See if the peer is stalled.
 
void kill () override
 
void pause ()
 Pause the peer connection.
 
float percentAvailable () const
 
Uint32 readData (Uint8 *buf, Uint32 len)
 
void sendAllowedFast (Uint32 index)
 
void sendBitSet (const BitSet &bs)
 
void sendCancel (const Request &r)
 
void sendChoke ()
 
bool sendChunk (Uint32 index, Uint32 begin, Uint32 len, Chunk *ch)
 
Uint32 sendData (const Uint8 *data, Uint32 len)
 
void sendEvilUnchoke ()
 
void sendExtProtHandshake (Uint16 port, Uint32 metadata_size, bool partial_seed)
 Send an extended protocol handshake.
 
void sendExtProtMsg (Uint8 id, const QByteArray &data)
 Send an extended protocol message.
 
void sendHave (Uint32 index)
 
void sendHaveAll ()
 Send a have all message.
 
void sendHaveNone ()
 Send a have none message.
 
void sendInterested ()
 
void sendNotInterested ()
 
void sendPort (Uint16 port)
 
void sendReject (const Request &r)
 
void sendRequest (const Request &r)
 
void sendSuggestPiece (Uint32 index)
 
void sendUnchoke ()
 
void setACAScore (double s)
 Set the ACA score.
 
void setGroupIDs (Uint32 up_gid, Uint32 down_gid)
 
void setPexEnabled (bool on)
 Disable or enable pex.
 
void unpause ()
 Unpause the peer connection.
 
void update ()
 Update the up- and down- speed and handle incoming packets.
 
- Public Member Functions inherited from bt::PeerInterface
 PeerInterface (const PeerID &peer_id, Uint32 num_chunks)
 
bool areWeChoked () const
 Are we choked for the Peer.
 
bool areWeInterested () const
 Are we interested in the Peer.
 
const BitSetgetBitSet () const
 Get the Peer's BitSet.
 
TimeStamp getChokeTime () const
 Get the time when this Peer choked us.
 
const PeerIDgetPeerID () const
 Get the Peer's ID.
 
const StatsgetStats () const
 Get the Peer's statistics.
 
TimeStamp getUnchokeTime () const
 Get the time when this Peer unchoked us.
 
bool isChoked () const
 Is the Peer choked.
 
bool isDHTSupported () const
 See if the peer supports DHT.
 
bool isInterested () const
 Is the Peer interested.
 
bool isKilled () const
 See if the peer has been killed.
 
bool isSeeder () const
 See if the peer is a seeder.
 

Static Public Member Functions

static void setResolveHostnames (bool on)
 Enable or disable hostname resolving.
 

Friends

class PeerDownloader
 

Additional Inherited Members

- Protected Attributes inherited from bt::PeerInterface
bool killed
 
bool paused
 
PeerID peer_id
 
BitSet pieces
 
PeerInterface::Stats stats
 

Detailed Description

Author
Joris Guisson

This class manages a connection with a peer in the P2P network. It provides functions for sending packets. Packets it receives get relayed to the outside world using a bunch of signals.

Definition at line 58 of file peer.h.

Constructor & Destructor Documentation

◆ Peer()

bt::Peer::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 
)

Constructor, set the socket. The socket is already opened.

Parameters
sockThe socket
peer_idThe Peer's BitTorrent ID
num_chunksThe number of chunks in the file
chunk_sizeSize of each chunk
supportWhich extensions the peer supports
localWhether or not it is a local peer
tokenConnectionLimit token
pmanThe PeerManager

Member Function Documentation

◆ averageDownloadSpeed()

bt::Uint32 bt::Peer::averageDownloadSpeed ( ) const
overridevirtual

Get the average download speed since the last unchoke in bytes/sec

Implements bt::PeerInterface.

◆ clearPendingPieceUploads()

void bt::Peer::clearPendingPieceUploads ( )

Clear all pending piece uploads we are not in the progress of sending.

◆ closeConnection()

void bt::Peer::closeConnection ( )

Close the peers connection.

◆ emitMetadataDownloaded()

void bt::Peer::emitMetadataDownloaded ( const QByteArray &  data)

Emit the metadataDownloaded signal

◆ emitPex()

void bt::Peer::emitPex ( const QByteArray &  data)

Emit the pex signal

◆ emitPortPacket()

void bt::Peer::emitPortPacket ( )

Emit the port packet signal.

◆ kill()

void bt::Peer::kill ( )
overridevirtual

Kill the Peer.

Implements bt::PeerInterface.

◆ metadataDownloaded

void bt::Peer::metadataDownloaded ( const QByteArray &  data)
signal

Emitted when metadata has been downloaded from the Peer

◆ percentAvailable()

float bt::Peer::percentAvailable ( ) const

Get the percentual amount of data available from peer.

◆ readData()

Uint32 bt::Peer::readData ( Uint8 *  buf,
Uint32  len 
)

Reads data from the peer.

Parameters
bufThe buffer to store the data
lenThe maximum number of bytes to read
Returns
The number of bytes read

◆ sendAllowedFast()

void bt::Peer::sendAllowedFast ( Uint32  index)

Send an allowed fast packet

Parameters
index

◆ sendBitSet()

void bt::Peer::sendBitSet ( const BitSet bs)

Send a BitSet. The BitSet indicates which chunks we have.

Parameters
bsThe BitSet

◆ sendCancel()

void bt::Peer::sendCancel ( const Request r)

Cancel a request.

Parameters
reqThe Request

◆ sendChoke()

void bt::Peer::sendChoke ( )

Send a choke packet.

◆ sendChunk()

bool bt::Peer::sendChunk ( Uint32  index,
Uint32  begin,
Uint32  len,
Chunk ch 
)

Send a chunk of data.

Parameters
indexIndex of chunk
beginOffset into chunk
lenLength of data
chThe Chunk
Returns
true If we satisfy the request, false otherwise

◆ sendData()

Uint32 bt::Peer::sendData ( const Uint8 *  data,
Uint32  len 
)

Send a chunk of data.

Parameters
dataThe data
lenThe length
protoIndicates whether the packed is data or a protocol message
Returns
Number of bytes written

◆ sendEvilUnchoke()

void bt::Peer::sendEvilUnchoke ( )

Sends an unchoke message but doesn't update the am_choked field so KT still thinks it is choked (and will not upload to it), this is to punish snubbers.

◆ sendHave()

void bt::Peer::sendHave ( Uint32  index)

Send a have packet.

Parameters
index

◆ sendInterested()

void bt::Peer::sendInterested ( )

Send an interested packet.

◆ sendNotInterested()

void bt::Peer::sendNotInterested ( )

Send a not interested packet.

◆ sendPort()

void bt::Peer::sendPort ( Uint16  port)

Send a port message

Parameters
portThe port

◆ sendReject()

void bt::Peer::sendReject ( const Request r)

Send a reject for a request

Parameters
reqThe Request

◆ sendRequest()

void bt::Peer::sendRequest ( const Request r)

Send a request for data.

Parameters
reqThe Request

◆ sendSuggestPiece()

void bt::Peer::sendSuggestPiece ( Uint32  index)

Send a suggest piece packet

Parameters
indexIndex of the chunk

◆ sendUnchoke()

void bt::Peer::sendUnchoke ( )

Send an unchoke packet.

◆ setGroupIDs()

void bt::Peer::setGroupIDs ( Uint32  up_gid,
Uint32  down_gid 
)

Set the peer's group IDs for traffic

Parameters
up_gidThe upload gid
down_gidThe download gid

The documentation for this class was generated from the following file: