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

View File

@ -49,14 +49,22 @@ enum class ParserResult {
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 {
//// 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,
//// This option try enable ssl connection from system configuration form fore information see Qt Documentation https://doc.qt.io/qt-5/qsslconfiguration.html
InitFromSystem,
//// This option force a current node geneerate self signed sertificat and work with it. For more information see a SslSrtData struct
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 {
QString country = "BY";
@ -85,129 +93,135 @@ class HEARTSHARED_EXPORT AbstractNode : public QTcpServer
public:
/**
* @brief AbstractNode
* @param ssl
* @param ptr
* @brief AbstractNode - base constructor of node.
* @param ptr - pointrt to parent Qt object, the AbstractNode class is Q_OBJECT
*/
AbstractNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr);
AbstractNode(QObject * ptr = nullptr);
~AbstractNode() override;
/**
* @brief run
* @param addres - If address is empty then serve weel be listen all addreses of all interfaces
* @param port
* @return true if all good
* @brief run - this method implement deployment a network node (server) on selected address.
* @param addres - If address is empty then server weel be listen all addreses of all interfaces else listen only selected address.
* @param port - This is port of deployment node (server)
* @return Result of deployment node (sever). (True if deploy finished successful else false).
*/
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();
/**
* @brief getInfo
* @param id of selected node
* @return pointer to information about node. if address not found return nullpt
* @brief getInfoPtr - This method return information class pointer about netwok connection.
* If Connection with id not found then return nullptr.
* @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);
/**
* @brief getInfoPtr
* @param id peer adders
* @return pointer to information about node. if address not found return nullpt
* @brief getInfoPtr - this is some that getInfoPtr(const HostAddress &id) bod it is constant implementation.
* @param id - it is network address of requested node
* @return The pointer of information about node. if address not found return nullptr
*/
virtual const AbstractNodeInfo* getInfoPtr(const HostAddress &id) const;
/**
* @brief ban
* @param target id of ban node
* @brief ban - this method set for target connection a trust property to 0 and target connection will been aborted.
* @param target - it is network address of target connection.
*/
virtual void ban(const HostAddress& target);
/**
* @brief unBan
* @param target id of unban node
* @brief unBan - this method set for target connection a trust property to 100.
* @param target - it is network address of target connection.
*/
virtual void unBan(const HostAddress& target);
/**
* @brief connectToHost - connect to host node
* @param address - address of node
* @param mode - mode see SslMode
* @brief connectToHost - connect to node (server) with address.
* @param address - This is Network address of node (server)
* @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);
/**
* @brief connectToHost - connect to host node. this method find ip address of domain befor connecting
* @param domain: address of node
* @param port - port of node
* @param mode - mode see SslMode
* @brief connectToHost - connect to node (server) with domain, bud this method find ip address of domain befor connecting
* @param domain - This is domain address of node (server)
* @param port - This is target port of node (server)
* @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);
/**
* @brief addNode - add new node for connect
* @param nodeAdderess - the network addres of a new node.
* @brief addNode - add new node (server) for this mode
* @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);
/**
* @brief removeNode - remove node
* @param nodeAdderess - the adddress of removed node.
* @brief removeNode - remove node and disconnected forom node (server)
* @param nodeAdderess - This is network adddress of removed node (server).
*/
void removeNode(const HostAddress& nodeAdderess);
/**
* @brief address - address of this node
* @return return current adders
* @brief address - Thim method return own network address of current node (server)
* @return The current network adderss
*/
HostAddress address() const;
/**
* @brief getSslConfig - configuration of this node.
* @return current ssl configuration on this nod
* @brief getSslConfig - This method return ssl configuration of current node (server).
* @return current ssl configuration on this node (server)
*/
QSslConfiguration getSslConfig() const;
/**
* @brief getMode
* @return
* @brief getMode - This method return SSL mode of corrent node (server).
* @return current mode for more information see SslMode
*/
SslMode getMode() const;
/**
* @brief getWorkState
* @return
* @brief getWorkState - This method collect general information about this server.
* For more information about returned data see getWorkState
* @return state value for more information see WorkState class
*/
virtual WorkState getWorkState() const;
/**
* @brief pareseResultToString
* @return string of pareseresult
* @brief pareseResultToString This method convert ParserResult value to string.
* @return The String value of pareseresult
*/
QString pareseResultToString(const ParserResult& parseResult) const;
/**
* @brief connectionsCount - return count fo connections (nodes with status connected)
* @return
* @brief connectionsCount - return count fo connections (connections with status connected)
* @return count valid connections.
*/
int connectionsCount() const;
/**
* @brief connectionsCount - return count of nodes with status confirmend
* @return
* @return return confirmend connections of this node (server)
*/
int confirmendCount() const;
/**
* @brief ping - ping address for testing
* @param address - address of other node
* @return true if ping sendet
* @brief ping This method send ping package to address for testing connection
* @param address This is address of target node (server)
* @return true if ping sendet successful.
*/
bool ping( const HostAddress& address);
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);
protected:
@ -232,7 +246,7 @@ protected:
* @brief selfSignedSslConfiguration
* @return generate new keys and use it
*/
virtual QSslConfiguration selfSignedSslConfiguration();
virtual QSslConfiguration selfSignedSslConfiguration( const SslSrtData& = {});
/**
* @brief createNodeInfo
@ -347,12 +361,30 @@ protected:
*/
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
* @param mode
* @brief useSystemSslConfiguration - This method reconfigure current node to use sslConfig.
* @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

View File

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

View File

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

View File

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

View File

@ -37,10 +37,9 @@ public:
/**
* @brief BaseNode
* @param mode
* @param ptr
*/
NetworkNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr);
NetworkNode(QObject * ptr = nullptr);
~NetworkNode() override;
/**
@ -56,10 +55,11 @@ public:
* @brief run server on address an port with local name of storage of keys
* @param addres - network address 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
*/
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.
@ -68,7 +68,7 @@ public:
/**
* @brief ping - ping node by node id
* @param address
* @param id
* @return
*/
bool ping( const BaseId& id);
@ -89,14 +89,14 @@ protected:
* @return true if data sendet seccussful
*/
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,
const Header *req = nullptr) override;
const Header *req = nullptr) override;
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,
const Header *req = nullptr) override;
const Header *req = nullptr) override;
/**
* @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 initialize database
- [X] Support work in database
- [ ] Sopport decentralized network mode
- [ ] Support decentralized network mode
### AbstractNode level (1)
### AbstractNode level (0)
#### Description
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
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
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.
INPUT = Heart \
Doc
Doc \
README.md
# 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
# 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