#include <BridgeDownloader.h>
Public Types | |
enum | BridgeDownloadMethod { DownloadMethodHttps } |
Public Slots | |
void | cancelBridgeRequest () |
Signals | |
void | downloadProgress (int done, int total) |
void | statusChanged (const QString &status) |
void | bridgeRequestFinished (const QStringList &bridges) |
void | bridgeRequestFailed (const QString &error) |
Public Member Functions | |
BridgeDownloader (QObject *parent=0) | |
bool | downloadBridges (BridgeDownloadMethod method) |
void | setProxy (const QString &host, int port, const QString &username=QString(), const QString &password=QString()) |
Static Public Member Functions | |
static bool | isMethodSupported (BridgeDownloadMethod method) |
Private Slots | |
void | httpsStateChanged (int state) |
void | httpsRequestFinished (int id, bool error) |
void | sslErrors (const QList< QSslError > &sslErrors) |
Private Member Functions | |
void | startHttpsDownload () |
Private Attributes | |
QHttp * | _https |
int | _requestId |
Definition at line 25 of file BridgeDownloader.h.
Available bridge download methods.
Definition at line 31 of file BridgeDownloader.h.
BridgeDownloader::BridgeDownloader | ( | QObject * | parent = 0 |
) |
Default constructor.
Definition at line 26 of file BridgeDownloader.cpp.
References _https, BRIDGEDB_HOST, BRIDGEDB_PORT, downloadProgress(), httpsRequestFinished(), httpsStateChanged(), and sslErrors().
void BridgeDownloader::bridgeRequestFailed | ( | const QString & | error | ) | [signal] |
Emitted when the previous request for bridge addresses fails. The QString error is a human-readable string describing the error encountered.
Referenced by httpsRequestFinished().
void BridgeDownloader::bridgeRequestFinished | ( | const QStringList & | bridges | ) | [signal] |
Emitted when the previous request for bridge addresses completes successfully. The QStringList bridges contains a (possibly empty) list of bridge addresses parsed from the received response.
Referenced by httpsRequestFinished().
void BridgeDownloader::cancelBridgeRequest | ( | ) | [slot] |
Cancels any pending bridge download requests.
Definition at line 93 of file BridgeDownloader.cpp.
References _https.
Referenced by NetworkPage::findBridges().
bool BridgeDownloader::downloadBridges | ( | BridgeDownloadMethod | method | ) |
Initiates a request for a set of bridges using the specified download method. Returns true if the request was initiated successfully, or false on error.
Definition at line 51 of file BridgeDownloader.cpp.
References DownloadMethodHttps, isMethodSupported(), and startHttpsDownload().
Referenced by NetworkPage::startBridgeRequest().
void BridgeDownloader::downloadProgress | ( | int | done, | |
int | total | |||
) | [signal] |
Emitted when the underlying QHttp object reads data from an HTTPS response. done indicates how many bytes out of total have been read so far. Note that total may be 0 if the expected total size of the response is not known.
Referenced by BridgeDownloader(), and startHttpsDownload().
void BridgeDownloader::httpsRequestFinished | ( | int | id, | |
bool | error | |||
) | [private, slot] |
Called when the underlying QHttp object used to make the bridge request completes. error is set to false if the request was successful, or true if the request failed. If id does not match the request ID previously returned by QHttp::get(), then the signal is ignored since it is the result of a close() or abort() request.
Definition at line 121 of file BridgeDownloader.cpp.
References _https, _requestId, bridgeRequestFailed(), bridgeRequestFinished(), vInfo, and vWarn.
Referenced by BridgeDownloader().
void BridgeDownloader::httpsStateChanged | ( | int | state | ) | [private, slot] |
Called when the state of the underlying QHttp object changes. A statusChanged() signal is emitted with the appropriate text describing the new state of the request.
Definition at line 99 of file BridgeDownloader.cpp.
References BRIDGEDB_HOST, BRIDGEDB_PORT, and statusChanged().
Referenced by BridgeDownloader().
bool BridgeDownloader::isMethodSupported | ( | BridgeDownloadMethod | method | ) | [static] |
Returns true if method is supported by the currently available Qt libraries.
Definition at line 68 of file BridgeDownloader.cpp.
References DownloadMethodHttps.
Referenced by downloadBridges(), and NetworkPage::NetworkPage().
void BridgeDownloader::setProxy | ( | const QString & | host, | |
int | port, | |||
const QString & | username = QString() , |
|||
const QString & | password = QString() | |||
) |
Enables HTTPS proxy support, using the proxy server host on port port. A username and password can also optionally be supplied, if required by the proxy.
Definition at line 44 of file BridgeDownloader.cpp.
References _https.
Referenced by NetworkPage::startBridgeRequest().
void BridgeDownloader::sslErrors | ( | const QList< QSslError > & | sslErrors | ) | [private, slot] |
Called when the HTTPS connection encounters one or more sslErrors. Currently the errors are just logged and bridgeRequestFailed() is not emitted, since QHttp will also emit
Definition at line 148 of file BridgeDownloader.cpp.
References _requestId, and vWarn.
Referenced by BridgeDownloader().
void BridgeDownloader::startHttpsDownload | ( | ) | [private] |
Initiates an HTTPS connection to bridges.torproject.org to start downloading a set of bridges.
Definition at line 81 of file BridgeDownloader.cpp.
References _https, _requestId, BRIDGEDB_HOST, BRIDGEDB_PORT, downloadProgress(), statusChanged(), and vInfo.
Referenced by downloadBridges().
void BridgeDownloader::statusChanged | ( | const QString & | status | ) | [signal] |
Emitted when the status of the bridge request changes. status describes the new current state of the request.
Referenced by httpsStateChanged(), and startHttpsDownload().
QHttp* BridgeDownloader::_https [private] |
Used to connect to the bridge database, send an HTTPS request for new bridge addresses and then read the response.
Definition at line 119 of file BridgeDownloader.h.
Referenced by BridgeDownloader(), cancelBridgeRequest(), httpsRequestFinished(), setProxy(), and startHttpsDownload().
int BridgeDownloader::_requestId [private] |
Unique numeric identifier of the current bridge request.
Definition at line 122 of file BridgeDownloader.h.
Referenced by httpsRequestFinished(), sslErrors(), and startHttpsDownload().