@ -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 ( ) ;