Protocols::BitTorrent::Trackers::SingleTrackerRequestSession Class Reference

#include <SingleTrackerRequestSession.h> [code]

Inherits Protocols::BitTorrent::Trackers::TrackerRequestSession.

Inheritance diagram for Protocols::BitTorrent::Trackers::SingleTrackerRequestSession:

Inheritance graph
[legend]
Collaboration diagram for Protocols::BitTorrent::Trackers::SingleTrackerRequestSession:

Collaboration graph
[legend]
List of all members.

Detailed Description

Sends requests and recieve responses from a single tracker.

This class is used to send tracker requests using HTTP request session to the (single) tracker specified in the ctor. After the request is sent and the HTTP response recieved, this class will handle the HTTP response header, parse the raw response body and make the parsed tracker response available to get.

Definition at line 43 of file SingleTrackerRequestSession.h.

Public Member Functions

 SingleTrackerRequestSession (HttpRequestSession *, Uri, TrackerRequestSessionStatus *)
 Constructor.
 ~SingleTrackerRequestSession ()
 Destructor.
void open ()
 Establishes the HttpRequestSession.
void sendRequest (const TrackerRequest &)
 Sends a tracker request to the tracker.
void close ()
 Closes the session by closing the HttpRequestSession.
void abort ()
 Aborts the session by aborting the HttpRequestSession.
void httpRequestSessionEstablished ()
 HttpRequestSession was established.
void httpRequestSessionError (const QString &)
 There was an error in the HttpRequestSession.
void httpRequestSessionResponseHeaderRecieved (const ResponseHeader &)
 Handles HTTP response header.
void httpRequestSessionResponseBodyRecieved (const QByteArray &)
 Handles HTTP response body.
void httpRequestSessionClosing ()
 HttpRequest started closing.
void httpRequestSessionClosed ()
 HttpRequestSession was closed.

Private Types

enum  State {
  Established,
  RequestSent,
  ResponseHeaderRecieved,
  Closing,
  Closed
}
 States. More...

Private Member Functions

CALITKO_TESTABLE SingleTrackerRequestSession (const SingleTrackerRequestSession &)
SingleTrackerRequestSessionoperator= (const SingleTrackerRequestSession &)

Static Private Member Functions

static bool httpRequestSucceeded (const ResponseHeader &)
static QString createHttpRequestSessionErrorMessage (const QString &)
 Creates and returns created error message from the original errorMessage.
static QString createHttpErrorMessage (const ResponseHeader &)
 Creates and returns created HTTP error message from the responseHeader.
static QString createTrackerErrorMessage (const QString &)
 Creates and returns created tracker error message from the failureReason.

Private Attributes

HttpRequestSessionhttpRequestSession_
const Uri announceUrl_
TrackerRequestSessionStatusstatus_
State state_

Static Private Attributes

static const int FirstSuccessfulHttpStatusCode = 200
static const int FirstHttpStatusCodePastSuccessfulCodes = 300


Member Enumeration Documentation

enum Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::State [private]
 

States.

Enumerator:
Established 
RequestSent 
ResponseHeaderRecieved 
Closing 
Closed 

Definition at line 69 of file SingleTrackerRequestSession.h.


Constructor & Destructor Documentation

CALITKO_TESTABLE Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::SingleTrackerRequestSession const SingleTrackerRequestSession  )  [private]
 

SingleTrackerRequestSession::SingleTrackerRequestSession HttpRequestSession httpRequestSession,
Uri  announceUrl,
TrackerRequestSessionStatus trackerRequestSessionStatus
 

Constructor.

Parameters:
httpRequestSession HTTP request session to be used for tracker communication.
announceUrl Announce URL of the tracker.
trackerRequestSessionStatus Tracker request session notifications listener.
Precondition:
httpRequestSession must NOT be already connected.
Constructs a SingleTrackerRequestSession object. No status notifications are sent.

Definition at line 42 of file SingleTrackerRequestSession.cpp.

SingleTrackerRequestSession::~SingleTrackerRequestSession  ) 
 

Destructor.

Destroys a session. No status notifications are sent.

Definition at line 57 of file SingleTrackerRequestSession.cpp.


Member Function Documentation

void SingleTrackerRequestSession::abort  )  [virtual]
 

Aborts the session by aborting the HttpRequestSession.

The HttpRequestSession will be aborted and then the session will be closed ( trackerRequestSessionClosed() notification will be sent). If the session has been already closed, nothing happens.

Implements Protocols::BitTorrent::Trackers::TrackerRequestSession.

Definition at line 119 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::close  )  [virtual]
 

Closes the session by closing the HttpRequestSession.

The HttpRequestSession will be closed (the trackerRequestSessionClosing() notification will be sent before that happens). It enters the Closing state

  • nothing could be sent or handled after then. If the session has been already closed (or it's closing), nothing happens.

See also:
httpRequestSessionClosed()

Implements Protocols::BitTorrent::Trackers::TrackerRequestSession.

Definition at line 104 of file SingleTrackerRequestSession.cpp.

QString SingleTrackerRequestSession::createHttpErrorMessage const ResponseHeader responseHeader  )  [static, private]
 

Creates and returns created HTTP error message from the responseHeader.

Parameters:
responseHeader HTTP response header.
Returns:
Error message according to the responseHeader.

Definition at line 271 of file SingleTrackerRequestSession.cpp.

QString SingleTrackerRequestSession::createHttpRequestSessionErrorMessage const QString &  errorMessage  )  [static, private]
 

Creates and returns created error message from the original errorMessage.

Parameters:
errorMessage HttpRequestSession failure reason.
Returns:
Error message according to the original errorMessage.

Definition at line 260 of file SingleTrackerRequestSession.cpp.

QString SingleTrackerRequestSession::createTrackerErrorMessage const QString &  failureReason  )  [static, private]
 

Creates and returns created tracker error message from the failureReason.

Parameters:
failureReason Failure reason from the tracker response.
Returns:
Error message according to the failureReason.

Definition at line 283 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionClosed  ) 
 

HttpRequestSession was closed.

Session gets closed - it enters the Closed state (nothing could be sent or handled after then) and trackerRequestSessionClosed() notification will be sent).

Definition at line 238 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionClosing  ) 
 

HttpRequest started closing.

Session enters the Closing state (nothing could be sent or handled after then). No status notifications are sent.

Definition at line 225 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionError const QString &  errorMessage  ) 
 

There was an error in the HttpRequestSession.

Parameters:
errorMessage Error message containing the failure reason.
trackerRequestSessionError() notification will be sent with error message in the following format: HTTP request session error: error reason phrase

Definition at line 149 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionEstablished  ) 
 

HttpRequestSession was established.

Session gets established (trackerRequestSessionEstablished() notification will be sent).

Definition at line 133 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionResponseBodyRecieved const QByteArray &  rawResponseBody  ) 
 

Handles HTTP response body.

Parameters:
rawResponseBody Body part of the HTTP response.
Precondition:
Response header from the tracker must have been already handled.
If the rawResponseBody was handled successfully, trackerRequestSessionResponseRecieved() notification will be sent. Otherwise, trackerRequestSessionResponseRecievedError() will be sent with error message in the following format: Tracker error: Failure reason

See also:
httpRequestSessionResponseHeaderRecieved()

Definition at line 198 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::httpRequestSessionResponseHeaderRecieved const ResponseHeader responseHeader  ) 
 

Handles HTTP response header.

Parameters:
responseHeader Header part of the HTTP response.
Precondition:
Request to the tracker must have been sent already.
If the HTTP request was NOT successful (the responseHeader status code is different than 2xx), trackerRequestSessionError() notification will be sent with error message in the following format: HTTP error: Status code and the error reason phrase

See also:
httpRequestSessionResponseBodyRecieved()

Definition at line 169 of file SingleTrackerRequestSession.cpp.

bool SingleTrackerRequestSession::httpRequestSucceeded const ResponseHeader responseHeader  )  [static, private]
 

Note:
Successfull HTTP status codes are 2xx.

Definition at line 248 of file SingleTrackerRequestSession.cpp.

void SingleTrackerRequestSession::open  )  [virtual]
 

Establishes the HttpRequestSession.

HttpRequestSession must be established as first in order to send requests to the tracker. No status notifications are sent.

See also:
httpRequestSessionEstablished()

Implements Protocols::BitTorrent::Trackers::TrackerRequestSession.

Definition at line 68 of file SingleTrackerRequestSession.cpp.

SingleTrackerRequestSession& Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::operator= const SingleTrackerRequestSession  )  [private]
 

void SingleTrackerRequestSession::sendRequest const TrackerRequest trackerRequest  )  [virtual]
 

Sends a tracker request to the tracker.

Parameters:
trackerRequest Tracker request to be sent.
Precondition:
Session must have been established.
No status notifications are sent.

See also:
httpRequestSessionResponseHeaderRecieved()

Implements Protocols::BitTorrent::Trackers::TrackerRequestSession.

Definition at line 85 of file SingleTrackerRequestSession.cpp.


Member Data Documentation

const Uri Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::announceUrl_ [private]
 

Definition at line 89 of file SingleTrackerRequestSession.h.

const int SingleTrackerRequestSession::FirstHttpStatusCodePastSuccessfulCodes = 300 [static, private]
 

Definition at line 85 of file SingleTrackerRequestSession.h.

const int SingleTrackerRequestSession::FirstSuccessfulHttpStatusCode = 200 [static, private]
 

Definition at line 84 of file SingleTrackerRequestSession.h.

HttpRequestSession* Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::httpRequestSession_ [private]
 

Definition at line 88 of file SingleTrackerRequestSession.h.

State Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::state_ [private]
 

Definition at line 91 of file SingleTrackerRequestSession.h.

TrackerRequestSessionStatus* Protocols::BitTorrent::Trackers::SingleTrackerRequestSession::status_ [private]
 

Definition at line 90 of file SingleTrackerRequestSession.h.


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