mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 21:38:51 +03:00
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.
This commit is contained in:
parent
17f5ffcaec
commit
6347700ee3
2 changed files with 20 additions and 16 deletions
|
@ -30,6 +30,12 @@
|
|||
|
||||
#include "filterparserthread.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include <libtorrent/session.hpp>
|
||||
#include <libtorrent/ip_filter.hpp>
|
||||
|
||||
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)
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
#define FILTERPARSERTHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
#include <QStringList>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include <libtorrent/session.hpp>
|
||||
#include <libtorrent/ip_filter.hpp>
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue