Browse Source

Code optimization

Made code to listen on a particular interface more robust
adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
6c1eda8755
  1. 63
      src/qtlibtorrent/qbtsession.cpp
  2. 34
      src/qtlibtorrent/qbtsession.h

63
src/qtlibtorrent/qbtsession.cpp

@ -197,14 +197,6 @@ void QBtSession::preAllocateAllFiles(bool b) {
} }
} }
ScanFoldersModel* QBtSession::getScanFoldersModel() const {
return m_scanFolders;
}
bool QBtSession::isPexEnabled() const {
return PeXEnabled;
}
void QBtSession::processBigRatios() { void QBtSession::processBigRatios() {
if(ratio_limit < 0) return; if(ratio_limit < 0) return;
qDebug("Process big ratios..."); qDebug("Process big ratios...");
@ -243,10 +235,6 @@ void QBtSession::setDownloadLimit(QString hash, long val) {
} }
} }
bool QBtSession::isQueueingEnabled() const {
return queueingEnabled;
}
void QBtSession::setUploadLimit(QString hash, long val) { void QBtSession::setUploadLimit(QString hash, long val) {
qDebug("Set upload limit rate to %ld", val); qDebug("Set upload limit rate to %ld", val);
QTorrentHandle h = getTorrentHandle(hash); QTorrentHandle h = getTorrentHandle(hash);
@ -1358,15 +1346,6 @@ void QBtSession::setMaxUploadsPerTorrent(int max) {
} }
} }
// Return DHT state
bool QBtSession::isDHTEnabled() const{
return DHTEnabled;
}
bool QBtSession::isLSDEnabled() const{
return LSDEnabled;
}
void QBtSession::enableUPnP(bool b) { void QBtSession::enableUPnP(bool b) {
if(b) { if(b) {
if(!UPnPEnabled) { if(!UPnPEnabled) {
@ -1605,14 +1584,6 @@ void QBtSession::saveFastResumeData() {
} }
} }
QStringList QBtSession::getConsoleMessages() const {
return consoleMessages;
}
QStringList QBtSession::getPeerBanMessages() const {
return peerBanMessages;
}
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
void QBtSession::addConsoleMessage(QString msg, QString) { void QBtSession::addConsoleMessage(QString msg, QString) {
#else #else
@ -1666,14 +1637,6 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) {
} }
} }
QString QBtSession::getDefaultSavePath() const {
return defaultSavePath;
}
bool QBtSession::useTemporaryFolder() const {
return !defaultTempPath.isEmpty();
}
void QBtSession::setDefaultTempPath(QString temppath) { void QBtSession::setDefaultTempPath(QString temppath) {
if(defaultTempPath == temppath) if(defaultTempPath == temppath)
return; return;
@ -1808,15 +1771,27 @@ void QBtSession::setListeningPort(int port) {
} }
QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);
if(!network_iface.isValid()) { if(!network_iface.isValid()) {
qDebug("Invalid network interface: %s", qPrintable(iface_name));
addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red");
addConsoleMessage(tr("Trying any other network interface available instead."));
s->listen_on(ports); s->listen_on(ports);
return; return;
} }
QString ip = "127.0.0.1"; QString ip;
if(!network_iface.addressEntries().isEmpty()) { qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());
ip = network_iface.addressEntries().first().ip().toString(); foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));
if(s->listen_on(ports, qPrintable(entry.ip().toString()))) {
ip = entry.ip().toString();
break;
}
}
if(s->is_listening()) {
addConsoleMessage(tr("Listening on IP address %1 on network interface %2...").arg(ip).arg(iface_name));
} else {
qDebug("Failed to listen on any of the IP addresses");
addConsoleMessage(tr("Failed to listen on network interface %1").arg(iface_name), "red");
} }
qDebug("Listening on interface %s with ip %s", qPrintable(iface_name), qPrintable(ip));
s->listen_on(ports, ip.toLocal8Bit().constData());
} }
// Set download rate limit // Set download rate limit
@ -1827,10 +1802,6 @@ void QBtSession::setDownloadRateLimit(long rate) {
s->set_download_rate_limit(rate); s->set_download_rate_limit(rate);
} }
session* QBtSession::getSession() const{
return s;
}
// Set upload rate limit // Set upload rate limit
// -1 to disable // -1 to disable
void QBtSession::setUploadRateLimit(long rate) { void QBtSession::setUploadRateLimit(long rate) {

34
src/qtlibtorrent/qbtsession.h

@ -65,6 +65,10 @@ class ScanFoldersModel;
class QBtSession : public QObject { class QBtSession : public QObject {
Q_OBJECT Q_OBJECT
private:
QBtSession(const QBtSession& other); // Present copy
QBtSession& operator=(const QBtSession& other);
public: public:
// Constructor / Destructor // Constructor / Destructor
QBtSession(); QBtSession();
@ -72,31 +76,28 @@ public:
QTorrentHandle getTorrentHandle(QString hash) const; QTorrentHandle getTorrentHandle(QString hash) const;
std::vector<torrent_handle> getTorrents() const; std::vector<torrent_handle> getTorrents() const;
bool isFilePreviewPossible(QString fileHash) const; bool isFilePreviewPossible(QString fileHash) const;
bool isDHTEnabled() const;
bool isLSDEnabled() const;
float getPayloadDownloadRate() const; float getPayloadDownloadRate() const;
float getPayloadUploadRate() const; float getPayloadUploadRate() const;
session_status getSessionStatus() const; session_status getSessionStatus() const;
int getListenPort() const; int getListenPort() const;
float getRealRatio(QString hash) const; float getRealRatio(QString hash) const;
session* getSession() const;
QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const; QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const;
bool hasActiveTorrents() const; bool hasActiveTorrents() const;
bool hasDownloadingTorrents() const; bool hasDownloadingTorrents() const;
bool isQueueingEnabled() const; //int getMaximumActiveDownloads() const;
int getMaximumActiveDownloads() const; //int getMaximumActiveTorrents() const;
int getMaximumActiveTorrents() const;
int loadTorrentPriority(QString hash); int loadTorrentPriority(QString hash);
QStringList getConsoleMessages() const;
QStringList getPeerBanMessages() const;
qlonglong getETA(QString hash); qlonglong getETA(QString hash);
bool useTemporaryFolder() const; inline QStringList getConsoleMessages() const { return consoleMessages; }
QString getDefaultSavePath() const; inline QStringList getPeerBanMessages() const { return peerBanMessages; }
ScanFoldersModel* getScanFoldersModel() const; inline session* getSession() const { return s; }
bool isPexEnabled() const; inline bool useTemporaryFolder() const { return !defaultTempPath.isEmpty(); }
#if LIBTORRENT_VERSION_MINOR < 15 inline QString getDefaultSavePath() const { return defaultSavePath; }
void saveDHTEntry(); inline ScanFoldersModel* getScanFoldersModel() const { return m_scanFolders; }
#endif inline bool isDHTEnabled() const { return DHTEnabled; }
inline bool isLSDEnabled() const { return LSDEnabled; }
inline bool isPexEnabled() const { return DHTEnabled; }
inline bool isQueueingEnabled() const { return queueingEnabled; }
public slots: public slots:
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
@ -183,6 +184,9 @@ protected slots:
void cleanUpAutoRunProcess(int); void cleanUpAutoRunProcess(int);
void mergeTorrents(QTorrentHandle h_ex, boost::intrusive_ptr<torrent_info> t); void mergeTorrents(QTorrentHandle h_ex, boost::intrusive_ptr<torrent_info> t);
void exportTorrentFile(QTorrentHandle h); void exportTorrentFile(QTorrentHandle h);
#if LIBTORRENT_VERSION_MINOR < 15
void saveDHTEntry();
#endif
signals: signals:
void addedTorrent(QTorrentHandle& h); void addedTorrent(QTorrentHandle& h);

Loading…
Cancel
Save