Skip to content

Commit

Permalink
Show how much DHT nodes LIII is connected to; build fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
aliakseis committed Feb 28, 2021
1 parent 9d7c5ef commit 8847a3f
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)

project(${PROJECT_NAME} VERSION 0.1.1.3)
project(${PROJECT_NAME} VERSION 0.1.1.4)
message("Building ${PROJECT_NAME} version ${PROJECT_VERSION}")

###################################################
Expand Down
2 changes: 0 additions & 2 deletions src/3rdparty/qtsingleapplication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ set(HEADERS_TOMOC_
)

set(HEADERS_
qtlockedfile.h
QtLockedFile
QtSingleApplication
)

set(SOURCES_
qtlocalpeer.cpp
qtlockedfile.cpp
qtsingleapplication.cpp
qtsinglecoreapplication.cpp
)
Expand Down
4 changes: 2 additions & 2 deletions src/3rdparty/qtsingleapplication/qtlockedfile_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)

Qt::HANDLE mutex;
if (doCreate) {
QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
QT_WA( { mutex = CreateMutexW(NULL, FALSE, (LPCWSTR)mname.utf16()); },
{ mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
if (!mutex) {
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
return 0;
}
}
else {
QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (LPCWSTR)mname.utf16()); },
{ mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
if (!mutex) {
if (GetLastError() != ERROR_FILE_NOT_FOUND)
Expand Down
9 changes: 9 additions & 0 deletions src/common/utilities/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ QString multiArg(const QString& str, int numArgs, const QString* args)
++i;
}

// concatenate if no placeholders
if (numbersUsed.empty())
{
result = str;
for (int i = 0; i < numArgs; ++i)
result += args[i];
return result;
}

// assign an argument number to each of the %n's
QMap<int, int>::iterator j = numbersUsed.begin();
QMap<int, int>::iterator jend = numbersUsed.end();
Expand Down
6 changes: 3 additions & 3 deletions src/gui/add_links_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ AddLinksWidget::AddLinksWidget(QWidget* parent)
setIndentation(0);
setColumnCount(3);
QTreeWidgetItem* head = headerItem();
head->setText(0, "Link");
head->setText(0, tr("Link"));
head->setText(1, "");
head->setText(2, "Priority");
head->setText(2, tr("Priority"));
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::Stretch);
header()->setSectionResizeMode(2, QHeaderView::Fixed);
Expand All @@ -18,4 +18,4 @@ AddLinksWidget::AddLinksWidget(QWidget* parent)
setColumnWidth(0, 30);
setColumnWidth(1, 380);
header()->setStyleSheet("QHeaderView::section:horizontal{background-color: #f4f4f4;} QHeaderView::section:horizontal:first{border-right-color: #f4f4f4;}");
}
}
15 changes: 15 additions & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "utilities/filesystem_utils.h"

#include "torrentmanager.h"
#include "torrentslistener.h"

#include "add_links.h"
#include "preferences.h"
Expand All @@ -38,6 +39,7 @@
#include "branding.hxx"
#include "version.hxx"

#include <libtorrent/session_stats.hpp>

#if defined (Q_OS_WIN)
#include <windows.h>
Expand Down Expand Up @@ -159,6 +161,8 @@ MainWindow::MainWindow()
VERIFY(connect(ui->lblClearText, SIGNAL(clicked()), SLOT(onlblClearTextClicked())));

refreshButtons();

connect(&TorrentsListener::instance(), &TorrentsListener::sessionStats, this, &MainWindow::onSessionStats);
}

#if defined(Q_OS_WIN)
Expand Down Expand Up @@ -668,6 +672,17 @@ void MainWindow::openTorrent(QStringList magnetUrls)
addLinks(std::move(magnetUrls));
}

void MainWindow::onSessionStats(const std::vector<boost::uint64_t>& stats)
{
static int const dht_nodes_idx = libtorrent::find_metric_idx("dht.dht_nodes");
if (dht_nodes_idx >= 0 && dht_nodes_idx < stats.size())
{
const auto dht_nodes = stats[dht_nodes_idx];
::Tr::SetTr(this, &QWidget::setWindowTitle, PROJECT_FULLNAME_TRANSLATION,
QStringLiteral(" [DHT: "), dht_nodes, QStringLiteral(" nodes]"));
}
}

void MainWindow::onOverallProgress(int progress)
{
#ifdef Q_OS_WIN
Expand Down
4 changes: 4 additions & 0 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "globals.h"
#include "ui_utils/taskbar.h"

#include <boost/cstdint.hpp>

#include <vector>

namespace Ui
{
Expand Down Expand Up @@ -90,6 +93,7 @@ private Q_SLOTS:
void onActiveDownloadsNumberChanged(int number);
void showTrayNotifDwnldFinish(const QString& str);
void openTorrent(QStringList magnetUrls);
void onSessionStats(const std::vector<boost::uint64_t>& stats);
#ifdef Q_OS_MAC
QString findApplicationPath(const QString& appBrand);
#endif //Q_OS_MAC
Expand Down
8 changes: 7 additions & 1 deletion src/logic/torrentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ TorrentManager::TorrentManager()

// enable dht by default for magnets
#ifdef QT_DEBUG
QThread::yieldCurrentThread(); // try to avoid assert failure
QThread::msleep(200); // try to avoid assert failure
#endif //QT_DEBUG
Q_ASSERT(m_session->is_dht_running());

Expand All @@ -289,6 +289,10 @@ TorrentManager::TorrentManager()
VERIFY(connect(&m_resumeDataTimer, SIGNAL(timeout()), SLOT(cacheResumeTorrentsData())));
m_resumeDataTimer.setSingleShot(false);
m_resumeDataTimer.start(200000); // 3.3min
connect(&m_statsTimer, &QTimer::timeout,
std::bind(&libtorrent::session::post_session_stats, m_session.get()));
m_statsTimer.setSingleShot(false);
m_statsTimer.start(1000);
}

TorrentManager::~TorrentManager()
Expand All @@ -305,6 +309,8 @@ void TorrentManager::close()

m_closed = true;

m_statsTimer.stop();

DownloadCollectionModel* dlcModel = &DownloadCollectionModel::instance();
libtorrent::entry session_state;
m_session->save_state(session_state);
Expand Down
1 change: 1 addition & 0 deletions src/logic/torrentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private Q_SLOTS:

QMap<int, libtorrent::torrent_handle> m_idToHandle;
QTimer m_resumeDataTimer;
QTimer m_statsTimer;

bool m_closed;

Expand Down
7 changes: 7 additions & 0 deletions src/logic/torrentslistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ TorrentsListener::TorrentsListener(QObject* parent /* = 0 */)
: QObject(parent)
, m_askAboutFilesChoose(false)
{
VERIFY(qRegisterMetaType<std::vector<boost::uint64_t>>("std::vector<boost::uint64_t>"));
}

TorrentsListener::~TorrentsListener()
Expand Down Expand Up @@ -314,6 +315,12 @@ void TorrentsListener::handler(libtorrent::state_changed_alert const& a)
emit signalTryNewtask(); // TODO fine tune
}

void TorrentsListener::handler(libtorrent::session_stats_alert const& a)
{
TRACE_ALERT

emit sessionStats({std::begin(a.values), std::end(a.values)});
}

void TorrentsListener::onTorrentAdded(libtorrent::torrent_handle handle, void* userData)
{
Expand Down
7 changes: 6 additions & 1 deletion src/logic/torrentslistener.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "utilities/singleton.h"
#include "treeitem.h"

#include <vector>

// status conversion
inline ItemDC::eSTATUSDC torrentStatus2ItemDCStatus(libtorrent::torrent_status::state_t state)
{
Expand Down Expand Up @@ -42,7 +44,8 @@ inline ItemDC::eSTATUSDC torrentStatus2ItemDCStatus(libtorrent::torrent_status::
(torrent_resumed_alert)\
(torrent_removed_alert)\
(stats_alert)\
(state_changed_alert)
(state_changed_alert)\
(session_stats_alert)

#if 0

Expand Down Expand Up @@ -109,6 +112,8 @@ friend class Singleton<TorrentsListener>;

void signalTryNewtask();

void sessionStats(const std::vector<boost::uint64_t>& stats);

private:
TorrentsListener(QObject* parent = 0);
~TorrentsListener();
Expand Down

0 comments on commit 8847a3f

Please sign in to comment.