#include <GeoIpResolver.h>
Signals | |
void | resolved (int id, const QList< GeoIp > &geoips) |
void | resolveFailed (int id, const QString &errorString) |
Public Member Functions | |
GeoIpResolver (QObject *parent=0) | |
void | setSocksHost (const QHostAddress &addr, quint16 port) |
int | resolve (const QHostAddress &ip) |
int | resolve (const QList< QHostAddress > &ips) |
bool | resolveFromCache (const QHostAddress &ip) |
QList< QHostAddress > | resolveFromCache (const QList< QHostAddress > &ips) |
Private Slots | |
void | connected () |
void | disconnected () |
void | socketError (const QString &errorString) |
Private Member Functions | |
GeoIpRequest * | createRequest (const QList< QHostAddress > &ips) |
void | parseGeoIpResponse (const QByteArray &response, GeoIpRequest *request) |
Private Attributes | |
GeoIpCache * | _cache |
QHash< QAbstractSocket *, GeoIpRequest * > | _requestList |
QHostAddress | _socksAddr |
quint16 | _socksPort |
Definition at line 34 of file GeoIpResolver.h.
GeoIpResolver::GeoIpResolver | ( | QObject * | parent = 0 |
) |
Default constructor.
Definition at line 35 of file GeoIpResolver.cpp.
References _cache, _socksAddr, and _socksPort.
void GeoIpResolver::connected | ( | ) | [private, slot] |
Called when the socket has connected to the Geo IP host.
Definition at line 95 of file GeoIpResolver.cpp.
References _requestList, GeoIpRequest::id(), GeoIpRequest::request(), GeoIpRequest::size(), and vInfo.
Referenced by resolve().
GeoIpRequest * GeoIpResolver::createRequest | ( | const QList< QHostAddress > & | ips | ) | [private] |
Creates an HTTP request for Geo IP information.
Definition at line 244 of file GeoIpResolver.cpp.
References GEOIP_HOST, GEOIP_PAGE, GeoIpRequest::setHost(), GeoIpRequest::setPage(), and GeoIpRequest::setRequest().
Referenced by resolve().
void GeoIpResolver::disconnected | ( | ) | [private, slot] |
Called when the socket has disconnected from the Geo IP host.
Definition at line 113 of file GeoIpResolver.cpp.
References _requestList, GeoIpResponse::content(), GeoIpRequest::id(), parseGeoIpResponse(), resolveFailed(), GeoIpResponse::statusCode(), GeoIpResponse::statusMessage(), and vWarn.
Referenced by resolve().
void GeoIpResolver::parseGeoIpResponse | ( | const QByteArray & | response, | |
GeoIpRequest * | request | |||
) | [private] |
Cached GeoIp objects.
Definition at line 144 of file GeoIpResolver.cpp.
References _cache, GeoIpCache::addToCache(), GeoIpCache::contains(), GeoIpRequest::contains(), err(), GeoIpRequest::id(), GeoIp::isValid(), resolved(), GeoIpCache::saveToDisk(), string_parse_keyvals(), vInfo, and vWarn.
Referenced by disconnected().
int GeoIpResolver::resolve | ( | const QList< QHostAddress > & | ips | ) |
Resolves a list of IPs to a geographic location.
Definition at line 256 of file GeoIpResolver.cpp.
References _requestList, _socksAddr, _socksPort, connected(), TorSslSocket::connectToRemoteHost(), createRequest(), disconnected(), GEOIP_HOST, GEOIP_SSL_PORT, GeoIpRequest::id(), resolveFromCache(), socketError(), and vInfo.
int GeoIpResolver::resolve | ( | const QHostAddress & | ip | ) |
Resolves a single IP to a geographic location.
Definition at line 88 of file GeoIpResolver.cpp.
Referenced by NetViewer::resolve().
void GeoIpResolver::resolved | ( | int | id, | |
const QList< GeoIp > & | geoips | |||
) | [signal] |
Emitted when a list of IPs have been resolved to lat/long.
Referenced by parseGeoIpResponse(), and resolveFromCache().
void GeoIpResolver::resolveFailed | ( | int | id, | |
const QString & | errorString | |||
) | [signal] |
Emitted when a resolve has failed.
Referenced by disconnected(), and socketError().
QList< QHostAddress > GeoIpResolver::resolveFromCache | ( | const QList< QHostAddress > & | ips | ) |
Resolves a list of IPs to a geographic location, but only those which are cached. Returns a list of which IPs were not cached.
Resolves a list of IPs to a geographic location, but only those which are cached. Returns a list of IPs that were not in the cache.
Definition at line 68 of file GeoIpResolver.cpp.
References _cache, GeoIpCache::contains(), GeoIpCache::geoIpForAddress(), resolved(), and vInfo.
bool GeoIpResolver::resolveFromCache | ( | const QHostAddress & | ip | ) |
Resolves ip to geographic information only if it is cached.
Resolves ip to geographic information if it is cached. A resolved() signal will be emitted and true returned if we have cached geographic information for ip. Otherwise, this returns false.
Definition at line 56 of file GeoIpResolver.cpp.
References _cache, GeoIpCache::contains(), GeoIpCache::geoIpForAddress(), and resolved().
Referenced by NetViewer::addToResolveQueue(), and resolve().
void GeoIpResolver::setSocksHost | ( | const QHostAddress & | addr, | |
quint16 | port | |||
) |
Sets the address and port of Tor, through which GeoIP requests will be made.
Definition at line 46 of file GeoIpResolver.cpp.
References _socksAddr, and _socksPort.
Referenced by NetViewer::onAuthenticated().
void GeoIpResolver::socketError | ( | const QString & | errorString | ) | [private, slot] |
Called when an error has occurred getting the Geo IP information.
Called when an error has occurred requesting Geo IP information.
Definition at line 220 of file GeoIpResolver.cpp.
References _requestList, GeoIpRequest::id(), resolveFailed(), and vWarn.
Referenced by resolve().
GeoIpCache* GeoIpResolver::_cache [private] |
List of sockets used for requests.
Definition at line 77 of file GeoIpResolver.h.
Referenced by GeoIpResolver(), parseGeoIpResponse(), and resolveFromCache().
QHash<QAbstractSocket *,GeoIpRequest*> GeoIpResolver::_requestList [private] |
Definition at line 78 of file GeoIpResolver.h.
Referenced by connected(), disconnected(), resolve(), and socketError().
QHostAddress GeoIpResolver::_socksAddr [private] |
Tor's SocksListenAddress.
Definition at line 80 of file GeoIpResolver.h.
Referenced by GeoIpResolver(), resolve(), and setSocksHost().
quint16 GeoIpResolver::_socksPort [private] |
Tor's SocksPort.
Definition at line 82 of file GeoIpResolver.h.
Referenced by GeoIpResolver(), resolve(), and setSocksHost().