Skip to content

Commit 5539e80

Browse files
committed
Qt: Network Watch tool
Simple realtime log of p2p network activity (blocks and transactions only) - Doesn't begin logging until opened; limited to 0x400 entries (outputs) - Automatically scrolls if left at the bottom of the log; maintains position if left elsewhere - Memory-efficient circular buffer; CTransaction references become weak after they're 0x200 entries back in the log - Search function that selects all matching log entries, including ongoing
1 parent 8eed7dd commit 5539e80

File tree

7 files changed

+1109
-0
lines changed

7 files changed

+1109
-0
lines changed

src/Makefile.qt.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ QT_MOC_CPP = \
5555
qt/moc_macdockiconhandler.cpp \
5656
qt/moc_macnotificationhandler.cpp \
5757
qt/moc_modaloverlay.cpp \
58+
qt/moc_netwatch.cpp \
5859
qt/moc_notificator.cpp \
5960
qt/moc_openuridialog.cpp \
6061
qt/moc_optionsdialog.cpp \
@@ -125,6 +126,7 @@ BITCOIN_QT_H = \
125126
qt/macnotificationhandler.h \
126127
qt/macos_appnap.h \
127128
qt/modaloverlay.h \
129+
qt/netwatch.h \
128130
qt/networkstyle.h \
129131
qt/notificator.h \
130132
qt/openuridialog.h \
@@ -222,6 +224,7 @@ BITCOIN_QT_BASE_CPP = \
222224
qt/guiutil.cpp \
223225
qt/intro.cpp \
224226
qt/modaloverlay.cpp \
227+
qt/netwatch.cpp \
225228
qt/networkstyle.cpp \
226229
qt/notificator.cpp \
227230
qt/optionsdialog.cpp \

src/qt/bitcoingui.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qt/guiconstants.h>
1111
#include <qt/guiutil.h>
1212
#include <qt/modaloverlay.h>
13+
#include <qt/netwatch.h>
1314
#include <qt/networkstyle.h>
1415
#include <qt/notificator.h>
1516
#include <qt/openuridialog.h>
@@ -233,6 +234,7 @@ BitcoinGUI::~BitcoinGUI()
233234
MacDockIconHandler::cleanup();
234235
#endif
235236

237+
delete NetWatch;
236238
delete rpcConsole;
237239
}
238240

@@ -328,6 +330,9 @@ void BitcoinGUI::createActions()
328330
m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from clipboard..."), this);
329331
m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard"));
330332

333+
m_show_netwatch_action = new QAction(tr("&Watch network activity"), this);
334+
m_show_netwatch_action->setStatusTip(tr("Open p2p network watching window"));
335+
331336
openRPCConsoleAction = new QAction(tr("Node window"), this);
332337
openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console"));
333338
// initially disable the debug window menu item
@@ -372,6 +377,7 @@ void BitcoinGUI::createActions()
372377
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
373378
connect(toggleHideAction, &QAction::triggered, this, &BitcoinGUI::toggleHidden);
374379
connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
380+
connect(m_show_netwatch_action, &QAction::triggered, this, &BitcoinGUI::showNetWatch);
375381
connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow);
376382
// prevents an open debug window from becoming stuck/unusable on client shutdown
377383
connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide);
@@ -520,6 +526,8 @@ void BitcoinGUI::createMenuBar()
520526
window_menu->addAction(usedReceivingAddressesAction);
521527
}
522528

529+
window_menu->addAction(m_show_netwatch_action);
530+
523531
window_menu->addSeparator();
524532
for (RPCConsole::TabTypes tab_type : rpcConsole->tabs()) {
525533
QAction* tab_action = window_menu->addAction(rpcConsole->tabTitle(tab_type));
@@ -600,6 +608,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
600608
// Show progress dialog
601609
connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress);
602610

611+
if (NetWatch) {
612+
NetWatch->setClientModel(_clientModel);
613+
}
614+
603615
rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress);
604616

605617
updateProxyIcon();
@@ -629,6 +641,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
629641
trayIconMenu->clear();
630642
}
631643
// Propagate cleared model to child objects
644+
if (NetWatch) {
645+
NetWatch->setClientModel(nullptr);
646+
}
632647
rpcConsole->setClientModel(nullptr);
633648
#ifdef ENABLE_WALLET
634649
if (walletFrame)
@@ -831,6 +846,15 @@ void BitcoinGUI::aboutClicked()
831846
dlg.exec();
832847
}
833848

849+
void BitcoinGUI::showNetWatch()
850+
{
851+
if (!NetWatch) {
852+
NetWatch = new GuiNetWatch(platformStyle, m_network_style);
853+
NetWatch->setClientModel(clientModel);
854+
}
855+
GUIUtil::bringToFront(NetWatch);
856+
}
857+
834858
void BitcoinGUI::showDebugWindow()
835859
{
836860
GUIUtil::bringToFront(rpcConsole);
@@ -1165,6 +1189,9 @@ void BitcoinGUI::closeEvent(QCloseEvent *event)
11651189
{
11661190
if(!clientModel->getOptionsModel()->getMinimizeOnClose())
11671191
{
1192+
if (NetWatch) {
1193+
NetWatch->close();
1194+
}
11681195
// close rpcConsole in case it was open to make some space for the shutdown window
11691196
rpcConsole->close();
11701197

@@ -1361,6 +1388,9 @@ void BitcoinGUI::detectShutdown()
13611388
{
13621389
if (m_node.shutdownRequested())
13631390
{
1391+
if (NetWatch) {
1392+
NetWatch->hide();
1393+
}
13641394
if(rpcConsole)
13651395
rpcConsole->hide();
13661396
qApp->quit();

src/qt/bitcoingui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <memory>
2727

2828
class ClientModel;
29+
class GuiNetWatch;
2930
class NetworkStyle;
3031
class Notificator;
3132
class OptionsModel;
@@ -151,6 +152,7 @@ class BitcoinGUI : public QMainWindow
151152
QAction* backupWalletAction = nullptr;
152153
QAction* changePassphraseAction = nullptr;
153154
QAction* aboutQtAction = nullptr;
155+
QAction* m_show_netwatch_action = nullptr;
154156
QAction* openRPCConsoleAction = nullptr;
155157
QAction* openAction = nullptr;
156158
QAction* showHelpMessageAction = nullptr;
@@ -169,6 +171,7 @@ class BitcoinGUI : public QMainWindow
169171
QSystemTrayIcon* trayIcon = nullptr;
170172
const std::unique_ptr<QMenu> trayIconMenu;
171173
Notificator* notificator = nullptr;
174+
GuiNetWatch* NetWatch = nullptr;
172175
RPCConsole* rpcConsole = nullptr;
173176
HelpMessageDialog* helpMessageDialog = nullptr;
174177
ModalOverlay* modalOverlay = nullptr;
@@ -291,6 +294,7 @@ public Q_SLOTS:
291294
void optionsClicked();
292295
/** Show about dialog */
293296
void aboutClicked();
297+
void showNetWatch();
294298
/** Show debug window */
295299
void showDebugWindow();
296300
/** Show debug window and set focus to the console */

src/qt/guiconstants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static const bool DEFAULT_SPLASHSCREEN = true;
2020

2121
/* Invalid field background style */
2222
#define STYLE_INVALID "background:#FF8080"
23+
/* Background style for active search in NetWatch */
24+
#define STYLE_ACTIVE "background:#80FF80"
2325

2426
/* Transaction list -- unconfirmed transaction */
2527
#define COLOR_UNCONFIRMED QColor(128, 128, 128)

0 commit comments

Comments
 (0)