From 6347700ee37989c9cf126864c490314978a4a597 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Tue, 4 Nov 2014 13:00:42 +0300 Subject: [PATCH] Move libtorrent includes to .cpp This commit probably fixes #2119. The only important change in this commit is moving session::get_ip_filter() from FilterParserThread::processFilterFile() to FilterParserThread::run(). Previously we called it in main thread, but now we calls it in worker thread. I don't now what libtorrent contract about threads, but I assume that if it is ok to set_ip_filter from other thread, it is ok to get it. --- src/qtlibtorrent/filterparserthread.cpp | 21 +++++++++++++-------- src/qtlibtorrent/filterparserthread.h | 15 +++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/qtlibtorrent/filterparserthread.cpp b/src/qtlibtorrent/filterparserthread.cpp index 84b9f3c3d..ea9a8dc6d 100644 --- a/src/qtlibtorrent/filterparserthread.cpp +++ b/src/qtlibtorrent/filterparserthread.cpp @@ -30,6 +30,12 @@ #include "filterparserthread.h" +#include +#include + +#include +#include + FilterParserThread::FilterParserThread(QObject* parent, libtorrent::session *s) : QThread(parent), s(s), abort(false) { } @@ -40,7 +46,7 @@ FilterParserThread::~FilterParserThread() { } // Parser for eMule ip filter in DAT format -int FilterParserThread::parseDATFilterFile(QString filePath) { +int FilterParserThread::parseDATFilterFile(QString filePath, libtorrent::ip_filter& filter) { int ruleCount = 0; QFile file(filePath); if (file.exists()) { @@ -126,7 +132,7 @@ int FilterParserThread::parseDATFilterFile(QString filePath) { } // Parser for PeerGuardian ip filter in p2p format -int FilterParserThread::parseP2PFilterFile(QString filePath) { +int FilterParserThread::parseP2PFilterFile(QString filePath, libtorrent::ip_filter& filter) { int ruleCount = 0; QFile file(filePath); if (file.exists()) { @@ -218,7 +224,7 @@ int FilterParserThread::getlineInStream(QDataStream& stream, string& name, char } // Parser for PeerGuardian ip filter in p2p format -int FilterParserThread::parseP2BFilterFile(QString filePath) { +int FilterParserThread::parseP2BFilterFile(QString filePath, libtorrent::ip_filter& filter) { int ruleCount = 0; QFile file(filePath); if (file.exists()) { @@ -327,8 +333,6 @@ int FilterParserThread::parseP2BFilterFile(QString filePath) { // * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format // * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format void FilterParserThread::processFilterFile(QString _filePath) { - // First, import current filter - filter = s->get_ip_filter(); if (isRunning()) { // Already parsing a filter, abort first abort = true; @@ -364,17 +368,18 @@ QString FilterParserThread::cleanupIPAddress(QString _ip) { void FilterParserThread::run() { qDebug("Processing filter file"); + libtorrent::ip_filter filter = s->get_ip_filter(); int ruleCount = 0; if (filePath.endsWith(".p2p", Qt::CaseInsensitive)) { // PeerGuardian p2p file - ruleCount = parseP2PFilterFile(filePath); + ruleCount = parseP2PFilterFile(filePath, filter); } else { if (filePath.endsWith(".p2b", Qt::CaseInsensitive)) { // PeerGuardian p2b file - ruleCount = parseP2BFilterFile(filePath); + ruleCount = parseP2BFilterFile(filePath, filter); } else { // Default: eMule DAT format - ruleCount = parseDATFilterFile(filePath); + ruleCount = parseDATFilterFile(filePath, filter); } } if (abort) diff --git a/src/qtlibtorrent/filterparserthread.h b/src/qtlibtorrent/filterparserthread.h index 1991182a1..7d41acbf5 100644 --- a/src/qtlibtorrent/filterparserthread.h +++ b/src/qtlibtorrent/filterparserthread.h @@ -32,13 +32,13 @@ #define FILTERPARSERTHREAD_H #include -#include #include #include -#include -#include -#include +namespace libtorrent { + class session; + struct ip_filter; +} using namespace std; @@ -58,10 +58,10 @@ public: FilterParserThread(QObject* parent, libtorrent::session *s); ~FilterParserThread(); - int parseDATFilterFile(QString filePath); - int parseP2PFilterFile(QString filePath); + int parseDATFilterFile(QString filePath, libtorrent::ip_filter& filter); + int parseP2PFilterFile(QString filePath, libtorrent::ip_filter& filter); int getlineInStream(QDataStream& stream, string& name, char delim); - int parseP2BFilterFile(QString filePath); + int parseP2BFilterFile(QString filePath, libtorrent::ip_filter& filter); void processFilterFile(QString _filePath); static void processFilterList(libtorrent::session *s, const QStringList& IPs); @@ -75,7 +75,6 @@ protected: private: libtorrent::session *s; - libtorrent::ip_filter filter; bool abort; QString filePath; };