Skip to content

Commit 79976fb

Browse files
committed
Implement new GeoIPManager class.
1 parent c702a7e commit 79976fb

28 files changed

Lines changed: 1228 additions & 401 deletions

configure

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ enable_dependency_tracking
716716
enable_silent_rules
717717
with_qt5
718718
with_libtorrent_rasterbar0_16
719-
with_geoip_database_embedded
720719
with_qtsingleapplication
721720
with_qjson
722721
enable_debug
@@ -1387,10 +1386,6 @@ Optional Packages:
13871386
--with-libtorrent-rasterbar0.16
13881387
Compile using libtorrent-rasterbar 0.16.x series
13891388
(default=no)
1390-
--with-geoip-database-embedded
1391-
Embed the GeoIP database in the qBittorrent
1392-
executable (please follow instructions in
1393-
src/gui/geoip/README) (default=no)
13941389
--with-qtsingleapplication=[system|shipped]
13951390
Use the shipped qtsingleapplication library or the
13961391
system one (default=shipped)
@@ -4194,15 +4189,6 @@ fi
41944189

41954190

41964191

4197-
# Check whether --with-geoip-database-embedded was given.
4198-
if test "${with_geoip_database_embedded+set}" = set; then :
4199-
withval=$with_geoip_database_embedded;
4200-
else
4201-
with_geoip_database_embedded=no
4202-
fi
4203-
4204-
4205-
42064192
# Check whether --with-qtsingleapplication was given.
42074193
if test "${with_qtsingleapplication+set}" = set; then :
42084194
withval=$with_qtsingleapplication;
@@ -4429,7 +4415,6 @@ $as_echo "yes" >&6; }
44294415
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
44304416
$as_echo "no" >&6; }
44314417
enable_qt_dbus=no
4432-
enable_geoip_database=no
44334418
QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui" ;; #(
44344419
*) :
44354420
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_gui" >&5
@@ -5493,23 +5478,6 @@ $as_echo "$with_libtorrent_rasterbar0_16" >&6; }
54935478
as_fn_error $? "Unknown option \"$with_libtorrent_rasterbar0_16\". Use either \"yes\" or \"no\"." "$LINENO" 5 ;;
54945479
esac
54955480

5496-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to embed the GeoIP database" >&5
5497-
$as_echo_n "checking whether to embed the GeoIP database... " >&6; }
5498-
case "x$with_geoip_database_embedded" in #(
5499-
"xno") :
5500-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5501-
$as_echo "no" >&6; }
5502-
QBT_REMOVE_DEFINES="$QBT_REMOVE_DEFINES WITH_GEOIP_EMBEDDED" ;; #(
5503-
"xyes") :
5504-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
5505-
$as_echo "yes" >&6; }
5506-
QBT_ADD_DEFINES="$QBT_ADD_DEFINES WITH_GEOIP_EMBEDDED" ;; #(
5507-
*) :
5508-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_geoip_database_embedded" >&5
5509-
$as_echo "$with_geoip_database_embedded" >&6; }
5510-
as_fn_error $? "Unknown option \"$with_geoip_database_embedded\". Use either \"yes\" or \"no\"." "$LINENO" 5 ;;
5511-
esac
5512-
55135481
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking which qtsingleapplication to use" >&5
55145482
$as_echo_n "checking which qtsingleapplication to use... " >&6; }
55155483
case "x$with_qtsingleapplication" in #(

configure.ac

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ AC_ARG_WITH(libtorrent-rasterbar0.16,
2424
[],
2525
[with_libtorrent_rasterbar0_16=no])
2626

27-
AC_ARG_WITH(geoip-database-embedded,
28-
[AS_HELP_STRING([--with-geoip-database-embedded],
29-
[Embed the GeoIP database in the qBittorrent executable (please follow instructions in src/gui/geoip/README) (default=no)])],
30-
[],
31-
[with_geoip_database_embedded=no])
32-
3327
AC_ARG_WITH(qtsingleapplication,
3428
[AS_HELP_STRING([--with-qtsingleapplication=@<:@system|shipped@:>@],
3529
[Use the shipped qtsingleapplication library or the system one (default=shipped)])],
@@ -198,17 +192,6 @@ AS_CASE(["x$with_libtorrent_rasterbar0_16"],
198192
[AC_MSG_RESULT([$with_libtorrent_rasterbar0_16])
199193
AC_MSG_ERROR([Unknown option "$with_libtorrent_rasterbar0_16". Use either "yes" or "no".])])
200194

201-
AC_MSG_CHECKING([whether to embed the GeoIP database])
202-
AS_CASE(["x$with_geoip_database_embedded"],
203-
["xno"],
204-
[AC_MSG_RESULT([no])
205-
QBT_REMOVE_DEFINES="$QBT_REMOVE_DEFINES WITH_GEOIP_EMBEDDED"],
206-
["xyes"],
207-
[AC_MSG_RESULT([yes])
208-
QBT_ADD_DEFINES="$QBT_ADD_DEFINES WITH_GEOIP_EMBEDDED"],
209-
[AC_MSG_RESULT([$with_geoip_database_embedded])
210-
AC_MSG_ERROR([Unknown option "$with_geoip_database_embedded". Use either "yes" or "no".])])
211-
212195
AC_MSG_CHECKING([which qtsingleapplication to use])
213196
AS_CASE(["x$with_qtsingleapplication"],
214197
["xshipped"],

macxconf.pri

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,3 @@ QMAKE_BUNDLE_DATA += qt_translations
5656

5757
ICON = $$DIST_PATH/qbittorrent_mac.icns
5858
QMAKE_INFO_PLIST = $$DIST_PATH/Info.plist
59-
60-
DEFINES += WITH_GEOIP_EMBEDDED
61-
message("On Mac OS X, GeoIP database must be embedded.")

os2conf.pri

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,4 @@ LIBS += \
1313
RC_FILE = qbittorrent_os2.rc
1414

1515
# LIBTORRENT DEFINES
16-
DEFINES += WITH_SHIPPED_GEOIP_H
1716
DEFINES += BOOST_ASIO_DYN_LINK
18-
19-
DEFINES += WITH_GEOIP_EMBEDDED
20-
message("On eCS(OS/2), GeoIP database must be embedded.")

src/app/application.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "core/scanfoldersmodel.h"
6666
#include "core/net/smtp.h"
6767
#include "core/net/downloadmanager.h"
68+
#include "core/net/geoipmanager.h"
6869
#include "core/bittorrent/session.h"
6970
#include "core/bittorrent/torrenthandle.h"
7071

@@ -232,10 +233,14 @@ int Application::exec(const QStringList &params)
232233
#else
233234
GuiIconProvider::initInstance();
234235
#endif
236+
235237
BitTorrent::Session::initInstance();
236238
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(torrentFinished(BitTorrent::TorrentHandle *const)));
237239
connect(BitTorrent::Session::instance(), SIGNAL(allTorrentsFinished()), SLOT(allTorrentsFinished()));
238240

241+
#ifndef DISABLE_COUNTRIES_RESOLUTION
242+
Net::GeoIPManager::initInstance();
243+
#endif
239244
ScanFoldersModel::initInstance(this);
240245

241246
#ifndef DISABLE_WEBUI
@@ -446,6 +451,9 @@ void Application::cleanup()
446451

447452
ScanFoldersModel::freeInstance();
448453
BitTorrent::Session::freeInstance();
454+
#ifndef DISABLE_COUNTRIES_RESOLUTION
455+
Net::GeoIPManager::freeInstance();
456+
#endif
449457
Preferences::freeInstance();
450458
Logger::freeInstance();
451459
IconProvider::freeInstance();

src/core/bittorrent/peerinfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <libtorrent/version.hpp>
3030

31+
#include "core/net/geoipmanager.h"
3132
#include "core/utils/string.h"
3233
#include "peerinfo.h"
3334

@@ -69,11 +70,12 @@ bool PeerInfo::fromLSD() const
6970
return (m_nativeInfo.source & libt::peer_info::lsd);
7071
}
7172

73+
#ifndef DISABLE_COUNTRIES_RESOLUTION
7274
QString PeerInfo::country() const
7375
{
74-
return QString(QByteArray(m_nativeInfo.country, 2));
76+
return Net::GeoIPManager::instance()->lookup(address().ip);
7577
}
76-
78+
#endif
7779

7880
bool PeerInfo::isInteresting() const
7981
{

src/core/bittorrent/peerinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ namespace BitTorrent
8989
qlonglong totalDownload() const;
9090
QBitArray pieces() const;
9191
QString connectionType() const;
92+
#ifndef DISABLE_COUNTRIES_RESOLUTION
9293
QString country() const;
94+
#endif
9395

9496
private:
9597
libtorrent::peer_info m_nativeInfo;

src/core/bittorrent/private/sessionprivate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ struct SessionPrivate
5050
virtual bool isTempPathEnabled() const = 0;
5151
virtual bool isAppendExtensionEnabled() const = 0;
5252
virtual bool useAppendLabelToSavePath() const = 0;
53-
#ifndef DISABLE_COUNTRIES_RESOLUTION
54-
virtual bool isResolveCountriesEnabled() const = 0;
55-
#endif
5653
virtual QString defaultSavePath() const = 0;
5754
virtual QString tempPath() const = 0;
5855
virtual qreal globalMaxRatio() const = 0;

src/core/bittorrent/private/torrenthandleprivate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ struct TorrentHandlePrivate
4242
virtual void handleDefaultSavePathChanged() = 0;
4343
virtual void handleTempPathChanged() = 0;
4444
virtual void handleAppendExtensionToggled() = 0;
45-
#ifndef DISABLE_COUNTRIES_RESOLUTION
46-
virtual void handleResolveCountriesToggled() = 0;
47-
#endif
4845

4946
protected:
5047
~TorrentHandlePrivate() {}

src/core/bittorrent/session.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ using namespace BitTorrent;
6363
//#include <libtorrent/extensions/metadata_transfer.hpp>
6464

6565
#ifndef DISABLE_COUNTRIES_RESOLUTION
66-
#include "geoipmanager.h"
66+
#include "core/net/geoipmanager.h"
6767
#endif
6868

6969
#include "core/utils/misc.h"
@@ -141,10 +141,6 @@ Session::Session(QObject *parent)
141141
, m_globalMaxRatio(-1)
142142
, m_numResumeData(0)
143143
, m_extraLimit(0)
144-
#ifndef DISABLE_COUNTRIES_RESOLUTION
145-
, m_geoipDBLoaded(false)
146-
, m_resolveCountries(false)
147-
#endif
148144
, m_appendLabelToSavePath(false)
149145
, m_appendExtension(false)
150146
, m_refreshInterval(0)
@@ -252,13 +248,6 @@ bool Session::useAppendLabelToSavePath() const
252248
return m_appendLabelToSavePath;
253249
}
254250

255-
#ifndef DISABLE_COUNTRIES_RESOLUTION
256-
bool Session::isResolveCountriesEnabled() const
257-
{
258-
return m_resolveCountries;
259-
}
260-
#endif
261-
262251
QString Session::defaultSavePath() const
263252
{
264253
return m_defaultSavePath;
@@ -577,25 +566,6 @@ void Session::configure()
577566
delete m_bwScheduler;
578567
}
579568

580-
#ifndef DISABLE_COUNTRIES_RESOLUTION
581-
// Resolve countries
582-
qDebug("Loading country resolution settings");
583-
const bool new_resolv_countries = pref->resolvePeerCountries();
584-
if (m_resolveCountries != new_resolv_countries) {
585-
qDebug("in country resolution settings");
586-
m_resolveCountries = new_resolv_countries;
587-
if (m_resolveCountries && !m_geoipDBLoaded) {
588-
qDebug("Loading geoip database");
589-
GeoIPManager::loadDatabase(m_nativeSession);
590-
m_geoipDBLoaded = true;
591-
}
592-
593-
// Update torrent handles
594-
foreach (TorrentHandlePrivate *const torrent, m_torrents)
595-
torrent->handleResolveCountriesToggled();
596-
}
597-
#endif
598-
599569
Logger* const logger = Logger::instance();
600570

601571
// * Session settings

0 commit comments

Comments
 (0)