Browse Source

- FEATURE: Added an option to set the max number of connections per torrent

- FEATURE: Added an option to set the max number of uploads per torrent
adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
078c80c81d
  1. 2
      Changelog
  2. 6
      TODO
  3. 151
      src/GUI.cpp
  4. 56
      src/bittorrent.cpp
  5. 4
      src/bittorrent.h
  6. 1452
      src/lang/qbittorrent_es.ts
  7. 1004
      src/lang/qbittorrent_ja.ts
  8. 11
      src/qtorrenthandle.cpp
  9. 1
      src/qtorrenthandle.h

2
Changelog

@ -35,6 +35,8 @@
- FEATURE: Added BTJunkie search engine plugin - FEATURE: Added BTJunkie search engine plugin
- FEATURE: Added an option to force full disk allocation for all torrents - FEATURE: Added an option to force full disk allocation for all torrents
- FEATURE: Added an option to add torrents in paused state - FEATURE: Added an option to add torrents in paused state
- FEATURE: Added an option to set the max number of connections per torrent
- FEATURE: Added an option to set the max number of uploads per torrent
- I18N: Added Hungarian translation - I18N: Added Hungarian translation
- I18N: Added Brazilian translation - I18N: Added Brazilian translation
- BUGFIX: Progress of paused torrents is now correct on restart - BUGFIX: Progress of paused torrents is now correct on restart

6
TODO

@ -71,7 +71,7 @@
LANGUAGES UPDATED: LANGUAGES UPDATED:
- French *BETA6* - French *BETA6*
- English *BETA6* - English *BETA6*
- Japanese *BETA3* - Japanese *BETA6*
- Swedish *BETA6* - Swedish *BETA6*
- Slovak *BETA6* - Slovak *BETA6*
- Ukrainian *BETA6* - Ukrainian *BETA6*
@ -81,7 +81,7 @@ LANGUAGES UPDATED:
- Polish *BETA6* - Polish *BETA6*
- Portuguese *BETA5* - Portuguese *BETA5*
- Brazilian *BETA5* - Brazilian *BETA5*
- Spanish *BETA5* - Spanish *BETA6*
- German *BETA6* - German *BETA6*
- Russian *BETA6* - Russian *BETA6*
- Korean *BETA6* - Korean *BETA6*
@ -100,6 +100,8 @@ beta6->beta7 changelog:
- FEATURE: Added an option to force full disk allocation for all torrents - FEATURE: Added an option to force full disk allocation for all torrents
- FEATURE: Added an option to add torrents in paused state - FEATURE: Added an option to add torrents in paused state
- FEATURE: Allow to disable UPnP/NAT-PMP/LSD - FEATURE: Allow to disable UPnP/NAT-PMP/LSD
- FEATURE: Added an option to set the max number of connections per torrent
- FEATURE: Added an option to set the max number of uploads per torrent
- BUGFIX: In torrent content, it is now easier to filter all torrents using right click menu - BUGFIX: In torrent content, it is now easier to filter all torrents using right click menu
- BUGFIX: Updated man page / README / INSTALL - BUGFIX: Updated man page / README / INSTALL
- BUGFIX: Paused torrents could be displayed as connected for a sec after checking - BUGFIX: Paused torrents could be displayed as connected for a sec after checking

151
src/GUI.cpp

@ -777,21 +777,35 @@ void GUI::processDownloadedFiles(QString path, QString url) {
// Set BT session configuration // Set BT session configuration
void GUI::configureSession(bool deleteOptions) { void GUI::configureSession(bool deleteOptions) {
qDebug("Configuring session"); qDebug("Configuring session");
QPair<int, int> limits;
unsigned short old_listenPort, new_listenPort;
proxy_settings proxySettings;
session_settings sessionSettings;
pe_settings encryptionSettings;
// Downloads // Downloads
BTSession->preAllocateAllFiles(options->preAllocateAllFiles()); BTSession->preAllocateAllFiles(options->preAllocateAllFiles());
BTSession->startTorrentsInPause(options->addTorrentsInPause()); BTSession->startTorrentsInPause(options->addTorrentsInPause());
// Connection // Connection
old_listenPort = BTSession->getListenPort(); // * Ports binding
unsigned short old_listenPort = BTSession->getListenPort();
BTSession->setListeningPortsRange(options->getPorts()); BTSession->setListeningPortsRange(options->getPorts());
new_listenPort = BTSession->getListenPort(); unsigned short new_listenPort = BTSession->getListenPort();
if(new_listenPort != old_listenPort) { if(new_listenPort != old_listenPort) {
downloadingTorrentTab->setInfoBar(tr("qBittorrent is bind to port: %1", "e.g: qBittorrent is bind to port: 1666").arg( misc::toQString(new_listenPort))); downloadingTorrentTab->setInfoBar(tr("qBittorrent is bind to port: %1", "e.g: qBittorrent is bind to port: 1666").arg( misc::toQString(new_listenPort)));
} }
// * Global download limit
QPair<int, int> limits = options->getGlobalBandwidthLimits();
if(limits.first <= 0) {
// Download limit disabled
BTSession->setDownloadRateLimit(-1);
} else {
// Enabled
BTSession->setDownloadRateLimit(limits.first*1024);
}
// * Global Upload limit
if(limits.second <= 0) {
// Upload limit disabled
BTSession->setUploadRateLimit(-1);
} else {
// Enabled
BTSession->setUploadRateLimit(limits.second*1024);
}
// * UPnP
if(options->isUPnPEnabled()) { if(options->isUPnPEnabled()) {
BTSession->enableUPnP(true); BTSession->enableUPnP(true);
downloadingTorrentTab->setInfoBar(tr("UPnP support [ON]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
@ -799,6 +813,7 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableUPnP(false); BTSession->enableUPnP(false);
downloadingTorrentTab->setInfoBar(tr("UPnP support [OFF]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
} }
// * NAT-PMP
if(options->isNATPMPEnabled()) { if(options->isNATPMPEnabled()) {
BTSession->enableNATPMP(true); BTSession->enableNATPMP(true);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
@ -806,14 +821,43 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableNATPMP(false); BTSession->enableNATPMP(false);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
} }
// Bittorrent // * Proxy settings
if(options->isLSDEnabled()) { proxy_settings proxySettings;
BTSession->enableLSD(true); if(options->isProxyEnabled()) {
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue")); switch(options->getProxyType()) {
} else { case HTTP:
BTSession->enableLSD(false); proxySettings.type = proxy_settings::http;
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue")); break;
case HTTP_PW:
proxySettings.type = proxy_settings::http_pw;
break;
case SOCKS5:
proxySettings.type = proxy_settings::socks5;
break;
default:
proxySettings.type = proxy_settings::socks5_pw;
break;
}
proxySettings.hostname = options->getProxyIp().toStdString();
proxySettings.port = options->getProxyPort();
if(options->isProxyAuthEnabled()) {
proxySettings.username = options->getProxyUsername().toStdString();
proxySettings.password = options->getProxyPassword().toStdString();
} }
}
BTSession->setProxySettings(proxySettings, options->useProxyForTrackers(), options->useProxyForPeers(), options->useProxyForWebseeds(), options->useProxyForDHT());
// * Session settings
session_settings sessionSettings;
sessionSettings.user_agent = "qBittorrent "VERSION;
BTSession->setSessionSettings(sessionSettings);
// Bittorrent
// * Max connections limit
BTSession->setMaxConnections(options->getMaxConnecs());
// * Max connections per torrent limit
BTSession->setMaxConnectionsPerTorrent(options->getMaxConnecsPerTorrent());
// * Max uploads per torrent limit
BTSession->setMaxUploadsPerTorrent(options->getMaxUploadsPerTorrent());
// * DHT
if(options->isDHTEnabled()) { if(options->isDHTEnabled()) {
BTSession->enableDHT(true); BTSession->enableDHT(true);
downloadingTorrentTab->setInfoBar(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue"));
@ -823,33 +867,26 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableDHT(false); BTSession->enableDHT(false);
downloadingTorrentTab->setInfoBar(tr("DHT support [OFF]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
} }
// IP Filter // * PeX
// Configure session regarding options if(options->isPeXEnabled()) {
BTSession->setDefaultSavePath(options->getSavePath()); downloadingTorrentTab->setInfoBar(tr("PeX support [ON]"), QString::fromUtf8("blue"));
// Apply max connec limit (-1 if disabled) BTSession->enablePeerExchange();
BTSession->setMaxConnections(options->getMaxConnecs()); }else{
limits = options->getGlobalBandwidthLimits(); // TODO: How can we remove the extension?
switch(limits.first) { downloadingTorrentTab->setInfoBar(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
case -1: // Download limit disabled
case 0:
BTSession->setDownloadRateLimit(-1);
break;
default:
BTSession->setDownloadRateLimit(limits.first*1024);
} }
switch(limits.second) { // * LSD
case -1: // Upload limit disabled if(options->isLSDEnabled()) {
case 0: BTSession->enableLSD(true);
BTSession->setUploadRateLimit(-1); downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
break; } else {
default: BTSession->enableLSD(false);
BTSession->setUploadRateLimit(limits.second*1024); downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
} }
// Apply ratio (0 if disabled) // * Encryption
BTSession->setGlobalRatio(options->getDesiredRatio());
// Encryption settings
int encryptionState = options->getEncryptionSetting(); int encryptionState = options->getEncryptionSetting();
// The most secure, rc4 only so that all streams and encrypted // The most secure, rc4 only so that all streams and encrypted
pe_settings encryptionSettings;
encryptionSettings.allowed_enc_level = pe_settings::rc4; encryptionSettings.allowed_enc_level = pe_settings::rc4;
encryptionSettings.prefer_rc4 = true; encryptionSettings.prefer_rc4 = true;
switch(encryptionState) { switch(encryptionState) {
@ -869,15 +906,11 @@ void GUI::configureSession(bool deleteOptions) {
downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue")); downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
} }
BTSession->applyEncryptionSettings(encryptionSettings); BTSession->applyEncryptionSettings(encryptionSettings);
// PeX // IP Filter
if(options->isPeXEnabled()) { // Configure session regarding options
qDebug("Enabling Peer eXchange (PeX)"); BTSession->setDefaultSavePath(options->getSavePath());
downloadingTorrentTab->setInfoBar(tr("PeX support [ON]"), QString::fromUtf8("blue")); // Apply ratio (0 if disabled)
BTSession->enablePeerExchange(); BTSession->setGlobalRatio(options->getDesiredRatio());
}else{
downloadingTorrentTab->setInfoBar(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
qDebug("Peer eXchange (PeX) disabled");
}
// Apply filtering settings // Apply filtering settings
if(options->isFilteringEnabled()) { if(options->isFilteringEnabled()) {
BTSession->enableIPFilter(options->getFilter()); BTSession->enableIPFilter(options->getFilter());
@ -886,32 +919,6 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->disableIPFilter(); BTSession->disableIPFilter();
downloadingTorrentTab->setBottomTabEnabled(1, false); downloadingTorrentTab->setBottomTabEnabled(1, false);
} }
// Apply Proxy settings
if(options->isProxyEnabled()) {
switch(options->getProxyType()) {
case HTTP:
proxySettings.type = proxy_settings::http;
break;
case HTTP_PW:
proxySettings.type = proxy_settings::http_pw;
break;
case SOCKS5:
proxySettings.type = proxy_settings::socks5;
break;
default:
proxySettings.type = proxy_settings::socks5_pw;
break;
}
proxySettings.hostname = options->getProxyIp().toStdString();
proxySettings.port = options->getProxyPort();
if(options->isProxyAuthEnabled()) {
proxySettings.username = options->getProxyUsername().toStdString();
proxySettings.password = options->getProxyPassword().toStdString();
}
}
BTSession->setProxySettings(proxySettings, options->useProxyForTrackers(), options->useProxyForPeers(), options->useProxyForWebseeds(), options->useProxyForDHT());
sessionSettings.user_agent = "qBittorrent "VERSION;
BTSession->setSessionSettings(sessionSettings);
// Scan dir stuff // Scan dir stuff
if(options->getScanDir().isNull()) { if(options->getScanDir().isNull()) {
BTSession->disableDirectoryScanning(); BTSession->disableDirectoryScanning();

56
src/bittorrent.cpp

@ -44,7 +44,7 @@
#define MAX_TRACKER_ERRORS 2 #define MAX_TRACKER_ERRORS 2
// Main constructor // Main constructor
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false){ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4) {
// To avoid some exceptions // To avoid some exceptions
fs::path::default_name_check(fs::no_check); fs::path::default_name_check(fs::no_check);
// Creating bittorrent session // Creating bittorrent session
@ -369,7 +369,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
if(file.isEmpty()) { if(file.isEmpty()) {
return; return;
} }
Q_ASSERT(!file.startsWith("http://") && !file.startsWith("https://") && !file.startsWith("ftp://")); Q_ASSERT(!file.startsWith("http://", Qt::CaseInsensitive) && !file.startsWith("https://", Qt::CaseInsensitive) && !file.startsWith("ftp://", Qt::CaseInsensitive));
qDebug("Adding %s to download list", file.toUtf8().data()); qDebug("Adding %s to download list", file.toUtf8().data());
std::ifstream in(file.toUtf8().data(), std::ios_base::binary); std::ifstream in(file.toUtf8().data(), std::ios_base::binary);
in.unsetf(std::ios_base::skipws); in.unsetf(std::ios_base::skipws);
@ -386,15 +386,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
QString old_hash = fi.baseName(); QString old_hash = fi.baseName();
if(old_hash != hash){ if(old_hash != hash){
qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data()); qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data());
// QStringList filters;
// filters << old_hash+".*";
// QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
// QString my_f;
// foreach(my_f, files) {
// qDebug("* deleting %s", my_f.toUtf8().data());
// torrentBackup.remove(my_f);
// }
// return;
} }
} }
if(s->find_torrent(t->info_hash()).is_valid()) { if(s->find_torrent(t->info_hash()).is_valid()) {
@ -442,9 +433,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
if(!from_url.isNull()) QFile::remove(file); if(!from_url.isNull()) QFile::remove(file);
return; return;
} }
// Is this really useful and appropriate ? // Connections limit per torrent
//h.set_max_connections(60); h.set_max_connections(maxConnecsPerTorrent);
h.set_max_uploads(-1); // Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent);
// Load filtered files // Load filtered files
loadFilesPriorities(h); loadFilesPriorities(h);
// Load custom url seeds // Load custom url seeds
@ -557,6 +549,36 @@ void bittorrent::setMaxConnections(int maxConnec) {
s->set_max_connections(maxConnec); s->set_max_connections(maxConnec);
} }
void bittorrent::setMaxConnectionsPerTorrent(int max) {
maxConnecsPerTorrent = max;
// Apply this to all session torrents
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
for(unsigned int i=0; i<nbHandles; ++i) {
QTorrentHandle h = handles[i];
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
continue;
}
h.set_max_connections(max);
}
}
void bittorrent::setMaxUploadsPerTorrent(int max) {
maxUploadsPerTorrent = max;
// Apply this to all session torrents
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
for(unsigned int i=0; i<nbHandles; ++i) {
QTorrentHandle h = handles[i];
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
continue;
}
h.set_max_uploads(max);
}
}
// Return DHT state // Return DHT state
bool bittorrent::isDHTEnabled() const{ bool bittorrent::isDHTEnabled() const{
return DHTEnabled; return DHTEnabled;
@ -1151,8 +1173,10 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
} }
QTorrentHandle new_h = s->add_torrent(t, saveDir, resumeData, false); QTorrentHandle new_h = s->add_torrent(t, saveDir, resumeData, false);
qDebug("Using full allocation mode"); qDebug("Using full allocation mode");
// Connections limit per torrent
new_h.set_max_uploads(-1); new_h.set_max_connections(maxConnecsPerTorrent);
// Uploads limit per torrent
new_h.set_max_uploads(maxUploadsPerTorrent);
// Load filtered Files // Load filtered Files
loadFilesPriorities(new_h); loadFilesPriorities(new_h);
// Load speed limit from hard drive // Load speed limit from hard drive

4
src/bittorrent.h

@ -59,6 +59,8 @@ class bittorrent : public QObject{
QStringList unfinishedTorrents; QStringList unfinishedTorrents;
bool preAllocateAll; bool preAllocateAll;
bool addInPause; bool addInPause;
int maxConnecsPerTorrent;
int maxUploadsPerTorrent;
protected: protected:
QString getSavePath(QString hash); QString getSavePath(QString hash);
@ -112,6 +114,8 @@ class bittorrent : public QObject{
// Session configuration - Setters // Session configuration - Setters
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports); void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
void setMaxConnections(int maxConnec); void setMaxConnections(int maxConnec);
void setMaxConnectionsPerTorrent(int max);
void setMaxUploadsPerTorrent(int max);
void setDownloadRateLimit(long rate); void setDownloadRateLimit(long rate);
void setUploadRateLimit(long rate); void setUploadRateLimit(long rate);
void setGlobalRatio(float ratio); void setGlobalRatio(float ratio);

1452
src/lang/qbittorrent_es.ts

File diff suppressed because it is too large Load Diff

1004
src/lang/qbittorrent_ja.ts

File diff suppressed because it is too large Load Diff

11
src/qtorrenthandle.cpp

@ -120,7 +120,7 @@ QStringList QTorrentHandle::url_seeds() const {
std::vector<std::string> existing_seeds = h.get_torrent_info().url_seeds(); std::vector<std::string> existing_seeds = h.get_torrent_info().url_seeds();
unsigned int nbSeeds = existing_seeds.size(); unsigned int nbSeeds = existing_seeds.size();
QString existing_seed; QString existing_seed;
for(unsigned int i=0; i<nbSeeds; ++i){ for(unsigned int i=0; i<nbSeeds; ++i) {
res << misc::toQString(existing_seeds[i]); res << misc::toQString(existing_seeds[i]);
} }
return res; return res;
@ -278,11 +278,16 @@ void QTorrentHandle::add_url_seed(QString seed) {
h.add_url_seed(misc::toString((const char*)seed.toUtf8())); h.add_url_seed(misc::toString((const char*)seed.toUtf8()));
} }
void QTorrentHandle::set_max_uploads(int val){ void QTorrentHandle::set_max_uploads(int val) {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
h.set_max_uploads(val); h.set_max_uploads(val);
} }
void QTorrentHandle::set_max_connections(int val) {
Q_ASSERT(h.is_valid());
h.set_max_connections(val);
}
void QTorrentHandle::prioritize_files(std::vector<int> v) { void QTorrentHandle::prioritize_files(std::vector<int> v) {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
h.prioritize_files(v); h.prioritize_files(v);
@ -308,7 +313,7 @@ void QTorrentHandle::set_sequenced_download_threshold(int val) {
h.set_sequenced_download_threshold(val); h.set_sequenced_download_threshold(val);
} }
void QTorrentHandle::set_tracker_login(QString username, QString password){ void QTorrentHandle::set_tracker_login(QString username, QString password) {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
h.set_tracker_login(std::string(username.toUtf8().data()), std::string(password.toUtf8().data())); h.set_tracker_login(std::string(username.toUtf8().data()), std::string(password.toUtf8().data()));
} }

1
src/qtorrenthandle.h

@ -96,6 +96,7 @@ class QTorrentHandle {
void remove_url_seed(QString seed); void remove_url_seed(QString seed);
void add_url_seed(QString seed); void add_url_seed(QString seed);
void set_max_uploads(int val); void set_max_uploads(int val);
void set_max_connections(int val);
void prioritize_files(std::vector<int> v); void prioritize_files(std::vector<int> v);
void set_ratio(float ratio) const; void set_ratio(float ratio) const;
void replace_trackers(std::vector<announce_entry> const&) const; void replace_trackers(std::vector<announce_entry> const&) const;

Loading…
Cancel
Save