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 @@ @@ -35,6 +35,8 @@
- FEATURE: Added BTJunkie search engine plugin
- 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 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 Brazilian translation
- BUGFIX: Progress of paused torrents is now correct on restart

6
TODO

@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
LANGUAGES UPDATED:
- French *BETA6*
- English *BETA6*
- Japanese *BETA3*
- Japanese *BETA6*
- Swedish *BETA6*
- Slovak *BETA6*
- Ukrainian *BETA6*
@ -81,7 +81,7 @@ LANGUAGES UPDATED: @@ -81,7 +81,7 @@ LANGUAGES UPDATED:
- Polish *BETA6*
- Portuguese *BETA5*
- Brazilian *BETA5*
- Spanish *BETA5*
- Spanish *BETA6*
- German *BETA6*
- Russian *BETA6*
- Korean *BETA6*
@ -100,6 +100,8 @@ beta6->beta7 changelog: @@ -100,6 +100,8 @@ beta6->beta7 changelog:
- FEATURE: Added an option to force full disk allocation for all torrents
- FEATURE: Added an option to add torrents in paused state
- 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: Updated man page / README / INSTALL
- 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) { @@ -777,21 +777,35 @@ void GUI::processDownloadedFiles(QString path, QString url) {
// Set BT session configuration
void GUI::configureSession(bool deleteOptions) {
qDebug("Configuring session");
QPair<int, int> limits;
unsigned short old_listenPort, new_listenPort;
proxy_settings proxySettings;
session_settings sessionSettings;
pe_settings encryptionSettings;
// Downloads
BTSession->preAllocateAllFiles(options->preAllocateAllFiles());
BTSession->startTorrentsInPause(options->addTorrentsInPause());
// Connection
old_listenPort = BTSession->getListenPort();
// * Ports binding
unsigned short old_listenPort = BTSession->getListenPort();
BTSession->setListeningPortsRange(options->getPorts());
new_listenPort = BTSession->getListenPort();
unsigned short new_listenPort = BTSession->getListenPort();
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)));
}
// * 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()) {
BTSession->enableUPnP(true);
downloadingTorrentTab->setInfoBar(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
@ -799,6 +813,7 @@ void GUI::configureSession(bool deleteOptions) { @@ -799,6 +813,7 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableUPnP(false);
downloadingTorrentTab->setInfoBar(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
}
// * NAT-PMP
if(options->isNATPMPEnabled()) {
BTSession->enableNATPMP(true);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
@ -806,14 +821,43 @@ void GUI::configureSession(bool deleteOptions) { @@ -806,14 +821,43 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableNATPMP(false);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
}
// Bittorrent
if(options->isLSDEnabled()) {
BTSession->enableLSD(true);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableLSD(false);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
// * Proxy settings
proxy_settings proxySettings;
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());
// * 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()) {
BTSession->enableDHT(true);
downloadingTorrentTab->setInfoBar(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue"));
@ -823,33 +867,26 @@ void GUI::configureSession(bool deleteOptions) { @@ -823,33 +867,26 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->enableDHT(false);
downloadingTorrentTab->setInfoBar(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// IP Filter
// Configure session regarding options
BTSession->setDefaultSavePath(options->getSavePath());
// Apply max connec limit (-1 if disabled)
BTSession->setMaxConnections(options->getMaxConnecs());
limits = options->getGlobalBandwidthLimits();
switch(limits.first) {
case -1: // Download limit disabled
case 0:
BTSession->setDownloadRateLimit(-1);
break;
default:
BTSession->setDownloadRateLimit(limits.first*1024);
// * PeX
if(options->isPeXEnabled()) {
downloadingTorrentTab->setInfoBar(tr("PeX support [ON]"), QString::fromUtf8("blue"));
BTSession->enablePeerExchange();
}else{
// TODO: How can we remove the extension?
downloadingTorrentTab->setInfoBar(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
}
switch(limits.second) {
case -1: // Upload limit disabled
case 0:
BTSession->setUploadRateLimit(-1);
break;
default:
BTSession->setUploadRateLimit(limits.second*1024);
// * LSD
if(options->isLSDEnabled()) {
BTSession->enableLSD(true);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableLSD(false);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
}
// Apply ratio (0 if disabled)
BTSession->setGlobalRatio(options->getDesiredRatio());
// Encryption settings
// * Encryption
int encryptionState = options->getEncryptionSetting();
// The most secure, rc4 only so that all streams and encrypted
pe_settings encryptionSettings;
encryptionSettings.allowed_enc_level = pe_settings::rc4;
encryptionSettings.prefer_rc4 = true;
switch(encryptionState) {
@ -869,15 +906,11 @@ void GUI::configureSession(bool deleteOptions) { @@ -869,15 +906,11 @@ void GUI::configureSession(bool deleteOptions) {
downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
}
BTSession->applyEncryptionSettings(encryptionSettings);
// PeX
if(options->isPeXEnabled()) {
qDebug("Enabling Peer eXchange (PeX)");
downloadingTorrentTab->setInfoBar(tr("PeX support [ON]"), QString::fromUtf8("blue"));
BTSession->enablePeerExchange();
}else{
downloadingTorrentTab->setInfoBar(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
qDebug("Peer eXchange (PeX) disabled");
}
// IP Filter
// Configure session regarding options
BTSession->setDefaultSavePath(options->getSavePath());
// Apply ratio (0 if disabled)
BTSession->setGlobalRatio(options->getDesiredRatio());
// Apply filtering settings
if(options->isFilteringEnabled()) {
BTSession->enableIPFilter(options->getFilter());
@ -886,32 +919,6 @@ void GUI::configureSession(bool deleteOptions) { @@ -886,32 +919,6 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->disableIPFilter();
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
if(options->getScanDir().isNull()) {
BTSession->disableDirectoryScanning();

56
src/bittorrent.cpp

@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
#define MAX_TRACKER_ERRORS 2
// 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
fs::path::default_name_check(fs::no_check);
// Creating bittorrent session
@ -369,7 +369,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -369,7 +369,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
if(file.isEmpty()) {
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());
std::ifstream in(file.toUtf8().data(), std::ios_base::binary);
in.unsetf(std::ios_base::skipws);
@ -386,15 +386,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -386,15 +386,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
QString old_hash = fi.baseName();
if(old_hash != hash){
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()) {
@ -442,9 +433,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -442,9 +433,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
if(!from_url.isNull()) QFile::remove(file);
return;
}
// Is this really useful and appropriate ?
//h.set_max_connections(60);
h.set_max_uploads(-1);
// Connections limit per torrent
h.set_max_connections(maxConnecsPerTorrent);
// Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent);
// Load filtered files
loadFilesPriorities(h);
// Load custom url seeds
@ -557,6 +549,36 @@ void bittorrent::setMaxConnections(int maxConnec) { @@ -557,6 +549,36 @@ void bittorrent::setMaxConnections(int 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
bool bittorrent::isDHTEnabled() const{
return DHTEnabled;
@ -1151,8 +1173,10 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { @@ -1151,8 +1173,10 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
}
QTorrentHandle new_h = s->add_torrent(t, saveDir, resumeData, false);
qDebug("Using full allocation mode");
new_h.set_max_uploads(-1);
// Connections limit per torrent
new_h.set_max_connections(maxConnecsPerTorrent);
// Uploads limit per torrent
new_h.set_max_uploads(maxUploadsPerTorrent);
// Load filtered Files
loadFilesPriorities(new_h);
// Load speed limit from hard drive

4
src/bittorrent.h

@ -59,6 +59,8 @@ class bittorrent : public QObject{ @@ -59,6 +59,8 @@ class bittorrent : public QObject{
QStringList unfinishedTorrents;
bool preAllocateAll;
bool addInPause;
int maxConnecsPerTorrent;
int maxUploadsPerTorrent;
protected:
QString getSavePath(QString hash);
@ -112,6 +114,8 @@ class bittorrent : public QObject{ @@ -112,6 +114,8 @@ class bittorrent : public QObject{
// Session configuration - Setters
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
void setMaxConnections(int maxConnec);
void setMaxConnectionsPerTorrent(int max);
void setMaxUploadsPerTorrent(int max);
void setDownloadRateLimit(long rate);
void setUploadRateLimit(long rate);
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 { @@ -120,7 +120,7 @@ QStringList QTorrentHandle::url_seeds() const {
std::vector<std::string> existing_seeds = h.get_torrent_info().url_seeds();
unsigned int nbSeeds = existing_seeds.size();
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]);
}
return res;
@ -278,11 +278,16 @@ void QTorrentHandle::add_url_seed(QString seed) { @@ -278,11 +278,16 @@ void QTorrentHandle::add_url_seed(QString seed) {
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());
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) {
Q_ASSERT(h.is_valid());
h.prioritize_files(v);
@ -308,7 +313,7 @@ void QTorrentHandle::set_sequenced_download_threshold(int val) { @@ -308,7 +313,7 @@ void QTorrentHandle::set_sequenced_download_threshold(int 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());
h.set_tracker_login(std::string(username.toUtf8().data()), std::string(password.toUtf8().data()));
}

1
src/qtorrenthandle.h

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

Loading…
Cancel
Save