update docs (AbstractNode, all public members is descripted)

This commit is contained in:
Andrei Yankovich 2020-09-16 23:40:42 +03:00
parent 930288d3ab
commit a57905d6a7
8 changed files with 115 additions and 100 deletions

View File

@ -28,14 +28,10 @@ namespace QH {
using namespace PKG; using namespace PKG;
AbstractNode::AbstractNode(SslMode mode, QObject *ptr): AbstractNode::AbstractNode( QObject *ptr):
QTcpServer(ptr) { QTcpServer(ptr) {
_mode = mode;
_dataSender = new DataSender(); _dataSender = new DataSender();
setMode(_mode);
} }
bool AbstractNode::run(const QString &addres, unsigned short port) { bool AbstractNode::run(const QString &addres, unsigned short port) {
@ -307,12 +303,11 @@ bool AbstractNode::generateSslDataPrivate(const SslSrtData &data, QSslCertificat
return true; return true;
} }
QSslConfiguration AbstractNode::selfSignedSslConfiguration() { QSslConfiguration AbstractNode::selfSignedSslConfiguration(const SslSrtData & sslData) {
QSslConfiguration res = QSslConfiguration::defaultConfiguration(); QSslConfiguration res = QSslConfiguration::defaultConfiguration();
QSslKey pkey; QSslKey pkey;
QSslCertificate crt; QSslCertificate crt;
SslSrtData sslData;
if (!generateSslDataPrivate(sslData, crt, pkey)) { if (!generateSslDataPrivate(sslData, crt, pkey)) {
@ -914,38 +909,26 @@ SslMode AbstractNode::getMode() const {
return _mode; return _mode;
} }
bool AbstractNode::setMode(const SslMode &mode) { bool AbstractNode::useSelfSignedSslConfiguration(const SslSrtData &crtData) {
if (_mode == mode) {
return true;
}
if (isListening()) { if (isListening()) {
return false; return false;
} }
_mode = mode; _ssl = selfSignedSslConfiguration(crtData);
_mode = SslMode::InitSelfSigned;
switch (_mode) { return !_ssl.isNull();
case SslMode::InitFromSystem: { }
_ssl = QSslConfiguration::defaultConfiguration();
break;
} bool AbstractNode::disableSSL() {
case SslMode::InitSelfSigned: { if (isListening()) {
_ssl = selfSignedSslConfiguration(); return false;
break;
}
default: {
_ssl = QSslConfiguration();
break;
} }
} _mode = SslMode::NoSSL;
return true; return true;
} }
void AbstractNode::incomingData(AbstractData *pkg, const HostAddress &sender) { void AbstractNode::incomingData(AbstractData *pkg, const HostAddress &sender) {

View File

@ -49,14 +49,22 @@ enum class ParserResult {
Processed = 2 Processed = 2
}; };
/**
* @brief The SslMode enum This enum contatins options for set ssl mode of node (server)
* For more information see AbstractNode::useSelfSignedSslConfiguration AbstractNode::useSystemSslConfiguration and AbstractNode::disableSSL methods.
*/
enum class SslMode { enum class SslMode {
//// This is not secure connection without ssl encription. It is default value of new any node see AbstractNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr)
NoSSL, NoSSL,
//// This option try enable ssl connection from system configuration form fore information see Qt Documentation https://doc.qt.io/qt-5/qsslconfiguration.html
InitFromSystem, InitFromSystem,
//// This option force a current node geneerate self signed sertificat and work with it. For more information see a SslSrtData struct
InitSelfSigned InitSelfSigned
}; };
/** /**
* @brief The SslSrtData struct * @brief The SslSrtData struct This structure contains base information for generate self signed ssl certefication.
* If yo want change selfSigned certificate then use method AbstractNode::useSelfSignedSslConfiguration
*/ */
struct SslSrtData { struct SslSrtData {
QString country = "BY"; QString country = "BY";
@ -85,129 +93,135 @@ class HEARTSHARED_EXPORT AbstractNode : public QTcpServer
public: public:
/** /**
* @brief AbstractNode * @brief AbstractNode - base constructor of node.
* @param ssl * @param ptr - pointrt to parent Qt object, the AbstractNode class is Q_OBJECT
* @param ptr
*/ */
AbstractNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr); AbstractNode(QObject * ptr = nullptr);
~AbstractNode() override; ~AbstractNode() override;
/** /**
* @brief run * @brief run - this method implement deployment a network node (server) on selected address.
* @param addres - If address is empty then serve weel be listen all addreses of all interfaces * @param addres - If address is empty then server weel be listen all addreses of all interfaces else listen only selected address.
* @param port * @param port - This is port of deployment node (server)
* @return true if all good * @return Result of deployment node (sever). (True if deploy finished successful else false).
*/ */
virtual bool run(const QString& addres, unsigned short port); virtual bool run(const QString& addres, unsigned short port);
/** /**
* @brief stop stop this node and close all connections. * @brief stop - stopped this node and close all network connections.
*/ */
virtual void stop(); virtual void stop();
/** /**
* @brief getInfo * @brief getInfoPtr - This method return information class pointer about netwok connection.
* @param id of selected node * If Connection with id not found then return nullptr.
* @return pointer to information about node. if address not found return nullpt * @param id - it is network address of requested node
* @return The pointer of information about node. if address not found return nullptr
*/ */
virtual AbstractNodeInfo* getInfoPtr(const HostAddress &id); virtual AbstractNodeInfo* getInfoPtr(const HostAddress &id);
/** /**
* @brief getInfoPtr * @brief getInfoPtr - this is some that getInfoPtr(const HostAddress &id) bod it is constant implementation.
* @param id peer adders * @param id - it is network address of requested node
* @return pointer to information about node. if address not found return nullpt * @return The pointer of information about node. if address not found return nullptr
*/ */
virtual const AbstractNodeInfo* getInfoPtr(const HostAddress &id) const; virtual const AbstractNodeInfo* getInfoPtr(const HostAddress &id) const;
/** /**
* @brief ban * @brief ban - this method set for target connection a trust property to 0 and target connection will been aborted.
* @param target id of ban node * @param target - it is network address of target connection.
*/ */
virtual void ban(const HostAddress& target); virtual void ban(const HostAddress& target);
/** /**
* @brief unBan * @brief unBan - this method set for target connection a trust property to 100.
* @param target id of unban node * @param target - it is network address of target connection.
*/ */
virtual void unBan(const HostAddress& target); virtual void unBan(const HostAddress& target);
/** /**
* @brief connectToHost - connect to host node * @brief connectToHost - connect to node (server) with address.
* @param address - address of node * @param address - This is Network address of node (server)
* @param mode - mode see SslMode * @param mode - This is mode of connection see SslMode. By default using SslMode::NoSSL connection mode, it is not secure.
*/ */
virtual bool connectToHost(const HostAddress &address, SslMode mode = SslMode::NoSSL); virtual bool connectToHost(const HostAddress &address, SslMode mode = SslMode::NoSSL);
/** /**
* @brief connectToHost - connect to host node. this method find ip address of domain befor connecting * @brief connectToHost - connect to node (server) with domain, bud this method find ip address of domain befor connecting
* @param domain: address of node * @param domain - This is domain address of node (server)
* @param port - port of node * @param port - This is target port of node (server)
* @param mode - mode see SslMode * @param mode - This is mode of connection see SslMode. By default using SslMode::NoSSL connection mode, it is not secure.
*/ */
virtual bool connectToHost(const QString &domain, unsigned short port, SslMode mode = SslMode::NoSSL); virtual bool connectToHost(const QString &domain, unsigned short port, SslMode mode = SslMode::NoSSL);
/** /**
* @brief addNode - add new node for connect * @brief addNode - add new node (server) for this mode
* @param nodeAdderess - the network addres of a new node. * @param nodeAdderess - This is network addres of a new node (server).
* @note By Default This immplementation move called function into main Thread and invoke connectToHost method.
*/ */
void addNode(const HostAddress& nodeAdderess); void addNode(const HostAddress& nodeAdderess);
/** /**
* @brief removeNode - remove node * @brief removeNode - remove node and disconnected forom node (server)
* @param nodeAdderess - the adddress of removed node. * @param nodeAdderess - This is network adddress of removed node (server).
*/ */
void removeNode(const HostAddress& nodeAdderess); void removeNode(const HostAddress& nodeAdderess);
/** /**
* @brief address - address of this node * @brief address - Thim method return own network address of current node (server)
* @return return current adders * @return The current network adderss
*/ */
HostAddress address() const; HostAddress address() const;
/** /**
* @brief getSslConfig - configuration of this node. * @brief getSslConfig - This method return ssl configuration of current node (server).
* @return current ssl configuration on this nod * @return current ssl configuration on this node (server)
*/ */
QSslConfiguration getSslConfig() const; QSslConfiguration getSslConfig() const;
/** /**
* @brief getMode * @brief getMode - This method return SSL mode of corrent node (server).
* @return * @return current mode for more information see SslMode
*/ */
SslMode getMode() const; SslMode getMode() const;
/** /**
* @brief getWorkState * @brief getWorkState - This method collect general information about this server.
* @return * For more information about returned data see getWorkState
* @return state value for more information see WorkState class
*/ */
virtual WorkState getWorkState() const; virtual WorkState getWorkState() const;
/** /**
* @brief pareseResultToString * @brief pareseResultToString This method convert ParserResult value to string.
* @return string of pareseresult * @return The String value of pareseresult
*/ */
QString pareseResultToString(const ParserResult& parseResult) const; QString pareseResultToString(const ParserResult& parseResult) const;
/** /**
* @brief connectionsCount - return count fo connections (nodes with status connected) * @brief connectionsCount - return count fo connections (connections with status connected)
* @return * @return count valid connections.
*/ */
int connectionsCount() const; int connectionsCount() const;
/** /**
* @brief connectionsCount - return count of nodes with status confirmend * @brief connectionsCount - return count of nodes with status confirmend
* @return * @return return confirmend connections of this node (server)
*/ */
int confirmendCount() const; int confirmendCount() const;
/** /**
* @brief ping - ping address for testing * @brief ping This method send ping package to address for testing connection
* @param address - address of other node * @param address This is address of target node (server)
* @return true if ping sendet * @return true if ping sendet successful.
*/ */
bool ping( const HostAddress& address); bool ping( const HostAddress& address);
signals: signals:
/**
* @brief requestError - this signal emited when client or node received from remoute server or node the BadRequest package.
* @param msg - received text of remoute node (server).
*/
void requestError(QString msg); void requestError(QString msg);
protected: protected:
@ -232,7 +246,7 @@ protected:
* @brief selfSignedSslConfiguration * @brief selfSignedSslConfiguration
* @return generate new keys and use it * @return generate new keys and use it
*/ */
virtual QSslConfiguration selfSignedSslConfiguration(); virtual QSslConfiguration selfSignedSslConfiguration( const SslSrtData& = {});
/** /**
* @brief createNodeInfo * @brief createNodeInfo
@ -347,12 +361,30 @@ protected:
*/ */
virtual void incomingTcp(qintptr handle); virtual void incomingTcp(qintptr handle);
/**
* @brief useSelfSignedSslConfiguration - This method reconfigure current node to use selfSigned certificate.
* @note Befor invoke this method stop this node (server) see AbstractNode::stop. if mode will be working then this method return false.
* The self signed certificate is temp value, this is will be changed after reboot node (server)
* @param crtData - This is data for generation a new self signed certification.
* @return result of change node ssl configuration.
*/
bool useSelfSignedSslConfiguration(const SslSrtData& crtData);
/** /**
* @brief setMode - invoke this method befor run method * @brief useSystemSslConfiguration - This method reconfigure current node to use sslConfig.
* @param mode * @note Befor invoke this method stop this node (server) see AbstractNode::stop. if mode will be working then this method return false.
* @param sslConfig - This is ssl configuration ot a current node (server)
* @return result of change node ssl configuration.
*/ */
bool setMode(const SslMode &mode); bool useSystemSslConfiguration(const QSslConfiguration& sslConfig);
/**
* @brief disableSSL - this method disable ssl mode for this node
* @note Befor invoke this method stop this node (server) see AbstractNode::stop. if mode will be working then this method return false.
* @return true if changes is completed.
*/
bool disableSSL();
/** /**
* @brief incomingData - this signal invoked when node get command or ansver * @brief incomingData - this signal invoked when node get command or ansver

View File

@ -30,8 +30,8 @@
namespace QH { namespace QH {
using namespace PKG; using namespace PKG;
DataBaseNode::DataBaseNode(QH::SslMode mode, QObject *ptr): DataBaseNode::DataBaseNode(QObject *ptr):
AbstractNode(mode, ptr) { AbstractNode(ptr) {
_webSocketWorker = new WebSocketController(this); _webSocketWorker = new WebSocketController(this);

View File

@ -39,10 +39,9 @@ public:
/** /**
* @brief BaseNode * @brief BaseNode
* @param mode
* @param ptr * @param ptr
*/ */
DataBaseNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr); DataBaseNode(QObject * ptr = nullptr);
~DataBaseNode() override; ~DataBaseNode() override;
/** /**

View File

@ -39,8 +39,8 @@ namespace QH {
using namespace PKG; using namespace PKG;
NetworkNode::NetworkNode(QH::SslMode mode, QObject *ptr): NetworkNode::NetworkNode(QObject *ptr):
DataBaseNode(mode, ptr) { DataBaseNode(ptr) {
_nodeKeys = new KeyStorage(new QSecretRSA2048()); _nodeKeys = new KeyStorage(new QSecretRSA2048());
_router = new Router(); _router = new Router();

View File

@ -37,10 +37,9 @@ public:
/** /**
* @brief BaseNode * @brief BaseNode
* @param mode
* @param ptr * @param ptr
*/ */
NetworkNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr); NetworkNode(QObject * ptr = nullptr);
~NetworkNode() override; ~NetworkNode() override;
/** /**
@ -56,10 +55,11 @@ public:
* @brief run server on address an port with local name of storage of keys * @brief run server on address an port with local name of storage of keys
* @param addres - network address of node * @param addres - network address of node
* @param port - port of node * @param port - port of node
* @param localNodeName - this is locale node name. Sets name of folder with the data for current node.
* @return true if node is deployed successful * @return true if node is deployed successful
*/ */
bool run(const QString &addres, unsigned short port, bool run(const QString &addres, unsigned short port,
const QString &localNodeName) override; const QString &localNodeName) override;
/** /**
* @brief stop - this implementation stop work database and push to database all cache data. * @brief stop - this implementation stop work database and push to database all cache data.
@ -68,7 +68,7 @@ public:
/** /**
* @brief ping - ping node by node id * @brief ping - ping node by node id
* @param address * @param id
* @return * @return
*/ */
bool ping( const BaseId& id); bool ping( const BaseId& id);
@ -89,14 +89,14 @@ protected:
* @return true if data sendet seccussful * @return true if data sendet seccussful
*/ */
bool sendData(const PKG::AbstractData *resp, const BaseId &nodeId, bool sendData(const PKG::AbstractData *resp, const BaseId &nodeId,
const Header *req = nullptr) override; const Header *req = nullptr) override;
bool sendData(PKG::AbstractData *resp, const BaseId &nodeId, bool sendData(PKG::AbstractData *resp, const BaseId &nodeId,
const Header *req = nullptr) override; const Header *req = nullptr) override;
bool sendData(const PKG::AbstractData *resp, const HostAddress &nodeId, bool sendData(const PKG::AbstractData *resp, const HostAddress &nodeId,
const Header *req = nullptr) override; const Header *req = nullptr) override;
bool sendData(PKG::AbstractData *resp, const HostAddress &nodeId, bool sendData(PKG::AbstractData *resp, const HostAddress &nodeId,
const Header *req = nullptr) override; const Header *req = nullptr) override;
/** /**
* @brief initDefaultDbObjects create default cache and db writer if pointer is null * @brief initDefaultDbObjects create default cache and db writer if pointer is null

View File

@ -7,19 +7,19 @@ This library consists of two levels (AbstractNode level and DataBaseNode level).
- [X] Support ssl sockets - [X] Support ssl sockets
- [X] Support initialize database - [X] Support initialize database
- [X] Support work in database - [X] Support work in database
- [ ] Sopport decentralized network mode - [ ] Support decentralized network mode
### AbstractNode level (1) ### AbstractNode level (0)
#### Description #### Description
The AbstractNode level implement only base functons of create new work threads and parsing packages. The AbstractNode level implement only base functons of create new work threads and parsing packages.
For more information see QuasarApp Heart documentation. For more information see QuasarApp Heart documentation or QH namespace.
### DataBaseNode level (2) ### DataBaseNode level (1)
#### Description #### Description
The DataBaseNode level implement methods and packages for work with databases. This level using Qt classes for wrking with database, so for more information about suport databases see [Qt Documentation](https://doc.qt.io/qt-5/sql-driver.html). The DataBaseNode level implement methods and packages for work with databases. This level using Qt classes for wrking with database, so for more information about suport databases see [Qt Documentation](https://doc.qt.io/qt-5/sql-driver.html).
### NetworkNode level (3) ### NetworkNode level (2)
#### Description #### Description
This level is still in develop. This level is still in develop.

View File

@ -791,7 +791,8 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched. # Note: If this tag is empty the current directory is searched.
INPUT = Heart \ INPUT = Heart \
Doc Doc \
README.md
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
@ -985,7 +986,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub # (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output. # and want to reuse the introduction page also for the doxygen output.
USE_MDFILE_AS_MAINPAGE = ./README.md USE_MDFILE_AS_MAINPAGE = README.md
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Configuration options related to source browsing # Configuration options related to source browsing