From 54a885fb086320f3b548b20c8944f448d163b5db Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 24 Aug 2017 21:50:31 +0000 Subject: [PATCH 1/2] CValidationInterface: ValidationInterfaceUnregistering, called when being unregistered --- src/validationinterface.cpp | 5 +++++ src/validationinterface.h | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 1e07ff23ae8..83fc6e62369 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -139,6 +139,8 @@ void UnregisterSharedValidationInterface(std::shared_ptr c void UnregisterValidationInterface(CValidationInterface* callbacks) { + callbacks->ValidationInterfaceUnregistering(); + if (g_signals.m_internals) { g_signals.m_internals->Unregister(callbacks); } @@ -149,6 +151,9 @@ void UnregisterAllValidationInterfaces() if (!g_signals.m_internals) { return; } + + g_signals.m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ValidationInterfaceUnregistering(); }); + g_signals.m_internals->Clear(); } diff --git a/src/validationinterface.h b/src/validationinterface.h index 7c3ce00fbcc..0f958f4fb02 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -173,6 +173,13 @@ class CValidationInterface { * Notifies listeners that a block which builds directly on our current tip * has been received and connected to the headers tree, though not validated yet */ virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr& block) {}; + /** + * Notifies the validation interface that it is being unregistered + */ + virtual void ValidationInterfaceUnregistering() {}; + + friend void UnregisterValidationInterface(CValidationInterface*); + friend void UnregisterAllValidationInterfaces(); friend class CMainSignals; }; From 36c0dfaefca06dfc8aca681e89afec9a39deabfa Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 24 Feb 2017 03:54:50 +0000 Subject: [PATCH 2/2] 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 --- src/Makefile.qt.include | 3 + src/qt/bitcoingui.cpp | 30 ++ src/qt/bitcoingui.h | 4 + src/qt/guiconstants.h | 2 + src/qt/netwatch.cpp | 838 ++++++++++++++++++++++++++++++++++++++++ src/qt/netwatch.h | 230 +++++++++++ src/qt/rpcconsole.h | 2 + 7 files changed, 1109 insertions(+) create mode 100644 src/qt/netwatch.cpp create mode 100644 src/qt/netwatch.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 3491f07ee00..a46ddb630a2 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -56,6 +56,7 @@ QT_MOC_CPP = \ qt/moc_macdockiconhandler.cpp \ qt/moc_macnotificationhandler.cpp \ qt/moc_modaloverlay.cpp \ + qt/moc_netwatch.cpp \ qt/moc_notificator.cpp \ qt/moc_openuridialog.cpp \ qt/moc_optionsdialog.cpp \ @@ -129,6 +130,7 @@ BITCOIN_QT_H = \ qt/macnotificationhandler.h \ qt/macos_appnap.h \ qt/modaloverlay.h \ + qt/netwatch.h \ qt/networkstyle.h \ qt/notificator.h \ qt/openuridialog.h \ @@ -232,6 +234,7 @@ BITCOIN_QT_BASE_CPP = \ qt/initexecutor.cpp \ qt/intro.cpp \ qt/modaloverlay.cpp \ + qt/netwatch.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ qt/optionsdialog.cpp \ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7c22880dd1c..8f5c5aadbcc 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -239,6 +240,7 @@ BitcoinGUI::~BitcoinGUI() MacDockIconHandler::cleanup(); #endif + delete NetWatch; delete rpcConsole; } @@ -320,6 +322,9 @@ void BitcoinGUI::createActions() m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from &clipboard…"), this); m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard")); + m_show_netwatch_action = new QAction(tr("&Watch network activity"), this); + m_show_netwatch_action->setStatusTip(tr("Open p2p network watching window")); + openRPCConsoleAction = new QAction(tr("Node window"), this); openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console")); // initially disable the debug window menu item @@ -363,6 +368,7 @@ void BitcoinGUI::createActions() connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt); connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked); connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked); + connect(m_show_netwatch_action, &QAction::triggered, this, &BitcoinGUI::showNetWatch); connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow); // prevents an open debug window from becoming stuck/unusable on client shutdown connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide); @@ -509,6 +515,8 @@ void BitcoinGUI::createMenuBar() window_menu->addAction(usedReceivingAddressesAction); } + window_menu->addAction(m_show_netwatch_action); + window_menu->addSeparator(); for (RPCConsole::TabTypes tab_type : rpcConsole->tabs()) { QAction* tab_action = window_menu->addAction(rpcConsole->tabTitle(tab_type)); @@ -591,6 +599,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH // Show progress dialog connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress); + if (NetWatch) { + NetWatch->setClientModel(_clientModel); + } + rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress); updateProxyIcon(); @@ -618,6 +630,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH trayIconMenu->clear(); } // Propagate cleared model to child objects + if (NetWatch) { + NetWatch->setClientModel(nullptr); + } rpcConsole->setClientModel(nullptr); #ifdef ENABLE_WALLET if (walletFrame) @@ -856,6 +871,15 @@ void BitcoinGUI::aboutClicked() GUIUtil::ShowModalDialogAsynchronously(dlg); } +void BitcoinGUI::showNetWatch() +{ + if (!NetWatch) { + NetWatch = new GuiNetWatch(platformStyle, m_network_style); + NetWatch->setClientModel(clientModel); + } + GUIUtil::bringToFront(NetWatch); +} + void BitcoinGUI::showDebugWindow() { GUIUtil::bringToFront(rpcConsole); @@ -1218,6 +1242,9 @@ void BitcoinGUI::closeEvent(QCloseEvent *event) { if(!clientModel->getOptionsModel()->getMinimizeOnClose()) { + if (NetWatch) { + NetWatch->close(); + } // close rpcConsole in case it was open to make some space for the shutdown window rpcConsole->close(); @@ -1411,6 +1438,9 @@ void BitcoinGUI::detectShutdown() { if (m_node.shutdownRequested()) { + if (NetWatch) { + NetWatch->hide(); + } if(rpcConsole) rpcConsole->hide(); Q_EMIT quitRequested(); diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 0ae5f7331e2..1f8dbbd3525 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -28,6 +28,7 @@ #include class ClientModel; +class GuiNetWatch; class NetworkStyle; class Notificator; class OptionsModel; @@ -150,6 +151,7 @@ class BitcoinGUI : public QMainWindow QAction* backupWalletAction = nullptr; QAction* changePassphraseAction = nullptr; QAction* aboutQtAction = nullptr; + QAction* m_show_netwatch_action = nullptr; QAction* openRPCConsoleAction = nullptr; QAction* openAction = nullptr; QAction* showHelpMessageAction = nullptr; @@ -168,6 +170,7 @@ class BitcoinGUI : public QMainWindow QSystemTrayIcon* trayIcon = nullptr; const std::unique_ptr trayIconMenu; Notificator* notificator = nullptr; + GuiNetWatch* NetWatch = nullptr; RPCConsole* rpcConsole = nullptr; HelpMessageDialog* helpMessageDialog = nullptr; ModalOverlay* modalOverlay = nullptr; @@ -293,6 +296,7 @@ public Q_SLOTS: void optionsClicked(); /** Show about dialog */ void aboutClicked(); + void showNetWatch(); /** Show debug window */ void showDebugWindow(); /** Show debug window and set focus to the console */ diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index fcdf6056c95..5c6f0eb68fb 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -26,6 +26,8 @@ static const bool DEFAULT_SPLASHSCREEN = true; /* Invalid field background style */ #define STYLE_INVALID "background:#FF8080" +/* Background style for active search in NetWatch */ +#define STYLE_ACTIVE "background:#80FF80" /* Transaction list -- unconfirmed transaction */ #define COLOR_UNCONFIRMED QColor(128, 128, 128) diff --git a/src/qt/netwatch.cpp b/src/qt/netwatch.cpp new file mode 100644 index 00000000000..58a62c1215f --- /dev/null +++ b/src/qt/netwatch.cpp @@ -0,0 +1,838 @@ +// Copyright (c) 2017-2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include