#include <TransferSessionImpl.h> [code]
Inherits Protocols::BitTorrent::Transfers::TransferSession, and Protocols::BitTorrent::Transfers::SessionStatus.
Inheritance diagram for Protocols::BitTorrent::Transfers::TransferSessionImpl:


This implementatio of TransferSession keeps track of all incoming and outgoing packets and updates the internal state accordingly.
Definition at line 92 of file TransferSessionImpl.h.
Public Member Functions | |
| TransferSessionImpl (Session *, const Handshake &, IntegerResetStopwatch *downloadStopwatch, IntegerResetStopwatch *uploadStopwatch, TransferSessionStatus *) | |
| Constructs a TransferSessionImpl object. | |
| void | sendPacket (const Packet &) |
| Queues up and sends packet at first possible occasion. | |
| void | close () |
| Closes this session. | |
| bool | areWeChoked () const |
| Tells whether the remote peer has choked us. | |
| bool | areWeInterested () const |
| Tells whether we have registered interest in the other peer's pieces. | |
| bool | areWeSnubbed () const |
| Tells whether the remote peer has not uploaded anything to us recently. | |
| bool | areWeSeeder () const |
| Tells whether are are a seeder (we have reported to have all pieces). | |
| bool | isPeerChoked () const |
| Tells whether we have choked the remote peer. | |
| bool | isPeerInterested () const |
| Tells whether the remote peer has registered interest in our pieces. | |
| bool | isPeerSnubbed () const |
| Tells whether we have not uploaded anything to the peer recently. | |
| bool | isPeerSeeder () const |
| Tells whether the remote peer has reported is is a seeder (has all pieces). | |
| qint64 | totalDownloaded () const |
| The total number of bytes (raw Piece bytes only) downloaded from the peer. | |
| qint64 | totalUploaded () const |
| The total number of bytes (raw Piece bytes only) uploaded to the peer. | |
| qint64 | currentDownloadSpeed () const |
| Average download speed (bytes/second) calculated over a sliding time window. | |
| qint64 | currentUploadSpeed () const |
| Average upload speed (bytes/second) calculated over a sliding time window. | |
| QBitArray | peerPiecesAvailable () const |
| Returns a bit array indicating all pieces the remote peer reported to have. | |
| QBitArray | wePiecesAvailable () const |
| Returns a bit array indicating all pieces we reported to have. | |
| void | sessionReceivedData (Session *, const Data &) |
| Handler for the SessionState notification. | |
| void | sessionSendingData (Session *, const Data &) |
| Handler for the SessionState notification. | |
| void | sessionClosing (Session *) |
| Handler for the SessionState notification. | |
| void | sessionClosed (Session *) |
| Handler for the SessionState notification. | |
Private Types | |
| typedef ObjectDispatcher< PacketBase > | PacketDispatcher |
Private Member Functions | |
| CALITKO_TESTABLE | TransferSessionImpl (const TransferSessionImpl &) |
| TransferSessionImpl & | operator= (const TransferSessionImpl &) |
| void | receivedChoke (const Choke &) |
| Handler for Choke packets - sets our 'choked' status. | |
| void | receivedUnchoke (const Unchoke &) |
| Handler for Unchoke packets - clears our 'choked' status. | |
| void | receivedInterested (const Interested &) |
| Handler for Interested packets - sets peer's 'interested' status. | |
| void | receivedNotInterested (const NotInterested &) |
| Handler for NotInterested packets - clears peer's 'interested' status. | |
| void | receivedPiece (const Piece &) |
| Handler for Piece packets - keeps track of total download volume and speed. | |
| void | receivedBitField (const BitField &) |
| Handler for BitField packet - keeps track of peer's available pieces. | |
| void | receivedHaveAll (const HaveAll &) |
| Handler for HaveAll packet - marks all pieces are available at the peer. | |
| void | receivedHaveNone (const HaveNone &) |
| Handler for HaveNone packet - marks all pieces as not available at the peer. | |
| void | receivedHave (const Have &) |
| Handler for Have packets - marks the corresponding piece as available. | |
| void | receivedUnhandled (const PacketBase &) |
| Handler for an unhandled packet types. | |
| void | sentChoke (const Choke &) |
| Handler for Choke packets - sets the peer's 'choked' status. | |
| void | sentUnchoke (const Unchoke &) |
| Handler for Unchoke packets - clars the peer's 'choked' status. | |
| void | sentInterested (const Interested &) |
| Handler for Interested packets - sets our 'interested' status. | |
| void | sentNotInterested (const NotInterested &) |
| Handler for Interested packets - clears our 'interested' status. | |
| void | sentPiece (const Piece &) |
| Handler for Piece packets - keeps track of total upload volume and speed. | |
| void | sentBitField (const BitField &) |
| Handler for BitField packet - keeps track of our available pieces. | |
| void | sentHaveAll (const HaveAll &) |
| Handler for HaveAll packet - marks all pieces as available at our side. | |
| void | sentHaveNone (const HaveNone &) |
| Handler for HaveNone packet - marks all pieces as not available at our side. | |
| void | sentHave (const Have &) |
| Handler for Have packets - marks the corresponding piece as available. | |
| void | sentUnhandled (const PacketBase &) |
| Handler for unhandled packet types. | |
| void | updateDownloadSpeed (int pieceLength) const |
| Helper to add a number of bytes to the download speed computation window. | |
| void | updateUploadSpeed (int pieceLength) const |
| Helper to add a number of bytes to the upload speed computation window. | |
| void | unregisterBitFieldHaveAllHaveNoneReceiveHandlers () |
| Helper to unregister the handlers for BitField, HaveAll, HaveNone packets. | |
| void | unregisterBitFieldHaveAllHaveNoneSendHandlers () |
| Helper to unregister the handlers for BitField, HaveAll, HaveNone packets. | |
Static Private Member Functions | |
| static void | shiftList (QList< qint64 > &list, qint64 count) |
| Helper that shift a list of integers to the right adding 0s on the left. | |
| static qint64 | calculateAverage (const QList< qint64 > &list) |
| Calculatex the sum of all elements in list and devide by its size. | |
| static void | setPiecesAvailable (QBitArray &piecesAvailable, const QByteArray &bitField) |
| Sets piecesAvailable from the raw bytes in bitField. | |
Private Attributes | |
| Session * | session_ |
| Handshake | handshake_ |
| TransferSessionStatus * | status_ |
| PacketDispatcher | inPacketDispatcher_ |
| PacketDispatcher | outPacketDispatcher_ |
| bool | areWeChoked_ |
| bool | areWeInterested_ |
| bool | areWeSeeder_ |
| bool | isPeerChoked_ |
| bool | isPeerInterested_ |
| bool | isPeerSeeder_ |
| qint64 | totalDownloaded_ |
| qint64 | totalUploaded_ |
| IntegerResetStopwatch * | downloadStopwatch_ |
| IntegerResetStopwatch * | uploadStopwatch_ |
| QList< qint64 > | downloadHistory_ |
| QList< qint64 > | uploadHistory_ |
| QBitArray | peerPiecesAvailable_ |
| QBitArray | wePiecesAvailable_ |
Static Private Attributes | |
| static const int | SpeedMovingAverageDuration = 20 |
| Time window (seconds) used to calculate average upload/download speeds. | |
| static const int | SnubbedTimeout = 20 |
| Time (seconds) no Piece is received to consider the session snubbed. | |
|
|
Definition at line 163 of file TransferSessionImpl.h. |
|
|
|
|
||||||||||||||||||||||||
|
Constructs a TransferSessionImpl object.
Definition at line 39 of file TransferSessionImpl.cpp. |
|
|
Tells whether the remote peer has choked us.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 145 of file TransferSessionImpl.cpp. |
|
|
Tells whether we have registered interest in the other peer's pieces.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 151 of file TransferSessionImpl.cpp. |
|
|
Tells whether are are a seeder (we have reported to have all pieces).
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 164 of file TransferSessionImpl.cpp. |
|
|
Tells whether the remote peer has not uploaded anything to us recently.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 157 of file TransferSessionImpl.cpp. |
|
|
Calculatex the sum of all elements in list and devide by its size.
Definition at line 469 of file TransferSessionImpl.cpp. |
|
|
Closes this session.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 139 of file TransferSessionImpl.cpp. |
|
|
Average download speed (bytes/second) calculated over a sliding time window.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 207 of file TransferSessionImpl.cpp. |
|
|
Average upload speed (bytes/second) calculated over a sliding time window.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 214 of file TransferSessionImpl.cpp. |
|
|
Tells whether we have choked the remote peer.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 170 of file TransferSessionImpl.cpp. |
|
|
Tells whether the remote peer has registered interest in our pieces.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 176 of file TransferSessionImpl.cpp. |
|
|
Tells whether the remote peer has reported is is a seeder (has all pieces).
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 189 of file TransferSessionImpl.cpp. |
|
|
Tells whether we have not uploaded anything to the peer recently.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 182 of file TransferSessionImpl.cpp. |
|
|
|
|
|
Returns a bit array indicating all pieces the remote peer reported to have.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 221 of file TransferSessionImpl.cpp. |
|
|
Handler for BitField packet - keeps track of peer's available pieces.
Definition at line 309 of file TransferSessionImpl.cpp. |
|
|
Handler for Choke packets - sets our 'choked' status.
Definition at line 277 of file TransferSessionImpl.cpp. |
|
|
Handler for Have packets - marks the corresponding piece as available.
Definition at line 332 of file TransferSessionImpl.cpp. |
|
|
Handler for HaveAll packet - marks all pieces are available at the peer.
Definition at line 316 of file TransferSessionImpl.cpp. |
|
|
Handler for HaveNone packet - marks all pieces as not available at the peer.
Definition at line 324 of file TransferSessionImpl.cpp. |
|
|
Handler for Interested packets - sets peer's 'interested' status.
Definition at line 289 of file TransferSessionImpl.cpp. |
|
|
Handler for NotInterested packets - clears peer's 'interested' status.
Definition at line 295 of file TransferSessionImpl.cpp. |
|
|
Handler for Piece packets - keeps track of total download volume and speed.
Definition at line 301 of file TransferSessionImpl.cpp. |
|
|
Handler for Unchoke packets - clears our 'choked' status.
Definition at line 283 of file TransferSessionImpl.cpp. |
|
|
Handler for an unhandled packet types. A packet handler should be installed for each allowed PacketBase derived packet type. If no handler is registered this means that the remote peer is not allowed to send us packets of this type. If the peer does so anyway we should close the session. Definition at line 346 of file TransferSessionImpl.cpp. |
|
|
Queues up and sends packet at first possible occasion.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 131 of file TransferSessionImpl.cpp. |
|
|
Handler for BitField packet - keeps track of our available pieces.
Definition at line 384 of file TransferSessionImpl.cpp. |
|
|
Handler for Choke packets - sets the peer's 'choked' status.
Definition at line 352 of file TransferSessionImpl.cpp. |
|
|
Handler for Have packets - marks the corresponding piece as available.
Definition at line 407 of file TransferSessionImpl.cpp. |
|
|
Handler for HaveAll packet - marks all pieces as available at our side.
Definition at line 391 of file TransferSessionImpl.cpp. |
|
|
Handler for HaveNone packet - marks all pieces as not available at our side.
Definition at line 399 of file TransferSessionImpl.cpp. |
|
|
Handler for Interested packets - sets our 'interested' status.
Definition at line 364 of file TransferSessionImpl.cpp. |
|
|
Handler for Interested packets - clears our 'interested' status.
Definition at line 370 of file TransferSessionImpl.cpp. |
|
|
Handler for Piece packets - keeps track of total upload volume and speed.
Definition at line 376 of file TransferSessionImpl.cpp. |
|
|
Handler for Unchoke packets - clars the peer's 'choked' status.
Definition at line 358 of file TransferSessionImpl.cpp. |
|
|
Handler for unhandled packet types. Control reaches here if a handler for this certain PacketBase derived class is not installed. If no handler is installed this means that sending this type of packets is not allowed. We will assert because this is a programmer error. Definition at line 421 of file TransferSessionImpl.cpp. |
|
|
Handler for the SessionState notification. Forwards the notification over our TransferSessionStatus interface. Definition at line 271 of file TransferSessionImpl.cpp. |
|
|
Handler for the SessionState notification. Forwards the notification over our TransferSessionStatus interface. Definition at line 262 of file TransferSessionImpl.cpp. |
|
||||||||||||
|
Handler for the SessionState notification. Internally dispatches the packet to update the TransferSessionImpl object's internal state. Unless the received message causes the session to be closed, the received data is converted to a Packet and a TransferSessionStatus notification is sent. Definition at line 241 of file TransferSessionImpl.cpp. |
|
||||||||||||
|
Handler for the SessionState notification. Currently ignored. Our corresponding notification transferSessionSendingPacket() is sent from sendPacket(). Definition at line 253 of file TransferSessionImpl.cpp. |
|
||||||||||||
|
Sets piecesAvailable from the raw bytes in bitField.
Definition at line 477 of file TransferSessionImpl.cpp. |
|
||||||||||||
|
Helper that shift a list of integers to the right adding 0s on the left.
Definition at line 459 of file TransferSessionImpl.cpp. |
|
|
The total number of bytes (raw Piece bytes only) downloaded from the peer.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 195 of file TransferSessionImpl.cpp. |
|
|
The total number of bytes (raw Piece bytes only) uploaded to the peer.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 201 of file TransferSessionImpl.cpp. |
|
|
Helper to unregister the handlers for BitField, HaveAll, HaveNone packets. By unregistering these handlers we effectively disable the reception of these packet types. If a peer sends us one of these nevertheless, then we will automatically close the session. These three packet types are exclusive - only one is allowed to be sent and this type should be sent only once right after the session is established.
Definition at line 500 of file TransferSessionImpl.cpp. |
|
|
Helper to unregister the handlers for BitField, HaveAll, HaveNone packets. By unregistering these handlers we effectively disable the sending of these packet types. If we send one of these nevertheless, then we will assert. Definition at line 519 of file TransferSessionImpl.cpp. |
|
|
Helper to add a number of bytes to the download speed computation window. The function checks how much time elapsed since last piece was received. If more than one second elapsed, the window is slided accordingly. The new bytes are counted in any case.
Definition at line 434 of file TransferSessionImpl.cpp. |
|
|
Helper to add a number of bytes to the upload speed computation window. The function checks how much time elapsed since last piece was sent. If more than one second elapsed, the window is slided accordingly. The new bytes are counted in any case.
Definition at line 450 of file TransferSessionImpl.cpp. |
|
|
Returns a bit array indicating all pieces we reported to have.
Implements Protocols::BitTorrent::Transfers::TransferSession. Definition at line 227 of file TransferSessionImpl.cpp. |
|
|
Definition at line 176 of file TransferSessionImpl.h. |
|
|
Definition at line 177 of file TransferSessionImpl.h. |
|
|
Definition at line 178 of file TransferSessionImpl.h. |
|
|
Definition at line 187 of file TransferSessionImpl.h. |
|
|
Definition at line 185 of file TransferSessionImpl.h. |
|
|
Definition at line 171 of file TransferSessionImpl.h. |
|
|
Definition at line 173 of file TransferSessionImpl.h. |
|
|
Definition at line 179 of file TransferSessionImpl.h. |
|
|
Definition at line 180 of file TransferSessionImpl.h. |
|
|
Definition at line 181 of file TransferSessionImpl.h. |
|
|
Definition at line 174 of file TransferSessionImpl.h. |
|
|
Definition at line 190 of file TransferSessionImpl.h. |
|
|
Definition at line 170 of file TransferSessionImpl.h. |
|
|
Time (seconds) no Piece is received to consider the session snubbed.
Definition at line 168 of file TransferSessionImpl.h. |
|
|
Time window (seconds) used to calculate average upload/download speeds.
Definition at line 166 of file TransferSessionImpl.h. |
|
|
Definition at line 172 of file TransferSessionImpl.h. |
|
|
Definition at line 183 of file TransferSessionImpl.h. |
|
|
Definition at line 184 of file TransferSessionImpl.h. |
|
|
Definition at line 188 of file TransferSessionImpl.h. |
|
|
Definition at line 186 of file TransferSessionImpl.h. |
|
|
Definition at line 191 of file TransferSessionImpl.h. |