@ -39,6 +39,7 @@
# include "smtp.h"
# include "smtp.h"
# include "filesystemwatcher.h"
# include "filesystemwatcher.h"
# include "torrentspeedmonitor.h"
# include "torrentspeedmonitor.h"
# include "torrentstatistics.h"
# include "qbtsession.h"
# include "qbtsession.h"
# include "misc.h"
# include "misc.h"
# include "fs_utils.h"
# include "fs_utils.h"
@ -114,6 +115,7 @@ QBtSession::QBtSession()
, m_upnp ( 0 ) , m_natpmp ( 0 )
, m_upnp ( 0 ) , m_natpmp ( 0 )
# endif
# endif
, m_dynDNSUpdater ( 0 )
, m_dynDNSUpdater ( 0 )
, m_alertDispatcher ( 0 )
{
{
BigRatioTimer = new QTimer ( this ) ;
BigRatioTimer = new QTimer ( this ) ;
BigRatioTimer - > setInterval ( 10000 ) ;
BigRatioTimer - > setInterval ( 10000 ) ;
@ -132,7 +134,7 @@ QBtSession::QBtSession()
addConsoleMessage ( " Peer ID: " + misc : : toQString ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) ) ) ;
addConsoleMessage ( " Peer ID: " + misc : : toQString ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) ) ) ;
// Set severity level of libtorrent session
// Set severity level of libtorrent session
s - > set_alert_mask ( alert : : error_notification | alert : : peer_notification | alert : : port_mapping_notification | alert : : storage_notification | alert : : tracker_notification | alert : : status_notification | alert : : ip_block_notification | alert : : progress_notification ) ;
s - > set_alert_mask ( alert : : error_notification | alert : : peer_notification | alert : : port_mapping_notification | alert : : storage_notification | alert : : tracker_notification | alert : : status_notification | alert : : ip_block_notification | alert : : progress_notification | alert : : stats_notification ) ;
// Load previous state
// Load previous state
loadSessionState ( ) ;
loadSessionState ( ) ;
// Enabling plugins
// Enabling plugins
@ -147,9 +149,8 @@ QBtSession::QBtSession()
PeXEnabled = false ;
PeXEnabled = false ;
}
}
s - > add_extension ( & create_smart_ban_plugin ) ;
s - > add_extension ( & create_smart_ban_plugin ) ;
timerAlerts = new QTimer ( this ) ;
m_alertDispatcher = new QAlertDispatcher ( s , this ) ;
connect ( timerAlerts , SIGNAL ( timeout ( ) ) , SLOT ( readAlerts ( ) ) ) ;
connect ( m_alertDispatcher , SIGNAL ( alertsReceived ( ) ) , SLOT ( readAlerts ( ) ) ) ;
timerAlerts - > start ( 1000 ) ;
appendLabelToSavePath = pref . appendTorrentLabel ( ) ;
appendLabelToSavePath = pref . appendTorrentLabel ( ) ;
appendqBExtension = pref . useIncompleteFilesExtension ( ) ;
appendqBExtension = pref . useIncompleteFilesExtension ( ) ;
connect ( m_scanFolders , SIGNAL ( torrentsAdded ( QStringList & ) ) , SLOT ( addTorrentsFromScanFolder ( QStringList & ) ) ) ;
connect ( m_scanFolders , SIGNAL ( torrentsAdded ( QStringList & ) ) , SLOT ( addTorrentsFromScanFolder ( QStringList & ) ) ) ;
@ -157,7 +158,7 @@ QBtSession::QBtSession()
configureSession ( ) ;
configureSession ( ) ;
// Torrent speed monitor
// Torrent speed monitor
m_speedMonitor = new TorrentSpeedMonitor ( this ) ;
m_speedMonitor = new TorrentSpeedMonitor ( this ) ;
m_speedMonitor - > start ( ) ;
m_torrentStatistics = new TorrentStatistics ( this , this ) ;
// To download from urls
// To download from urls
downloader = new DownloadThread ( this ) ;
downloader = new DownloadThread ( this ) ;
connect ( downloader , SIGNAL ( downloadFinished ( QString , QString ) ) , SLOT ( processDownloadedFile ( QString , QString ) ) ) ;
connect ( downloader , SIGNAL ( downloadFinished ( QString , QString ) ) , SLOT ( processDownloadedFile ( QString , QString ) ) ) ;
@ -179,7 +180,6 @@ QBtSession::~QBtSession() {
// Delete our objects
// Delete our objects
if ( m_tracker )
if ( m_tracker )
delete m_tracker ;
delete m_tracker ;
delete timerAlerts ;
if ( BigRatioTimer )
if ( BigRatioTimer )
delete BigRatioTimer ;
delete BigRatioTimer ;
if ( filterParser )
if ( filterParser )
@ -190,6 +190,8 @@ QBtSession::~QBtSession() {
// HTTP Server
// HTTP Server
if ( httpServer )
if ( httpServer )
delete httpServer ;
delete httpServer ;
delete m_alertDispatcher ;
delete m_torrentStatistics ;
qDebug ( " Deleting the session " ) ;
qDebug ( " Deleting the session " ) ;
delete s ;
delete s ;
qDebug ( " BTSession destructor OUT " ) ;
qDebug ( " BTSession destructor OUT " ) ;
@ -220,7 +222,7 @@ void QBtSession::processBigRatios() {
if ( ! h . is_valid ( ) ) continue ;
if ( ! h . is_valid ( ) ) continue ;
if ( h . is_seed ( ) ) {
if ( h . is_seed ( ) ) {
const QString hash = h . hash ( ) ;
const QString hash = h . hash ( ) ;
const qreal ratio = getRealRatio ( has h ) ;
const qreal ratio = getRealRatio ( h . status ( torrent_ handle : : query_accurate_download_counters ) ) ;
qreal ratio_limit = TorrentPersistentData : : getRatioLimit ( hash ) ;
qreal ratio_limit = TorrentPersistentData : : getRatioLimit ( hash ) ;
if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO )
if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO )
ratio_limit = global_ratio_limit ;
ratio_limit = global_ratio_limit ;
@ -1556,15 +1558,11 @@ bool QBtSession::enableDHT(bool b) {
return true ;
return true ;
}
}
qreal QBtSession : : getRealRatio ( const QString & hash ) const {
qreal QBtSession : : getRealRatio ( const libtorrent : : torrent_status & status ) const {
QTorrentHandle h = getTorrentHandle ( hash ) ;
libtorrent : : size_type all_time_upload = status . all_time_upload ;
if ( ! h . is_valid ( ) ) {
libtorrent : : size_type all_time_download = status . all_time_download ;
return 0. ;
libtorrent : : size_type total_done = status . total_done ;
}
libtorrent : : size_type all_time_upload = h . all_time_upload ( ) ;
libtorrent : : size_type all_time_download = h . all_time_download ( ) ;
libtorrent : : size_type total_done = h . total_done ( ) ;
if ( all_time_download < total_done ) {
if ( all_time_download < total_done ) {
// We have more data on disk than we downloaded
// We have more data on disk than we downloaded
// either because the user imported the file
// either because the user imported the file
@ -1577,7 +1575,7 @@ qreal QBtSession::getRealRatio(const QString &hash) const {
if ( all_time_download = = 0 ) {
if ( all_time_download = = 0 ) {
if ( all_time_upload = = 0 )
if ( all_time_upload = = 0 )
return 0 ;
return 0. 0;
return MAX_RATIO + 1 ;
return MAX_RATIO + 1 ;
}
}
@ -1612,7 +1610,6 @@ void QBtSession::saveFastResumeData() {
qDebug ( " Saving fast resume data... " ) ;
qDebug ( " Saving fast resume data... " ) ;
// Stop listening for alerts
// Stop listening for alerts
resumeDataTimer . stop ( ) ;
resumeDataTimer . stop ( ) ;
timerAlerts - > stop ( ) ;
int num_resume_data = 0 ;
int num_resume_data = 0 ;
// Pause session
// Pause session
s - > pause ( ) ;
s - > pause ( ) ;
@ -1637,17 +1634,16 @@ void QBtSession::saveFastResumeData() {
} catch ( libtorrent : : invalid_handle & ) { }
} catch ( libtorrent : : invalid_handle & ) { }
}
}
while ( num_resume_data > 0 ) {
while ( num_resume_data > 0 ) {
alert const * a = s - > wait_for_alert ( seconds ( 30 ) ) ;
std : : deque < alert * > alerts ;
if ( a = = 0 ) {
m_alertDispatcher - > getPendingAlerts ( alerts ) ;
std : : cerr < < " aborting with " < < num_resume_data < < " outstanding "
" torrents to save resume data for " < < std : : endl ;
for ( std : : deque < alert * > : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i )
break ;
{
}
alert const * a = * i ;
// Saving fastresume data can fail
// Saving fastresume data can fail
save_resume_data_failed_alert const * rda = dynamic_cast < save_resume_data_failed_alert const * > ( a ) ;
save_resume_data_failed_alert const * rda = dynamic_cast < save_resume_data_failed_alert const * > ( a ) ;
if ( rda ) {
if ( rda ) {
- - num_resume_data ;
- - num_resume_data ;
s - > pop_alert ( ) ;
try {
try {
// Remove torrent from session
// Remove torrent from session
if ( rda - > handle . is_valid ( ) )
if ( rda - > handle . is_valid ( ) )
@ -1657,7 +1653,6 @@ void QBtSession::saveFastResumeData() {
}
}
save_resume_data_alert const * rd = dynamic_cast < save_resume_data_alert const * > ( a ) ;
save_resume_data_alert const * rd = dynamic_cast < save_resume_data_alert const * > ( a ) ;
if ( ! rd ) {
if ( ! rd ) {
s - > pop_alert ( ) ;
continue ;
continue ;
}
}
// Saving fast resume data was successful
// Saving fast resume data was successful
@ -1681,8 +1676,10 @@ void QBtSession::saveFastResumeData() {
}
}
// Remove torrent from session
// Remove torrent from session
s - > remove_torrent ( rd - > handle ) ;
s - > remove_torrent ( rd - > handle ) ;
s - > pop_alert ( ) ;
} catch ( libtorrent : : invalid_handle & ) { }
} catch ( libtorrent : : invalid_handle & ) { }
delete a ;
}
}
}
}
}
@ -2107,11 +2104,12 @@ void QBtSession::autoRunExternalProgram(const QTorrentHandle &h) {
}
}
void QBtSession : : sendNotificationEmail ( const QTorrentHandle & h ) {
void QBtSession : : sendNotificationEmail ( const QTorrentHandle & h ) {
libtorrent : : torrent_status status = h . status ( torrent_handle : : query_accurate_download_counters ) ;
// Prepare mail content
// Prepare mail content
QString content = tr ( " Torrent name: %1 " ) . arg ( h . name ( ) ) + " \n " ;
QString content = tr ( " Torrent name: %1 " ) . arg ( h . name ( ) ) + " \n " ;
content + = tr ( " Torrent size: %1 " ) . arg ( misc : : friendlyUnit ( h . actual_size ( ) ) ) + " \n " ;
content + = tr ( " Torrent size: %1 " ) . arg ( misc : : friendlyUnit ( status . total_wanted ) ) + " \n " ;
content + = tr ( " Save path: %1 " ) . arg ( TorrentPersistentData : : getSavePath ( h . hash ( ) ) ) + " \n \n " ;
content + = tr ( " Save path: %1 " ) . arg ( TorrentPersistentData : : getSavePath ( h . hash ( ) ) ) + " \n \n " ;
content + = tr ( " The torrent was downloaded in %1. " , " The torrent was downloaded in 1 hour and 20 seconds " ) . arg ( misc : : userFriendlyDuration ( h . active_time ( ) ) ) + " \n \n \n " ;
content + = tr ( " The torrent was downloaded in %1. " , " The torrent was downloaded in 1 hour and 20 seconds " ) . arg ( misc : : userFriendlyDuration ( status . active_time ) ) + " \n \n \n " ;
content + = tr ( " Thank you for using qBittorrent. " ) + " \n " ;
content + = tr ( " Thank you for using qBittorrent. " ) + " \n " ;
// Send the notification email
// Send the notification email
Smtp * sender = new Smtp ( this ) ;
Smtp * sender = new Smtp ( this ) ;
@ -2120,11 +2118,20 @@ void QBtSession::sendNotificationEmail(const QTorrentHandle &h) {
// Read alerts sent by the Bittorrent session
// Read alerts sent by the Bittorrent session
void QBtSession : : readAlerts ( ) {
void QBtSession : : readAlerts ( ) {
// look at session alerts and display some infos
std : : auto_ptr < alert > a = s - > pop_alert ( ) ;
typedef std : : deque < alert * > alerts_t ;
while ( a . get ( ) ) {
alerts_t alerts ;
m_alertDispatcher - > getPendingAlertsNoWait ( alerts ) ;
for ( alerts_t : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i ) {
handleAlert ( * i ) ;
delete * i ;
}
}
void QBtSession : : handleAlert ( libtorrent : : alert * a ) {
try {
try {
if ( torrent_finished_alert * p = dynamic_cast < torrent_finished_alert * > ( a . get ( ) ) ) {
if ( torrent_finished_alert * p = dynamic_cast < torrent_finished_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
const QString hash = h . hash ( ) ;
const QString hash = h . hash ( ) ;
@ -2180,14 +2187,14 @@ void QBtSession::readAlerts() {
qDebug ( " Emitting finishedTorrent() signal " ) ;
qDebug ( " Emitting finishedTorrent() signal " ) ;
emit finishedTorrent ( h ) ;
emit finishedTorrent ( h ) ;
qDebug ( " Received finished alert for %s " , qPrintable ( h . name ( ) ) ) ;
qDebug ( " Received finished alert for %s " , qPrintable ( h . name ( ) ) ) ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
bool will_shutdown = ( pref . shutdownWhenDownloadsComplete ( ) | |
bool will_shutdown = ( pref . shutdownWhenDownloadsComplete ( ) | |
pref . shutdownqBTWhenDownloadsComplete ( ) | |
pref . shutdownqBTWhenDownloadsComplete ( ) | |
pref . suspendWhenDownloadsComplete ( ) )
pref . suspendWhenDownloadsComplete ( ) )
& & ! hasDownloadingTorrents ( ) ;
& & ! hasDownloadingTorrents ( ) ;
# else
# else
bool will_shutdown = false ;
bool will_shutdown = false ;
# endif
# endif
// AutoRun program
// AutoRun program
if ( pref . isAutoRunEnabled ( ) )
if ( pref . isAutoRunEnabled ( ) )
autoRunExternalProgram ( h ) ;
autoRunExternalProgram ( h ) ;
@ -2197,7 +2204,7 @@ void QBtSession::readAlerts() {
// Mail notification
// Mail notification
if ( pref . isMailNotificationEnabled ( ) )
if ( pref . isMailNotificationEnabled ( ) )
sendNotificationEmail ( h ) ;
sendNotificationEmail ( h ) ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
// Auto-Shutdown
// Auto-Shutdown
if ( will_shutdown ) {
if ( will_shutdown ) {
bool suspend = pref . suspendWhenDownloadsComplete ( ) ;
bool suspend = pref . suspendWhenDownloadsComplete ( ) ;
@ -2229,11 +2236,11 @@ void QBtSession::readAlerts() {
qApp - > exit ( ) ;
qApp - > exit ( ) ;
return ;
return ;
}
}
# endif // DISABLE_GUI
# endif // DISABLE_GUI
}
}
}
}
}
}
else if ( save_resume_data_alert * p = dynamic_cast < save_resume_data_alert * > ( a . get ( ) ) ) {
else if ( save_resume_data_alert * p = dynamic_cast < save_resume_data_alert * > ( a ) ) {
const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ;
const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ;
const QTorrentHandle h ( p - > handle ) ;
const QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) & & p - > resume_data ) {
if ( h . is_valid ( ) & & p - > resume_data ) {
@ -2251,7 +2258,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( file_renamed_alert * p = dynamic_cast < file_renamed_alert * > ( a . get ( ) ) ) {
else if ( file_renamed_alert * p = dynamic_cast < file_renamed_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
if ( h . num_files ( ) > 1 ) {
if ( h . num_files ( ) > 1 ) {
@ -2274,7 +2281,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( torrent_deleted_alert * p = dynamic_cast < torrent_deleted_alert * > ( a . get ( ) ) ) {
else if ( torrent_deleted_alert * p = dynamic_cast < torrent_deleted_alert * > ( a ) ) {
qDebug ( " A torrent was deleted from the hard disk, attempting to remove the root folder too... " ) ;
qDebug ( " A torrent was deleted from the hard disk, attempting to remove the root folder too... " ) ;
QString hash = misc : : toQString ( p - > info_hash ) ;
QString hash = misc : : toQString ( p - > info_hash ) ;
if ( ! hash . isEmpty ( ) ) {
if ( ! hash . isEmpty ( ) ) {
@ -2296,7 +2303,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( storage_moved_alert * p = dynamic_cast < storage_moved_alert * > ( a . get ( ) ) ) {
else if ( storage_moved_alert * p = dynamic_cast < storage_moved_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
// Attempt to remove old folder if empty
// Attempt to remove old folder if empty
@ -2316,7 +2323,7 @@ void QBtSession::readAlerts() {
//h.force_recheck();
//h.force_recheck();
}
}
}
}
else if ( metadata_received_alert * p = dynamic_cast < metadata_received_alert * > ( a . get ( ) ) ) {
else if ( metadata_received_alert * p = dynamic_cast < metadata_received_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
Preferences pref ;
Preferences pref ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
@ -2365,7 +2372,7 @@ void QBtSession::readAlerts() {
}
}
}
}
else if ( file_error_alert * p = dynamic_cast < file_error_alert * > ( a . get ( ) ) ) {
else if ( file_error_alert * p = dynamic_cast < file_error_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
h . pause ( ) ;
h . pause ( ) ;
@ -2379,7 +2386,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( file_completed_alert * p = dynamic_cast < file_completed_alert * > ( a . get ( ) ) ) {
else if ( file_completed_alert * p = dynamic_cast < file_completed_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
qDebug ( " A file completed download in torrent %s " , qPrintable ( h . name ( ) ) ) ;
qDebug ( " A file completed download in torrent %s " , qPrintable ( h . name ( ) ) ) ;
if ( appendqBExtension ) {
if ( appendqBExtension ) {
@ -2393,7 +2400,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( torrent_paused_alert * p = dynamic_cast < torrent_paused_alert * > ( a . get ( ) ) ) {
else if ( torrent_paused_alert * p = dynamic_cast < torrent_paused_alert * > ( a ) ) {
if ( p - > handle . is_valid ( ) ) {
if ( p - > handle . is_valid ( ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( ! HiddenData : : hasData ( h . hash ( ) ) ) {
if ( ! HiddenData : : hasData ( h . hash ( ) ) ) {
@ -2403,7 +2410,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( tracker_error_alert * p = dynamic_cast < tracker_error_alert * > ( a . get ( ) ) ) {
else if ( tracker_error_alert * p = dynamic_cast < tracker_error_alert * > ( a ) ) {
// Level: fatal
// Level: fatal
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
@ -2421,7 +2428,7 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( tracker_reply_alert * p = dynamic_cast < tracker_reply_alert * > ( a . get ( ) ) ) {
else if ( tracker_reply_alert * p = dynamic_cast < tracker_reply_alert * > ( a ) ) {
const QTorrentHandle h ( p - > handle ) ;
const QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
qDebug ( " Received a tracker reply from %s (Num_peers=%d) " , p - > url . c_str ( ) , p - > num_peers ) ;
qDebug ( " Received a tracker reply from %s (Num_peers=%d) " , p - > url . c_str ( ) , p - > num_peers ) ;
@ -2435,7 +2442,7 @@ void QBtSession::readAlerts() {
trackersInfos [ h . hash ( ) ] = trackers_data ;
trackersInfos [ h . hash ( ) ] = trackers_data ;
}
}
}
}
else if ( tracker_warning_alert * p = dynamic_cast < tracker_warning_alert * > ( a . get ( ) ) ) {
else if ( tracker_warning_alert * p = dynamic_cast < tracker_warning_alert * > ( a ) ) {
const QTorrentHandle h ( p - > handle ) ;
const QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
// Connection was successful now but there is a warning message
// Connection was successful now but there is a warning message
@ -2448,16 +2455,16 @@ void QBtSession::readAlerts() {
qDebug ( " Received a tracker warning from %s: %s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ;
qDebug ( " Received a tracker warning from %s: %s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ;
}
}
}
}
else if ( portmap_error_alert * p = dynamic_cast < portmap_error_alert * > ( a . get ( ) ) ) {
else if ( portmap_error_alert * p = dynamic_cast < portmap_error_alert * > ( a ) ) {
addConsoleMessage ( tr ( " UPnP/NAT-PMP: Port mapping failure, message: %1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , " red " ) ;
addConsoleMessage ( tr ( " UPnP/NAT-PMP: Port mapping failure, message: %1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , " red " ) ;
//emit UPnPError(QString(p->msg().c_str()));
//emit UPnPError(QString(p->msg().c_str()));
}
}
else if ( portmap_alert * p = dynamic_cast < portmap_alert * > ( a . get ( ) ) ) {
else if ( portmap_alert * p = dynamic_cast < portmap_alert * > ( a ) ) {
qDebug ( " UPnP Success, msg: %s " , p - > message ( ) . c_str ( ) ) ;
qDebug ( " UPnP Success, msg: %s " , p - > message ( ) . c_str ( ) ) ;
addConsoleMessage ( tr ( " UPnP/NAT-PMP: Port mapping successful, message: %1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , " blue " ) ;
addConsoleMessage ( tr ( " UPnP/NAT-PMP: Port mapping successful, message: %1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , " blue " ) ;
//emit UPnPSuccess(QString(p->msg().c_str()));
//emit UPnPSuccess(QString(p->msg().c_str()));
}
}
else if ( peer_blocked_alert * p = dynamic_cast < peer_blocked_alert * > ( a . get ( ) ) ) {
else if ( peer_blocked_alert * p = dynamic_cast < peer_blocked_alert * > ( a ) ) {
boost : : system : : error_code ec ;
boost : : system : : error_code ec ;
string ip = p - > ip . to_string ( ec ) ;
string ip = p - > ip . to_string ( ec ) ;
if ( ! ec ) {
if ( ! ec ) {
@ -2465,7 +2472,7 @@ void QBtSession::readAlerts() {
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
}
}
}
}
else if ( peer_ban_alert * p = dynamic_cast < peer_ban_alert * > ( a . get ( ) ) ) {
else if ( peer_ban_alert * p = dynamic_cast < peer_ban_alert * > ( a ) ) {
boost : : system : : error_code ec ;
boost : : system : : error_code ec ;
string ip = p - > ip . address ( ) . to_string ( ec ) ;
string ip = p - > ip . address ( ) . to_string ( ec ) ;
if ( ! ec ) {
if ( ! ec ) {
@ -2473,7 +2480,7 @@ void QBtSession::readAlerts() {
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
}
}
}
}
else if ( fastresume_rejected_alert * p = dynamic_cast < fastresume_rejected_alert * > ( a . get ( ) ) ) {
else if ( fastresume_rejected_alert * p = dynamic_cast < fastresume_rejected_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
qDebug ( " /! \\ Fast resume failed for %s, reason: %s " , qPrintable ( h . name ( ) ) , p - > message ( ) . c_str ( ) ) ;
qDebug ( " /! \\ Fast resume failed for %s, reason: %s " , qPrintable ( h . name ( ) ) , p - > message ( ) . c_str ( ) ) ;
@ -2489,11 +2496,11 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( url_seed_alert * p = dynamic_cast < url_seed_alert * > ( a . get ( ) ) ) {
else if ( url_seed_alert * p = dynamic_cast < url_seed_alert * > ( a ) ) {
addConsoleMessage ( tr ( " Url seed lookup failed for url: %1, message: %2 " ) . arg ( misc : : toQString ( p - > url ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , QString : : fromUtf8 ( " red " ) ) ;
addConsoleMessage ( tr ( " Url seed lookup failed for url: %1, message: %2 " ) . arg ( misc : : toQString ( p - > url ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , QString : : fromUtf8 ( " red " ) ) ;
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
}
}
else if ( listen_succeeded_alert * p = dynamic_cast < listen_succeeded_alert * > ( a . get ( ) ) ) {
else if ( listen_succeeded_alert * p = dynamic_cast < listen_succeeded_alert * > ( a ) ) {
boost : : system : : error_code ec ;
boost : : system : : error_code ec ;
QString proto = " TCP " ;
QString proto = " TCP " ;
# if LIBTORRENT_VERSION_NUM >= 10000
# if LIBTORRENT_VERSION_NUM >= 10000
@ -2515,7 +2522,7 @@ void QBtSession::readAlerts() {
it - > force_reannounce ( ) ;
it - > force_reannounce ( ) ;
}
}
}
}
else if ( listen_failed_alert * p = dynamic_cast < listen_failed_alert * > ( a . get ( ) ) ) {
else if ( listen_failed_alert * p = dynamic_cast < listen_failed_alert * > ( a ) ) {
boost : : system : : error_code ec ;
boost : : system : : error_code ec ;
QString proto = " TCP " ;
QString proto = " TCP " ;
# if LIBTORRENT_VERSION_NUM >= 10000
# if LIBTORRENT_VERSION_NUM >= 10000
@ -2533,7 +2540,7 @@ void QBtSession::readAlerts() {
qDebug ( ) < < " Failed listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ;
qDebug ( ) < < " Failed listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ;
addConsoleMessage ( tr ( " qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4 " , " e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) . arg ( misc : : toQStringU ( p - > error . message ( ) ) ) , " red " ) ;
addConsoleMessage ( tr ( " qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4 " , " e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) . arg ( misc : : toQStringU ( p - > error . message ( ) ) ) , " red " ) ;
}
}
else if ( torrent_checked_alert * p = dynamic_cast < torrent_checked_alert * > ( a . get ( ) ) ) {
else if ( torrent_checked_alert * p = dynamic_cast < torrent_checked_alert * > ( a ) ) {
QTorrentHandle h ( p - > handle ) ;
QTorrentHandle h ( p - > handle ) ;
if ( h . is_valid ( ) ) {
if ( h . is_valid ( ) ) {
const QString hash = h . hash ( ) ;
const QString hash = h . hash ( ) ;
@ -2559,16 +2566,19 @@ void QBtSession::readAlerts() {
}
}
}
}
}
}
else if ( external_ip_alert * p = dynamic_cast < external_ip_alert * > ( a . get ( ) ) ) {
else if ( external_ip_alert * p = dynamic_cast < external_ip_alert * > ( a ) ) {
boost : : system : : error_code ec ;
boost : : system : : error_code ec ;
addConsoleMessage ( tr ( " External IP: %1 " , " e.g. External IP: 192.168.0.1 " ) . arg ( p - > external_address . to_string ( ec ) . c_str ( ) ) , " blue " ) ;
addConsoleMessage ( tr ( " External IP: %1 " , " e.g. External IP: 192.168.0.1 " ) . arg ( p - > external_address . to_string ( ec ) . c_str ( ) ) , " blue " ) ;
}
}
else if ( state_update_alert * p = dynamic_cast < state_update_alert * > ( a ) ) {
emit stateUpdate ( p - > status ) ;
}
else if ( stats_alert * p = dynamic_cast < stats_alert * > ( a ) ) {
emit statsReceived ( * p ) ;
}
} catch ( const std : : exception & e ) {
} catch ( const std : : exception & e ) {
qWarning ( ) < < " Caught exception in readAlerts(): " < < e . what ( ) ;
qWarning ( ) < < " Caught exception in readAlerts(): " < < e . what ( ) ;
}
}
a = s - > pop_alert ( ) ;
}
}
}
void QBtSession : : recheckTorrent ( const QString & hash ) {
void QBtSession : : recheckTorrent ( const QString & hash ) {
@ -2804,17 +2814,21 @@ void QBtSession::drop()
}
}
}
}
qlonglong QBtSession : : getETA ( const QString & hash ) const
qlonglong QBtSession : : getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const
{
{
return m_speedMonitor - > getETA ( hash ) ;
return m_speedMonitor - > getETA ( hash , status ) ;
}
}
quint64 QBtSession : : getAlltimeDL ( ) const {
quint64 QBtSession : : getAlltimeDL ( ) const {
return m_speedMonitor - > getAlltimeDL ( ) ;
return m_torrentStatistics - > getAlltimeDL ( ) ;
}
}
quint64 QBtSession : : getAlltimeUL ( ) const {
quint64 QBtSession : : getAlltimeUL ( ) const {
return m_speedMonitor - > getAlltimeUL ( ) ;
return m_torrentStatistics - > getAlltimeUL ( ) ;
}
void QBtSession : : postTorrentUpdate ( ) {
s - > post_torrent_updates ( ) ;
}
}
void QBtSession : : handleIPFilterParsed ( int ruleCount )
void QBtSession : : handleIPFilterParsed ( int ruleCount )