diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfaf920783e3e84864efcdda75c603bd0bd85394 --- /dev/null +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp @@ -0,0 +1,328 @@ +#include "DapChainNodeNetworkExplorer.h" + +#define DEFAULT_NODE_COLOR_HOVER QColor("#FF0000") +#define DEFAULT_NODE_COLOR QColor("#000000") +#define DEFAULT_NODE_COLOR_OFFLINE QColor("#FF0000") +#define DEFAULT_NODE_COLOR_ONLINE QColor("#00FF00") +#define DEFAULT_NODE_COLOR_SELECTED QColor("#0000FF") +#define DEFAULT_NODE_SIZE 50 +#define DEFAULT_WIDTH_LINE 3 + +DapChainNodeNetworkExplorer::DapChainNodeNetworkExplorer(QQuickItem *parent) : + QQuickPaintedItem(parent), + m_model(nullptr), + m_colorOnline(DEFAULT_NODE_COLOR_ONLINE), + m_colorOffline(DEFAULT_NODE_COLOR_OFFLINE), + m_colorSelect(DEFAULT_NODE_COLOR_SELECTED), + m_colorNormal(DEFAULT_NODE_COLOR), + m_colorFocused(DEFAULT_NODE_COLOR_HOVER), + m_widthLine(DEFAULT_WIDTH_LINE), + m_sizeNode(DEFAULT_NODE_SIZE) +{ + setAcceptedMouseButtons(Qt::RightButton); + setAcceptHoverEvents(true); +} + +void DapChainNodeNetworkExplorer::mousePressEvent(QMouseEvent* event) +{ + QQuickPaintedItem::mousePressEvent(event); + + emit selectNodeChanged(); + + if(m_currentSelectedNode.second != nullptr) + { + m_currentSelectedNode.second->State = Normal; + m_currentSelectedNode.second = nullptr; + } + + for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) + { + if(node.value().State == DapNodeState::Focused) + { + DapNodeGui* nodeData = &node.value(); + nodeData->State = DapNodeState::Selected; + m_currentSelectedNode = QPair<QString, DapNodeGui*>(node.key(), nodeData); + + const DapNodeData* currentData = m_model->getNodeData(node.key()); + emit selectNode(currentData->isCurrentNode); + update(); + return; + } + } +} + +void DapChainNodeNetworkExplorer::wheelEvent(QWheelEvent* event) +{ +// if(event->modifiers() == Qt::ControlModifier) +// { + if(event->delta() > 1) + { + if(scale() < 1.8) setScale(scale() + 0.1); + } + else + { + if(scale() > 0.5) setScale(scale() - 0.1); + } +// } +} + +void DapChainNodeNetworkExplorer::hoverMoveEvent(QHoverEvent* event) +{ + QQuickPaintedItem::hoverMoveEvent(event); + + for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) + { + DapNodeGui* nodeDataGui = &node.value(); + if(nodeDataGui->Rect.contains(event->pos()) && nodeDataGui->State != Selected) + { + nodeDataGui->State = DapNodeState::Focused; + break; + } + else if(nodeDataGui->State == DapNodeState::Focused) + { + nodeDataGui->State = DapNodeState::Normal; + break; + } + } + + update(); +} + +void DapChainNodeNetworkExplorer::paint(QPainter* painter) +{ + if(m_model == nullptr) return; + QString focusedNode = QString(); + QPen penNormal(QBrush(m_colorNormal), m_widthLine); + QPen penOnline(QBrush(m_colorOnline), m_widthLine); + QPen penOffline(QBrush(m_colorOffline), m_widthLine); + QPen penFocused(QBrush(m_colorFocused), m_widthLine); + QPen penSelected(QBrush(m_colorSelect), m_widthLine); + + painter->setBrush(QBrush("#FFFFFF")); + for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) + { + const DapNodeGui* nodeDataGui = &node.value(); + const DapNodeData* nodeData = m_model->getNodeData(node.key()); + if(nodeData == nullptr) continue; + for(int i = 0; i < nodeData->Link.count(); i++) + { + painter->setPen(penNormal); + if(nodeData->isCurrentNode) + { + if(nodeData->Status) painter->setPen(penOnline); + else painter->setPen(penOffline); + } + + painter->drawLine(nodeDataGui->Rect.center(), m_nodeMap[nodeData->Link.at(i)].Rect.center()); + } + + if(nodeDataGui->State == Focused) + { + painter->setPen(penFocused); + focusedNode = node.key(); + } + else if(nodeDataGui->State == Selected) painter->setPen(penSelected); + else painter->setPen(penNormal); + + painter->drawEllipse(nodeDataGui->Rect); + } + + if(!focusedNode.isEmpty()) + { + QPen penWhite(QBrush("#FFFFFF"), m_widthLine); + QRect rect(m_nodeMap[focusedNode].Rect.center(), QSize(200, 15)); + const DapNodeData* nodeData = m_model->getNodeData(focusedNode); + + painter->setPen(penWhite); + painter->drawRect(rect); + painter->setPen(penNormal); + painter->drawText(rect, nodeData->Alias); + } +} + +QColor DapChainNodeNetworkExplorer::getColorNormal() const +{ + return m_colorNormal; +} + +QColor DapChainNodeNetworkExplorer::getColorFocused() const +{ + return m_colorFocused; +} + +int DapChainNodeNetworkExplorer::getWidthLine() const +{ + return m_widthLine; +} + +int DapChainNodeNetworkExplorer::getSizeNode() const +{ + return m_sizeNode; +} + +DapChainNodeNetworkModel* DapChainNodeNetworkExplorer::getModel() const +{ + return m_model; +} + +int DapChainNodeNetworkExplorer::getSelectedNodePosX() const +{ + if(m_currentSelectedNode.second != nullptr) + return m_currentSelectedNode.second->Rect.center().x(); + return -1; +} + +int DapChainNodeNetworkExplorer::getSelectedNodePosY() const +{ + if(m_currentSelectedNode.second != nullptr) + return m_currentSelectedNode.second->Rect.center().y(); + return -1; +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeAddress() const +{ + if(m_currentSelectedNode.second != nullptr) + return m_currentSelectedNode.first; + return QString(); +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeAlias() const +{ + if(m_currentSelectedNode.second != nullptr) + { + const DapNodeData* nodeData = m_model->getNodeData(m_currentSelectedNode.first); + if(nodeData != nullptr) + return nodeData->Alias; + } + + return QString(); +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeIpv4() const +{ + if(m_currentSelectedNode.second != nullptr) + { + const DapNodeData* nodeData = m_model->getNodeData(m_currentSelectedNode.first); + if(nodeData != nullptr) + return nodeData->Ipv4; + } + + return QString(); +} + +QColor DapChainNodeNetworkExplorer::getColorOnline() const +{ + return m_colorOnline; +} + +QColor DapChainNodeNetworkExplorer::getColorOffline() const +{ + return m_colorOffline; +} + +QColor DapChainNodeNetworkExplorer::getColorSelect() const +{ + return m_colorSelect; +} + +void DapChainNodeNetworkExplorer::setColorNormal(const QColor& aColorNormal) +{ + if (m_colorNormal == aColorNormal) + return; + + m_colorNormal = aColorNormal; + emit colorNormalChanged(m_colorNormal); +} + +void DapChainNodeNetworkExplorer::setColorFocused(const QColor& aColorActivated) +{ + if (m_colorFocused == aColorActivated) return; + m_colorFocused = aColorActivated; + emit colorFocusedChanged(m_colorFocused); +} + +void DapChainNodeNetworkExplorer::setWidthLine(const int widthLine) +{ + if (m_widthLine == widthLine) return; + m_widthLine = widthLine; + emit widthLineChanged(m_widthLine); +} + +void DapChainNodeNetworkExplorer::setSizeNode(const int sizeNode) +{ + if (m_sizeNode == sizeNode) return; + m_sizeNode = sizeNode; + emit sizeNodeChanged(m_sizeNode); +} + +void DapChainNodeNetworkExplorer::setModel(DapChainNodeNetworkModel* aModel) +{ + if (m_model == aModel) return; + m_model = aModel; + QObject::connect(m_model, SIGNAL(changeNodeNetwork()), this, SLOT(proccessCreateGraph())); + QObject::connect(m_model, SIGNAL(changeStatusNode(QString, bool)), this, SLOT(update())); + proccessCreateGraph(); + emit modelChanged(m_model); +} + +QString DapChainNodeNetworkExplorer::getAddressByPos(const int aX, const int aY) +{ + for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) + { + if(node->Rect.contains(aX, aY)) + return node.key(); + } + + return QString(); +} + +void DapChainNodeNetworkExplorer::setColorOnline(const QColor& aColorOnline) +{ + if (m_colorOnline == aColorOnline) + return; + + m_colorOnline = aColorOnline; + emit colorOnlineChanged(m_colorOnline); +} + +void DapChainNodeNetworkExplorer::setColorOffline(const QColor& aColorOffline) +{ + if (m_colorOffline == aColorOffline) + return; + + m_colorOffline = aColorOffline; + emit colorOfflineChanged(m_colorOffline); +} + +void DapChainNodeNetworkExplorer::setColorSelect(const QColor& aColorSelect) +{ + if (m_colorSelect == aColorSelect) + return; + + m_colorSelect = aColorSelect; + emit colorSelectChanged(m_colorSelect); +} + +void DapChainNodeNetworkExplorer::proccessCreateGraph() +{ + if(m_model == nullptr) return; + + const DapNodeMap* const nodeMap = m_model->getDataMap(); + int pointX = m_sizeNode; + int heightConten = nodeMap->count() * m_sizeNode; + + qsrand(150); + for (auto node = nodeMap->constBegin(); node != nodeMap->constEnd(); node++) + { + DapNodeGui nodeData; + + int posY = (qrand() % ((heightConten + 1) - m_sizeNode) + m_sizeNode); + nodeData.Rect = QRect(pointX, posY, m_sizeNode, m_sizeNode); + pointX += m_sizeNode * 2; + + m_nodeMap[node.key()] = nodeData; + } + + setSize(QSize(pointX + m_sizeNode * 2, heightConten + m_sizeNode * 2)); + update(); +} diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h new file mode 100644 index 0000000000000000000000000000000000000000..b0017d2fa184f2267c0127927962e54be6b7f815 --- /dev/null +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h @@ -0,0 +1,109 @@ +#ifndef DAPCHAINNODENETWORKEXPLORER_H +#define DAPCHAINNODENETWORKEXPLORER_H + +#include <QQuickPaintedItem> +#include <QPainter> +#include <QVariant> +#include <QToolTip> + +#include "DapChainNodeNetworkModel.h" +#include "DapNodeType.h" + +/*! + * \brief The DapChainNodeNetworkExplorer class + * \details Class paiting DapKelvin map + * \warning To use this class it requers to send DapChainNodeNetworkModel model to slot setModel() + * \author Tagiltsev Evgenii + */ +class DapChainNodeNetworkExplorer : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(QColor colorSelect READ getColorSelect WRITE setColorSelect NOTIFY colorSelectChanged) + Q_PROPERTY(QColor colorNormal READ getColorNormal WRITE setColorNormal NOTIFY colorNormalChanged) + Q_PROPERTY(QColor colorFocused READ getColorFocused WRITE setColorFocused NOTIFY colorFocusedChanged) + Q_PROPERTY(QColor colorOnline READ getColorOnline WRITE setColorOnline NOTIFY colorOnlineChanged) + Q_PROPERTY(QColor colorOffline READ getColorOffline WRITE setColorOffline NOTIFY colorOfflineChanged) + Q_PROPERTY(int widthLine READ getWidthLine WRITE setWidthLine NOTIFY widthLineChanged) + Q_PROPERTY(int sizeNode READ getSizeNode WRITE setSizeNode NOTIFY sizeNodeChanged) + Q_PROPERTY(DapChainNodeNetworkModel* model READ getModel WRITE setModel NOTIFY modelChanged) + +public: + enum DapNodeState { + Normal, + Focused, + Selected + }; + + struct DapNodeGui { + DapNodeState State; + QRect Rect; + }; + +private: + DapChainNodeNetworkModel* m_model; + QMap<QString /*Address*/, DapNodeGui /*NodeDataGui*/> m_nodeMap; // node map for gui + QPair<QString /*Address*/, DapNodeGui* /*NodeDataGui*/> m_currentSelectedNode; // selected node + + QColor m_colorOnline; // Property color for online status + QColor m_colorOffline; // Property color for offline status + QColor m_colorSelect; // Property color for selected state + QColor m_colorNormal; // Property color for normal state + QColor m_colorFocused; // Property color for focused state + int m_widthLine; // Property width line for borders + int m_sizeNode; // Property lenght of square's side + +protected: + void mousePressEvent(QMouseEvent* event); + void wheelEvent(QWheelEvent* event); + void hoverMoveEvent(QHoverEvent* event); + +public: + explicit DapChainNodeNetworkExplorer(QQuickItem *parent = nullptr); + void paint(QPainter* painter); //!< Overload method for paiting + + QColor getColorOnline() const; //!< Get color for online nodes + QColor getColorOffline() const; //!< Get color for offline nodes + QColor getColorSelect() const; //!< Get color for selected node + QColor getColorNormal() const; //!< Get color for normal state for node + QColor getColorFocused() const; //!< Get color for focused node + int getWidthLine() const; //!< Get line width for borders + int getSizeNode() const; //!< Get lenght of square's side + + DapChainNodeNetworkModel* getModel() const; //!< Get model + + Q_INVOKABLE int getSelectedNodePosX() const; //!< Get X position for selected node + Q_INVOKABLE int getSelectedNodePosY() const; //!< Get Y position for selected node + Q_INVOKABLE QString getSelectedNodeAddress() const; //!< Get address for selected node + Q_INVOKABLE QString getSelectedNodeAlias() const; //!< Get alias for selected node + Q_INVOKABLE QString getSelectedNodeIpv4() const; //!< Get Ipv4 address for selected node + Q_INVOKABLE QString getAddressByPos(const int aX, const int aY); //!< Find node address by coordinate + +public slots: + void setColorSelect(const QColor& aColorSelect); //!< Set color for selected node + void setColorNormal(const QColor& aColorNormal); //!< Set color for normal state for node + void setColorFocused(const QColor& aColorActivated); //!< Set color for focused node + void setColorOnline(const QColor& aColorOnline); //!< Set color for online nodes + void setColorOffline(const QColor& aColorOffline); //!< Set color for offline nodes + void setWidthLine(const int widthLine); //!< Set line width for borders + void setSizeNode(const int sizeNode); //!< Set lenght of square's side + + void setModel(DapChainNodeNetworkModel* aModel); //!< Set model + +private slots: + void proccessCreateGraph(); // Slot for repainting map if it was changed + +signals: + void colorSelectChanged(QColor colorSelect); + void colorNormalChanged(QColor colorNormal); + void colorFocusedChanged(QColor colorActivated); + void colorOnlineChanged(QColor colorOnline); + void colorOfflineChanged(QColor colorOffline); + void widthLineChanged(int widthLine); + void sizeNodeChanged(int sizeNode); + void modelChanged(DapChainNodeNetworkModel* model); + + void selectNode(bool isCurrentNode); //!< Signal selected node + void selectNodeChanged(); //!< Signal deselect node +}; + +#endif // DAPCHAINNODENETWORKEXPLORER_H diff --git a/KelvinDashboardGUI/DapChainNodeNetworkModel.cpp b/KelvinDashboardGUI/DapChainNodeNetworkModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7dfd5a7156781b31e5a75e0e5658a36a64c0c376 --- /dev/null +++ b/KelvinDashboardGUI/DapChainNodeNetworkModel.cpp @@ -0,0 +1,141 @@ +#include "DapChainNodeNetworkModel.h" +#include <QDataStream> +#include <QDebug> + +#define DEFAULT_TIMER_MS 1000 + +DapChainNodeNetworkModel::DapChainNodeNetworkModel(QObject *parent) : QObject(parent) +{ + m_timerRequest = new QTimer(this); + QObject::connect(m_timerRequest, SIGNAL(timeout()), this, SIGNAL(requestNodeNetwork())); + m_timerRequest->start(DEFAULT_TIMER_MS); +} + +DapChainNodeNetworkModel& DapChainNodeNetworkModel::getInstance() +{ + static DapChainNodeNetworkModel instance; + return instance; +} + +const DapNodeMap* DapChainNodeNetworkModel::getDataMap() const +{ + return &m_nodeMap; +} + +const DapNodeData* DapChainNodeNetworkModel::getNodeData(const QString& aAddress) const +{ + const DapNodeData* nodeData = nullptr; + if(m_nodeMap.contains(aAddress)) + nodeData = const_cast<const DapNodeData*>(&m_nodeMap.find(aAddress).value()); + + return nodeData; +} + +QString DapChainNodeNetworkModel::getCurrentAddress() const +{ + for (auto node = m_nodeMap.constBegin(); node != m_nodeMap.constBegin(); node++) { + if(node.value().isCurrentNode) return node.key(); + } + + return QString(); +} + +bool DapChainNodeNetworkModel::isNodeOnline(const QString& aAddress) const +{ + if(m_nodeMap.contains(aAddress)) + return m_nodeMap[aAddress].Status; + + return false; +} + +void DapChainNodeNetworkModel::sendRequestNodeStatus(const bool aIsOnline) +{ + QString address = getCurrentAddress(); + qDebug() << "New STatus" << address << aIsOnline; + if(m_nodeMap[address].Status != aIsOnline) + emit requestNodeStatus(aIsOnline); +} + +void DapChainNodeNetworkModel::startRequest() +{ + if(m_timerRequest->isActive()) m_timerRequest->stop(); + m_timerRequest->start(); +} + +void DapChainNodeNetworkModel::startRequest(const int aTimeout) +{ + if(m_timerRequest->isActive()) m_timerRequest->stop(); + m_timerRequest->start(aTimeout); +} + +void DapChainNodeNetworkModel::stopRequest() +{ + m_timerRequest->stop(); +} + +void DapChainNodeNetworkModel::receiveNewNetwork(const QVariant& aData) +{ + if (m_data == aData) return; + m_data = aData; + m_nodeMap.clear(); + + QMap<QString, QVariant> dataMap = m_data.toMap(); + + QList<QString> addressList = dataMap.keys(); + QString currentNode; + bool currentNodeStatus = false; + foreach(auto address, addressList) + { + if(address == "current") + { + QStringList args = dataMap["current"].toStringList(); + currentNode = args.at(0); + currentNodeStatus = (args.at(1) == "NET_STATE_OFFLINE" ? false : true); + + continue; + } + m_nodeMap[address] = DapNodeData(); + } + + if(m_nodeMap.contains(currentNode)) + { + m_nodeMap[currentNode].Status = currentNodeStatus; + m_nodeMap[currentNode].isCurrentNode = true; + } + + for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) + { + DapNodeData* nodeData = &node.value(); + QStringList nodeDataList = dataMap[node.key()].toStringList(); + nodeData->Cell = nodeDataList.at(0).toUInt(); + nodeData->Ipv4 = nodeDataList.at(1); + nodeData->Alias = nodeDataList.at(2); + + if(nodeDataList.at(3).toUInt() > 0) + { + for(int i = 4; i < nodeDataList.count(); i++) + nodeData->Link.append(nodeDataList.at(i)); + } + } + + emit changeNodeNetwork(); +} + +void DapChainNodeNetworkModel::receiveNodeStatus(const QVariant& aData) +{ + QByteArray data = aData.toByteArray(); + QDataStream out(&data, QIODevice::ReadOnly); + + QString address; + bool status; + + out >> address >> status; + + if(m_nodeMap.contains(address)) + { + DapNodeData* nodeData = &m_nodeMap[address]; + nodeData->Status = status; + nodeData->isCurrentNode = true; + emit changeStatusNode(address, status); + } +} diff --git a/KelvinDashboardGUI/DapChainNodeNetworkModel.h b/KelvinDashboardGUI/DapChainNodeNetworkModel.h new file mode 100644 index 0000000000000000000000000000000000000000..db19d6ca44f773930fe22595ffc52ab26bbe1626 --- /dev/null +++ b/KelvinDashboardGUI/DapChainNodeNetworkModel.h @@ -0,0 +1,48 @@ +#ifndef DAPCHAINNODENETWORKMODEL_H +#define DAPCHAINNODENETWORKMODEL_H + +#include <QObject> +#include <QTimer> +#include <QHostAddress> +#include <QVariant> + +#include "DapNodeType.h" + +class DapChainNodeNetworkModel : public QObject +{ + Q_OBJECT + +private: + QVariant m_data; + QTimer* m_timerRequest; + +protected: + DapNodeMap m_nodeMap; + +public: + explicit DapChainNodeNetworkModel(QObject *parent = nullptr); + const DapNodeMap* getDataMap() const; + const DapNodeData* getNodeData(const QString& aAddress) const; + + QString getCurrentAddress() const; + Q_INVOKABLE static DapChainNodeNetworkModel &getInstance(); + Q_INVOKABLE bool isNodeOnline(const QString& aAddress) const; + +public slots: + void receiveNewNetwork(const QVariant& aData); + void receiveNodeStatus(const QVariant& aData); + Q_INVOKABLE void sendRequestNodeStatus(const bool aIsOnline); + Q_INVOKABLE void startRequest(); + Q_INVOKABLE void startRequest(const int aTimeout); + Q_INVOKABLE void stopRequest(); + +signals: + void changeNodeNetwork(); + void requestNodeNetwork(); + void requestNodeStatus(bool status); + void changeStatusNode(QString node, bool isOnline); + void appendNode(QMap<QString, QVariant>); +}; + + +#endif // DAPCHAINNODENETWORKMODEL_H diff --git a/KelvinDashboardGUI/DapCommandController.cpp b/KelvinDashboardGUI/DapCommandController.cpp index f89ad9b552cfd2606559634ea48fb6bff41ffcad..ace19cf633e011f401c19e785d3ffe701931419b 100755 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -145,6 +145,18 @@ void DapCommandController::processGetWalletInfo() emit sigWalletInfoChanged(name, address, balance, tokens); } +void DapCommandController::processGetNodeNetwork() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit sendNodeNetwork(reply->response().result().toVariant()); +} + +void DapCommandController::processGetNodeStatus() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit sendNodeStatus(reply->response().result().toVariant()); +} + void DapCommandController::processExecuteCommand() { qInfo() << "processGetWalletInfo()"; @@ -218,6 +230,19 @@ void DapCommandController::getWalletInfo(const QString& asWalletName) connect(reply, SIGNAL(finished()), this, SLOT(processGetWalletInfo())); } +void DapCommandController::getNodeNetwork() +{ + qInfo() << QString("getNodeNetwork()"); + DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getNodeNetwork"); + connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeNetwork())); +} + +void DapCommandController::setNodeStatus(const bool aIsOnline) +{ + /*DapRpcServiceReply *reply =*/ m_DAPRpcSocket->invokeRemoteMethod("RPCServer.setNodeStatus", aIsOnline); +// connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeStatus())); +} + void DapCommandController::executeCommand(const QString &command) { qInfo() << QString("rpc executeCommand(%1)").arg(command); diff --git a/KelvinDashboardGUI/DapCommandController.h b/KelvinDashboardGUI/DapCommandController.h index 492338d5c6e5a0706f1c59ef546159fc889698da..bac1d36516aaa5b7f72291a75f0309943d4d6346 100755 --- a/KelvinDashboardGUI/DapCommandController.h +++ b/KelvinDashboardGUI/DapCommandController.h @@ -37,6 +37,10 @@ signals: void sigWalletInfoChanged(const QString& asWalletName, const QString& asWalletAddress, const QStringList& aBalance, const QStringList& aTokens); + void sendNodeNetwork(const QVariant& aData); + + void sendNodeStatus(const QVariant& aData); + void executeCommandChanged(const QString& result); void onClearLogModel(); @@ -63,6 +67,10 @@ private slots: void processGetWalletInfo(); + void processGetNodeNetwork(); + + void processGetNodeStatus(); + void processExecuteCommand(); public slots: /// Show or hide GUI client by clicking on the tray icon. @@ -86,6 +94,10 @@ public slots: void getWalletInfo(const QString& asWalletName); + void getNodeNetwork(); + + void setNodeStatus(const bool aIsOnline); + void executeCommand(const QString& command); void clearLogModel(); diff --git a/KelvinDashboardGUI/DapServiceController.cpp b/KelvinDashboardGUI/DapServiceController.cpp index dc5bae9c65e204546af082ca1534086d426c224d..aa06a764a769257135cf748e5352a2b0f2304fab 100755 --- a/KelvinDashboardGUI/DapServiceController.cpp +++ b/KelvinDashboardGUI/DapServiceController.cpp @@ -50,8 +50,11 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) connect(m_pDapCommandController, SIGNAL(executeCommandChanged(QString)), SLOT(processExecuteCommandInfo(QString))); + connect(m_pDapCommandController, SIGNAL(sendNodeNetwork(QVariant)), this, SLOT(processGetNodeNetwork(QVariant))); connect(m_pDapCommandController, SIGNAL(onLogModel()), SLOT(get())); + connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeNetwork()), this, SLOT(getNodeNetwork())); + connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeStatus(bool)), this, SLOT(setNodeStatus(bool))); } QString DapServiceController::getBrand() const @@ -173,6 +176,17 @@ void DapServiceController::getWalletInfo(const QString &asWalletName) m_pDapCommandController->getWalletInfo(asWalletName); } +void DapServiceController::getNodeNetwork() +{ + qInfo() << QString("requestNodeNetwork"); + m_pDapCommandController->getNodeNetwork(); +} + +void DapServiceController::setNodeStatus(const bool aIsOnline) +{ + m_pDapCommandController->setNodeStatus(aIsOnline); +} + void DapServiceController::processAddWallet(const QString& asWalletName, const QString& asWalletAddress) { qInfo() << QString("processAddWallet(%1, %2)").arg(asWalletName).arg(asWalletAddress); @@ -212,6 +226,12 @@ void DapServiceController::processExecuteCommandInfo(const QString &result) emit resultChanged(); } +void DapServiceController::processGetNodeNetwork(const QVariant& aData) +{ + DapChainNodeNetworkModel::getInstance().receiveNewNetwork(aData); +} + + /// Get an instance of a class. /// @return Instance of a class. DapServiceController &DapServiceController::getInstance() diff --git a/KelvinDashboardGUI/DapServiceController.h b/KelvinDashboardGUI/DapServiceController.h index fa2a17f6e34caa4cb1e946df378dfe3ec0270890..7222e0f7d20d731d8e9fdc4138c714c9ee6c0e1c 100755 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -13,6 +13,7 @@ #include "DapServiceClient.h" #include "DapLogModel.h" #include "DapChainWalletsModel.h" +#include "DapChainNodeNetworkModel.h" class DapServiceController : public QObject { @@ -92,8 +93,9 @@ signals: /// The signal is emitted when checking the existence of an already running copy of the application. void isExistenceClient(bool isExistenceClient); void sendToQML(QString); + void logCompleted(); + void sendNodeNetwork(const QVariant& aData); - void logCompleted(); private slots: /// Handling service response for receiving node logs. /// @param aNodeLogs List of node logs. @@ -109,7 +111,12 @@ private slots: void processExecuteCommandInfo(const QString& result); + void processGetNodeNetwork(const QVariant& aData); + public slots: + void getNodeNetwork(); + void setNodeStatus(const bool aIsOnline); + void get(); /// Get node logs. /// @param aiTimeStamp Timestamp start reading logging. diff --git a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp index 0530c87a1c42d979cc2653cd255cb3d1c8e46535..97be86b6950f710ec0cd8a5df5271c52e8b340cb 100755 --- a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp @@ -10,6 +10,7 @@ DapUiQmlWidgetModel::DapUiQmlWidgetModel(QObject *parent) : QAbstractListModel(p m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Wallet", "DapUiQmlWidgetChainWallet.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Logs", "DapUiQmlWidgetChainNodeLogsForm.ui.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Console cli", "DapUiQmlWidgetConsole.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Map", "DapUiQmlWidgetNodeNetworkExplorer.qml", "qrc:/Resources/Icons/add.png")); } DapUiQmlWidgetModel &DapUiQmlWidgetModel::getInstance() diff --git a/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml new file mode 100644 index 0000000000000000000000000000000000000000..d0cd5729717e2969d9beabd36d6432a4841a29e5 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml @@ -0,0 +1,198 @@ +import QtQuick 2.13 +import QtQuick.Controls 2.2 +import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.12 +import NodeNetworkExplorer 1.0 + +Page { + Rectangle { + anchors.fill: parent; +// color: "#3b3353"; + } + + RowLayout { + anchors.fill: parent + spacing: 2 + + Flickable { + id: dapExplorer + Layout.fillWidth: true + Layout.fillHeight: true + contentWidth: dapGraphWidget.width * dapGraphWidget.scale + contentHeight: dapGraphWidget.height * dapGraphWidget.scale + contentY: dapGraphWidget.height / 2 + contentX: dapGraphWidget.width / 2 + + DapUiQmlWidgetNodeNetwork { + id: dapGraphWidget + scale: 0.6 + transformOrigin: Item.TopLeft + model: dapNodeNetworkModel + colorOffline: "#eb4d4b" + colorOnline: "#6ab04c" + colorFocused: "#ff7979" + colorSelect: "#686de0" + onSelectNode: { + dapNodeNetworkMenu.x = getSelectedNodePosX(); + dapNodeNetworkMenu.y = getSelectedNodePosY(); + + if(dapNodeNetworkModel.isNodeOnline(getSelectedNodeAddress())) + dapRadioButtonOnline.checked = true; + else + dapRadioButtonOffline.checked = true; + + dapMenuItemStatus.enabled = isCurrentNode; + dapNodeNetworkMenu.visible = true; + } + onSelectNodeChanged: { + dapNodeNetworkDescription.visible = false; + } + + Menu { + id: dapNodeNetworkMenu + MenuItem { + id: dapMenuItemDetails + text: qsTr("Show detalies") + onTriggered: { + dapNodeNetworkDescription.visible = true; + dapDescriptionModel.get(0).name = dapGraphWidget.getSelectedNodeAddress(); + dapDescriptionModel.get(1).name = dapGraphWidget.getSelectedNodeAlias(); + dapDescriptionModel.get(2).name = dapGraphWidget.getSelectedNodeIpv4(); + } + } + + MenuItem { + id: dapMenuItemStatus + text: qsTr("Set status") + onTriggered: { + dapWidgetNodeStatus.visible = true; + } + } + } + } + } + + + Rectangle { + id: dapNodeNetworkDescription + Layout.fillWidth: true + Layout.fillHeight: true + visible: false + color: "#eaecef" + + ListModel { + id: dapDescriptionModel + ListElement { name: ""; category: "Address"; } + ListElement { name: ""; category: "Alias"; } + ListElement { name: ""; category: "Ipv4"; } + } + + ListView { + anchors.fill: parent + model: dapDescriptionModel + delegate: Text {text: name; font.pixelSize: 18 } + section.property: "category" + section.criteria: ViewSection.FullString + section.delegate: dapCategory + + header: Rectangle { + width: parent.width + height: rowContent.height + RowLayout { + id: rowContent + Button { + text: "X" + onClicked: { + dapNodeNetworkDescription.visible = false; + } + } + + Text { + Layout.rowSpan: 1 + verticalAlignment: Qt.AlignVCenter + horizontalAlignment: Qt.AlignHCenter + text: qsTr("Description") + } + } + + } + } + + + Component { + id: dapCategory + Rectangle { + width: dapNodeNetworkDescription.width + height: childrenRect.height + color: "#0000FF" + + Text { + color: "#FFFFFF" + text: section + font.bold: true + font.pixelSize: 20 + } + } + } + } + } + + Rectangle + { + id: dapWidgetNodeStatus + anchors.fill: parent + visible: false + color: "#B3B2B1" + opacity: 0.6 + } + + Rectangle { + anchors.centerIn: parent + visible: dapWidgetNodeStatus.visible + width: contentLayout.width + height: contentLayout.height + border.color: "#F3F2F1" + border.width: 1 + + ColumnLayout { + id: contentLayout + + Text { + Layout.fillWidth: true + leftPadding: 30 + rightPadding: 30 + topPadding: 15 + font.pointSize: 16 + text: qsTr("Choose status") + } + + RadioButton { + id: dapRadioButtonOffline + Layout.alignment: Qt.AlignCenter + text: qsTr("Offline") + onToggled: { + dapNodeNetworkModel.sendRequestNodeStatus(false); + } + } + + RadioButton { + id: dapRadioButtonOnline + Layout.alignment: Qt.AlignCenter + text: qsTr("Online") + onToggled: { + dapNodeNetworkModel.sendRequestNodeStatus(true); + } + } + + Button { + Layout.fillWidth: true + text: qsTr("Ok") + + onClicked: { + dapWidgetNodeStatus.visible = false; + } + } + } + } + +} diff --git a/KelvinDashboardGUI/KelvinDashboardGUI.pro b/KelvinDashboardGUI/KelvinDashboardGUI.pro index 9ab746e33499dd0f985b849220d689ba6798d0b0..46a8b6e30709ae62f6a2598d2a7efd113a4bf2d6 100755 --- a/KelvinDashboardGUI/KelvinDashboardGUI.pro +++ b/KelvinDashboardGUI/KelvinDashboardGUI.pro @@ -40,6 +40,8 @@ ICON = icon.ico #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + DapChainNodeNetworkExplorer.cpp \ + DapChainNodeNetworkModel.cpp \ DapUiQmlWidgetChainTransactions.cpp \ main.cpp \ DapUiQmlWidgetChainBallance.cpp \ @@ -72,6 +74,8 @@ else: unix:!android: target.path = /opt/kelvin-dashboard/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ + DapChainNodeNetworkExplorer.h \ + DapChainNodeNetworkModel.h \ DapUiQmlWidgetChainBallance.h \ DapUiQmlWidgetChainBlockExplorer.h \ DapUiQmlWidgetChainNodeLogs.h \ diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index 59a5b4d0c0e5481421274a21efe42b9a7d7a9d64..8dface83a4ba01dfbcf4f55a5ae2a4974bbd2644 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -19,6 +19,8 @@ #include "DapLogMessage.h" #include "DapLogModel.h" #include "DapChainWalletsModel.h" +#include "DapChainNodeNetworkModel.h" +#include "DapChainNodeNetworkExplorer.h" #include <QRegExp> @@ -48,10 +50,12 @@ int main(int argc, char *argv[]) dapServiceClient.init(); controller.getNodeLogs(0, 100); controller.getWallets(); +// controller.getNodeNetwork(); qmlRegisterType<DapScreenDialog>("KelvinDashboard", 1, 0, "DapScreenDialog"); qmlRegisterType<DapScreenDialogChangeWidget>("KelvinDashboard", 1, 0, "DapScreenDialogChangeWidget"); qmlRegisterType<DapLogMessage>("LogMessage", 1, 0, "DapLogMessage"); + qmlRegisterType<DapChainNodeNetworkExplorer>("NodeNetworkExplorer", 1, 0, "DapUiQmlWidgetNodeNetwork"); qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider); QQmlApplicationEngine engine; @@ -59,6 +63,7 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("dapUiQmlWidgetModel", &DapUiQmlWidgetModel::getInstance()); engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance()); engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance()); + engine.rootContext()->setContextProperty("dapNodeNetworkModel", &DapChainNodeNetworkModel::getInstance()); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // DapSettings &settings = DapSettings::getInstance("Settings.json"); diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index 1f1f48bc6acc2346951fc024e39fc2962fca919b..1970cadf08a8b96312ee27840d1a2036237ea4c1 100755 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -37,6 +37,7 @@ <file>DapUiQmlScreenDialogRemoveWallet.qml</file> <file>DapUiQmlWidgetConsoleForm.ui.qml</file> <file>DapUiQmlWidgetConsole.qml</file> - <file>Resources/Icons/logs.png</file> + <file>Resources/Icons/logs.png</file> + <file>DapUiQmlWidgetNodeNetworkExplorer.qml</file> </qresource> </RCC> diff --git a/KelvinDashboardService/DapChainDashboardService.cpp b/KelvinDashboardService/DapChainDashboardService.cpp index 4a90de4df0cf32f7403e9fc5c48d506d5d1a0c70..59fbf897af40c20c938e2d92cfff904b23af3012 100755 --- a/KelvinDashboardService/DapChainDashboardService.cpp +++ b/KelvinDashboardService/DapChainDashboardService.cpp @@ -67,6 +67,16 @@ QStringList DapChainDashboardService::getWalletInfo(const QString &asWalletName) return m_pDapChainWalletHandler->getWalletInfo(asWalletName); } +QVariant DapChainDashboardService::getNodeNetwork() const +{ + return m_pDapChainNodeHandler->getNodeNetwork(); +} + +void DapChainDashboardService::setNodeStatus(const bool aIsOnline) +{ + m_pDapChainNodeHandler->setNodeStatus(aIsOnline); +} + QString DapChainDashboardService::sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount) { qInfo() << QString("sendToken(%1;%2;%3;%4)").arg(asWalletName).arg(asReceiverAddr).arg(asToken).arg(asAmount); diff --git a/KelvinDashboardService/DapChainDashboardService.h b/KelvinDashboardService/DapChainDashboardService.h index fcbcdf4e37688399457c1687131de3cd465fbaee..b5717ee9abace9593fda952e9b49d7543a3b4ca7 100755 --- a/KelvinDashboardService/DapChainDashboardService.h +++ b/KelvinDashboardService/DapChainDashboardService.h @@ -25,6 +25,7 @@ #include "DapChainLogHandler.h" #include "DapChainWalletHandler.h" +#include "DapChainNodeNetworkHandler.h" #include <QLocalServer> typedef class DapRpcLocalServer DapUiService; @@ -42,13 +43,14 @@ class DapChainDashboardService : public DapRpcService DapChainLogHandler * m_pDapChainLogHandler {nullptr}; DapChainWalletHandler * m_pDapChainWalletHandler {nullptr}; + + DapChainNodeNetworkHandler * m_pDapChainNodeHandler {nullptr}; + public: /// Standard Ñonstructor. explicit DapChainDashboardService(); bool start(); - - signals: /// The signal is emitted in case of successful connection of a new client. @@ -81,6 +83,9 @@ public slots: QString sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount); + QVariant getNodeNetwork() const; + + void setNodeStatus(const bool aIsOnline); }; #endif // DAPCHAINDASHBOARDSERVICE_H diff --git a/KelvinDashboardService/DapChainNodeNetworkHandler.cpp b/KelvinDashboardService/DapChainNodeNetworkHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08aa838e3845554febe8302a4bde1f0948866c25 --- /dev/null +++ b/KelvinDashboardService/DapChainNodeNetworkHandler.cpp @@ -0,0 +1,131 @@ +#include "DapChainNodeNetworkHandler.h" + + +DapChainNodeNetworkHandler::DapChainNodeNetworkHandler(QObject *parent) : QObject(parent) +{ + +} + +QVariant DapChainNodeNetworkHandler::getNodeNetwork() const +{ + QProcess process; + process.start(QString(CLI_PATH) + " node dump -net kelvin-testnet -full"); + process.waitForFinished(-1); + + QByteArray result = process.readAll(); + + QMap<QString, QVariant> nodeMap; + + if(!result.isEmpty()) + { + QStringList nodes = QString::fromStdString(result.toStdString()).split("node "); + for(int m = 1; m < nodes.count(); m++) + { + QString node = nodes.at(m); + QStringList nodeData; + QRegExp rx_node("address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4}).+" + "cell (0[xX][0-9A-F]{16}).+" + "ipv4 ((?:[0-9]{1,3}\\.){3}[0-9]{1,3}).+" + "ipv6 ::.+" + "alias (\\S+).+" + "links (\\d+).+"); + + rx_node.indexIn(node, 0); + for(int i = 2; i < 6; i++) nodeData << rx_node.cap(i); + + if(nodeData.last().toUInt() > 0) + { + QRegExp rx_links("link\\d+ address : ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); + int pos = 0; + while ((pos = rx_links.indexIn(node, pos)) != -1) + { + nodeData << rx_links.cap(1); + pos += rx_links.matchedLength(); + } + } + + nodeMap[rx_node.cap(1)] = nodeData; + } + } + + + QProcess process_status; + process_status.start(QString(CLI_PATH) + QString(" net -net kelvin-testnet get status")); + + process_status.waitForFinished(-1); + QByteArray result_status = process_status.readAll(); + + if(!result_status.isEmpty()) + { + QRegExp reg_exp("Network \"([\\w\\W]+)\" has state (\\w+).+, " + "active links \\d+ from \\d+, cur node address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); + + reg_exp.indexIn(result_status, 0); + nodeMap["current"] = QStringList() << reg_exp.cap(3) << reg_exp.cap(2); + } + + return nodeMap; + +// DapNodeMap nodeMap; + +// if(!result.isEmpty()) +// { +// QStringList nodes = QString::fromStdString(result.toStdString()).split("node "); +// for(int m = 1; m < nodes.count(); m++) +// { +// QString node = nodes.at(m); +// DapNodeData nodeData; +// QRegExp rx_node("address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4}).+" +// "cell (0[xX][0-9A-F]{16}).+" +// "ipv4 ((?:[0-9]{1,3}\\.){3}[0-9]{1,3}).+" +// "ipv6 ::.+" +// "alias (\\S+).+" +// "links (\\d+).+"); + +// rx_node.indexIn(node, 0); +// nodeData.Cell = rx_node.cap(2).toUInt(); +// nodeData.Ipv4 = rx_node.cap(3); +// nodeData.Alias = rx_node.cap(4); + +// if(rx_node.cap(5).toUInt() > 0) +// { +// QStringList nodeLink; +// QRegExp rx_links("link\\d+ address : ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); +// int pos = 0; + +// while ((pos = rx_links.indexIn(node, pos)) != -1) +// { +// nodeLink << rx_links.cap(1); +// pos += rx_links.matchedLength(); +// } +// } + +// qDebug() << rx_node.cap(1) << nodeMap.count(); +// nodeMap[rx_node.cap(1)] = nodeData; +// } +// } + +// QProcess process_status; +// process_status.start(QString(CLI_PATH) + QString(" net -net kelvin-testnet get status")); + +// process.waitForFinished(-1); +// QByteArray result_status = process_status.readAll(); + +// if(!result_status.isEmpty()) +// { +// QRegExp reg_exp("Network \"([\\w\\W]+)\" has state (\\w+) \\(target state [\\w]+\\), " +// "active links \\d+ from \\d+, cur node address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); + +// reg_exp.indexIn(result_status, 0); +// nodeMap[reg_exp.cap(2)].Status = reg_exp.cap(1) == "NET_STATE_OFFLINE" ? false : true; +// nodeMap[reg_exp.cap(2)].isCurrentNode = true; +// } +} + +void DapChainNodeNetworkHandler::setNodeStatus(const bool aIsOnline) +{ + qDebug() << "SeT new status" << aIsOnline; + QProcess process; + process.start(QString(CLI_PATH) + QString(" net -net kelvin-testnet go %1").arg(aIsOnline ? "online" : "offline")); + process.waitForFinished(-1); +} diff --git a/KelvinDashboardService/DapChainNodeNetworkHandler.h b/KelvinDashboardService/DapChainNodeNetworkHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..d487eb26da0fcdfdad6f29182aff3fbcb7abbed3 --- /dev/null +++ b/KelvinDashboardService/DapChainNodeNetworkHandler.h @@ -0,0 +1,24 @@ +#ifndef DAPCHAINNODENETWORKHANDLER_H +#define DAPCHAINNODENETWORKHANDLER_H + +#include <QObject> +#include <QProcess> +#include <QRegExp> +#include <QDebug> +#include <QDataStream> + +#include "DapNodeType.h" + +class DapChainNodeNetworkHandler : public QObject +{ + Q_OBJECT + +public: + explicit DapChainNodeNetworkHandler(QObject *parent = nullptr); + +public slots: + void setNodeStatus(const bool aIsOnline); + QVariant getNodeNetwork() const; +}; + +#endif // DAPCHAINNODENETWORKHANDLER_H diff --git a/KelvinDashboardService/KelvinDashboardService.pro b/KelvinDashboardService/KelvinDashboardService.pro index 993f36d0eeb60c8eb8eda1d37d84df55ca265cc3..69994d7c9e4ad047153916d909ef5b0d5b510b9f 100755 --- a/KelvinDashboardService/KelvinDashboardService.pro +++ b/KelvinDashboardService/KelvinDashboardService.pro @@ -21,6 +21,7 @@ ICON = icon.ico win32 { VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT DEFINES += CLI_PATH=\\\"./kelvin-node-cli.exe\\\" + DEFINES += LOG_FILE=\\\"./opt/kelvin-node/bin/kelvin-node_logs.txt\\\" } else { VERSION = $$VER_MAJ\.$$VER_MIN\-$$VER_PAT @@ -40,6 +41,7 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + DapChainNodeNetworkHandler.cpp \ main.cpp \ DapChainDashboardService.cpp \ DapChainNode.cpp \ @@ -51,6 +53,7 @@ HEADERS += \ DapChainDashboardService.h \ DapChainNode.h \ DapChainNodeCache.h \ + DapChainNodeNetworkHandler.h \ DapChainWalletHandler.h \ DapChainLogHandler.h diff --git a/libKelvinDashboardCommon/DapNodeType.h b/libKelvinDashboardCommon/DapNodeType.h new file mode 100644 index 0000000000000000000000000000000000000000..7e9991a795875a46f307d78113455d4332d23df1 --- /dev/null +++ b/libKelvinDashboardCommon/DapNodeType.h @@ -0,0 +1,59 @@ +#ifndef DAPNODETYPE_H +#define DAPNODETYPE_H + +#include <QString> +#include <QStringList> +#include <QDataStream> + +struct DapNodeData { + quint32 Cell; + QString Ipv4; + QString Alias; + QStringList Link; + bool Status; + bool isCurrentNode; + + DapNodeData() + { + Status = false; + isCurrentNode = false; + } + + DapNodeData& operator = (const DapNodeData& AData) { + Cell = AData.Cell; + Alias = AData.Alias; + Ipv4 = AData.Ipv4; + Link = AData.Link; + Status = AData.Status; + isCurrentNode = AData.isCurrentNode; + return *this; + } + + friend QDataStream& operator<< (QDataStream& out, const DapNodeData& aData) + { + out << aData.Cell + << aData.Ipv4 + << aData.Alias + << aData.Link + << aData.Status + << aData.isCurrentNode; + + return out; + } + + friend QDataStream& operator>> (QDataStream& in, DapNodeData& aData) + { + in >> aData.Cell + >> aData.Ipv4 + >> aData.Alias + >> aData.Link + >> aData.Status + >> aData.isCurrentNode; + return in; + } +}; + +typedef QMap<QString /*Address*/, DapNodeData /*Data*/> DapNodeMap; + + +#endif // DAPNODETYPE_H diff --git a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri index 0db2e7e162777bc41f088930dcea8f687b78fa77..6f2fbbbe156c9bdd4ad6e9c832f1e94c15edecb6 100755 --- a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri +++ b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri @@ -25,4 +25,5 @@ HEADERS +=\ $$PWD/DapSettingsCipher.h \ $$PWD/DapLogMessage.h \ $$PWD/DapLogModel.h \ - $$PWD/DapChainWallet.h + $$PWD/DapChainWallet.h \ + $$PWD/DapNodeType.h diff --git a/libdap b/libdap index c93ede6618819350bec1937832efbac0eb06c460..5b72cc303107680535c4591313033611b01c4a0b 160000 --- a/libdap +++ b/libdap @@ -1 +1 @@ -Subproject commit c93ede6618819350bec1937832efbac0eb06c460 +Subproject commit 5b72cc303107680535c4591313033611b01c4a0b diff --git a/libdap-crypto b/libdap-crypto index 6249887fdd5c9ed88eb26c1e10f853ea9f7001b6..ff63d762657f9687173db825705b8bf4b958abee 160000 --- a/libdap-crypto +++ b/libdap-crypto @@ -1 +1 @@ -Subproject commit 6249887fdd5c9ed88eb26c1e10f853ea9f7001b6 +Subproject commit ff63d762657f9687173db825705b8bf4b958abee diff --git a/libdap-qt b/libdap-qt index 735f35502bf533281c5924c0113130ac072b9280..948d0658552674cd2826bedae80341774a2101d1 160000 --- a/libdap-qt +++ b/libdap-qt @@ -1 +1 @@ -Subproject commit 735f35502bf533281c5924c0113130ac072b9280 +Subproject commit 948d0658552674cd2826bedae80341774a2101d1