mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00: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
@ -30,6 +30,12 @@
|
|||||||
|
|
||||||
#include "filterparserthread.h"
|
#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) {
|
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
|
// 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;
|
int ruleCount = 0;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -126,7 +132,7 @@ int FilterParserThread::parseDATFilterFile(QString filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parser for PeerGuardian ip filter in p2p format
|
// 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;
|
int ruleCount = 0;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -218,7 +224,7 @@ int FilterParserThread::getlineInStream(QDataStream& stream, string& name, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parser for PeerGuardian ip filter in p2p format
|
// 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;
|
int ruleCount = 0;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -327,8 +333,6 @@ int FilterParserThread::parseP2BFilterFile(QString filePath) {
|
|||||||
// * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format
|
// * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format
|
||||||
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format
|
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format
|
||||||
void FilterParserThread::processFilterFile(QString _filePath) {
|
void FilterParserThread::processFilterFile(QString _filePath) {
|
||||||
// First, import current filter
|
|
||||||
filter = s->get_ip_filter();
|
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
// Already parsing a filter, abort first
|
// Already parsing a filter, abort first
|
||||||
abort = true;
|
abort = true;
|
||||||
@ -364,17 +368,18 @@ QString FilterParserThread::cleanupIPAddress(QString _ip) {
|
|||||||
|
|
||||||
void FilterParserThread::run() {
|
void FilterParserThread::run() {
|
||||||
qDebug("Processing filter file");
|
qDebug("Processing filter file");
|
||||||
|
libtorrent::ip_filter filter = s->get_ip_filter();
|
||||||
int ruleCount = 0;
|
int ruleCount = 0;
|
||||||
if (filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
|
if (filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
|
||||||
// PeerGuardian p2p file
|
// PeerGuardian p2p file
|
||||||
ruleCount = parseP2PFilterFile(filePath);
|
ruleCount = parseP2PFilterFile(filePath, filter);
|
||||||
} else {
|
} else {
|
||||||
if (filePath.endsWith(".p2b", Qt::CaseInsensitive)) {
|
if (filePath.endsWith(".p2b", Qt::CaseInsensitive)) {
|
||||||
// PeerGuardian p2b file
|
// PeerGuardian p2b file
|
||||||
ruleCount = parseP2BFilterFile(filePath);
|
ruleCount = parseP2BFilterFile(filePath, filter);
|
||||||
} else {
|
} else {
|
||||||
// Default: eMule DAT format
|
// Default: eMule DAT format
|
||||||
ruleCount = parseDATFilterFile(filePath);
|
ruleCount = parseDATFilterFile(filePath, filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (abort)
|
if (abort)
|
||||||
|
@ -32,13 +32,13 @@
|
|||||||
#define FILTERPARSERTHREAD_H
|
#define FILTERPARSERTHREAD_H
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QFile>
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QHostAddress>
|
|
||||||
|
|
||||||
#include <libtorrent/session.hpp>
|
namespace libtorrent {
|
||||||
#include <libtorrent/ip_filter.hpp>
|
class session;
|
||||||
|
struct ip_filter;
|
||||||
|
}
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -58,10 +58,10 @@ public:
|
|||||||
FilterParserThread(QObject* parent, libtorrent::session *s);
|
FilterParserThread(QObject* parent, libtorrent::session *s);
|
||||||
~FilterParserThread();
|
~FilterParserThread();
|
||||||
|
|
||||||
int parseDATFilterFile(QString filePath);
|
int parseDATFilterFile(QString filePath, libtorrent::ip_filter& filter);
|
||||||
int parseP2PFilterFile(QString filePath);
|
int parseP2PFilterFile(QString filePath, libtorrent::ip_filter& filter);
|
||||||
int getlineInStream(QDataStream& stream, string& name, char delim);
|
int getlineInStream(QDataStream& stream, string& name, char delim);
|
||||||
int parseP2BFilterFile(QString filePath);
|
int parseP2BFilterFile(QString filePath, libtorrent::ip_filter& filter);
|
||||||
void processFilterFile(QString _filePath);
|
void processFilterFile(QString _filePath);
|
||||||
static void processFilterList(libtorrent::session *s, const QStringList& IPs);
|
static void processFilterList(libtorrent::session *s, const QStringList& IPs);
|
||||||
|
|
||||||
@ -75,7 +75,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
libtorrent::session *s;
|
libtorrent::session *s;
|
||||||
libtorrent::ip_filter filter;
|
|
||||||
bool abort;
|
bool abort;
|
||||||
QString filePath;
|
QString filePath;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user