Heart 1.3.848.aa44c26
Heart is base back end library for your c++ Qt projects.
|
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send and receive data messages, and work with crypto method for create a security connections betwin nodes. AbstractNode - is thread save class. More...
#include <abstractnode.h>
Public Types | |
enum | NodeType : int { Client = 0 , Node = 1 , Server = 2 } |
The NodeType enum contains types of the node. By default node contains only 3 types. More... | |
Signals | |
void | requestError (unsigned char code, QString msg) |
requestError This signal emited when client or node received from remoute server or node the BadRequest package. | |
void | sigNoLongerSupport (const QString &ApiKey, unsigned short version) |
sigNoLongerSupport is some as a APIVersionParser::sigNoLongerSupport. This signal just retronslate this signal as direct connection. | |
Public Member Functions | |
AbstractNode (QObject *ptr=nullptr) | |
AbstractNode - Base constructor of node. | |
~AbstractNode () override | |
virtual NodeType | nodeType () const =0 |
nodeType This method should be return type of the serve. | |
virtual bool | run (const QString &addres, unsigned short port) |
run This method implement deployment a network node (server) on selected address. | |
QSharedPointer< QH::iParser > | selectParser (unsigned short cmd, AbstractNodeInfo *sender) const |
selectParser This method select parser by command and sender. | |
QSharedPointer< QH::iParser > | selectParser (const QString &type, int version) const |
selectParser This method select parser by command and sender. | |
QSharedPointer< QH::iParser > | selectParser (const QString &type, AbstractNodeInfo *sender) const |
selectParser This method select parser by command and sender. | |
virtual void | stop () |
stop - Stopped this node and close all network connections. | |
virtual AbstractNodeInfo * | getInfoPtr (const HostAddress &id) |
getInfoPtr - This method return information class pointer about netwok connection. If Connection with id not found then return nullptr. | |
virtual const AbstractNodeInfo * | getInfoPtr (const HostAddress &id) const |
getInfoPtr - This is some that getInfoPtr(const HostAddress &id) bod it is constant implementation. | |
virtual void | ban (const HostAddress &target) |
ban - This method set for target connection a trust property to 0 and target connection will been aborted. | |
virtual void | unBan (const HostAddress &target) |
unBan - This method set for target connection a trust property to 100. | |
virtual unsigned int | sendData (const PKG::AbstractData *resp, const HostAddress &address, const Header *req=nullptr) |
sendData This method send data object another to node | |
virtual unsigned int | sendData (const PKG::AbstractData *resp, const AbstractNodeInfo *node, const Header *req=nullptr) |
sendData This method send data object another to node | |
bool | addNode (const HostAddress &address) |
addNode - Connect to node (server) with address. | |
bool | addNode (const HostAddress &address, const std::function< void(QH::AbstractNodeInfo *)> &action, NodeCoonectionStatus status=NodeCoonectionStatus::Connected) |
addNode This method add new peer connection to this node and execute the action when node status will be changed to the status. | |
bool | addNode (const QString &domain, unsigned short port, const std::function< void(QH::AbstractNodeInfo *)> &action=nullptr, NodeCoonectionStatus status=NodeCoonectionStatus::Connected) |
addNode This method add new peer connection to this node and execute the action when node status will be changed to the status. | |
bool | removeNode (const HostAddress &nodeAdderess) |
removeNode - Remove node and disconnected forom node (server). | |
bool | removeNode (AbstractNodeInfo *node) |
removeNode - Remove node and disconnected forom node (server). | |
HostAddress | address () const |
address - Thim method return own network address of current node (server). | |
SslMode | getMode () const |
getMode - This method return SSL mode of corrent node (server). | |
virtual WorkState | getWorkState () const |
getWorkState - This method collect general information about this server. For more information about returned data see getWorkState | |
int | connectionsCount () const |
connectionsCount - Return count fo connections (connections with status connected) | |
int | confirmendCount () const |
connectionsCount - Return count of nodes with status confirmend. | |
bool | ping (const HostAddress &address) |
ping This method send ping package to address for testing connection. | |
bool | sheduleTask (const QSharedPointer< AbstractTask > &task) |
sheduleTask This method shedule execute task on this node. | |
void | removeTask (int taskId) |
removeTask This method remove task from sheduler. | |
int | sheduledTaskCount () const |
sheduledTaskCount This method return count of sheduled tasks. | |
virtual void | badRequest (const HostAddress &address, const Header &req, const PKG::ErrorData &err, qint8 diff=REQUEST_ERROR) |
badRequest This method is send data about error of request. | |
bool | addApiParser (const QSharedPointer< iParser > &parser) |
addApiParser This method add new Api parser for this node. | |
bool | fSendBadRequestErrors () const |
fSendBadRequestErrors This property enable or disable sending feedback to connected node when them sent wrong packages. | |
void | setSendBadRequestErrors (bool value) |
setSendBadRequestErrors This method enable or disable the fSendBadRequestErrors property. | |
bool | fCloseConnectionAfterBadRequest () const |
fCloseConnectionAfterBadRequest This propery enable or disable droping connection after badRequests. By default it is true. | |
void | setCloseConnectionAfterBadRequest (bool value) |
setSendBadRequestErrors This method enable or disable the fcloseConnectionAfterBadRequest property. | |
Public Member Functions inherited from QH::SoftDelete | |
SoftDelete () | |
virtual | ~SoftDelete () |
~SoftDelete This destructor has bin crashed if the softDelete method not will be invoked before delete this object. IF you try delete this object on release distribution then you get error message only without invoked std::abort method. | |
void | softDelete () |
softDelete This method remove this object and save all changes into database. | |
Static Public Member Functions | |
static QThread * | mainThreadID () |
mainThreadID This method return the pointer to main thread | |
Protected Slots | |
virtual void | receivePing (const QSharedPointer< QH::PKG::Ping > &ping) |
receivePing This method invoked when node receive new ping object. | |
Protected Member Functions | |
virtual AbstractNodeInfo * | createNodeInfo (QAbstractSocket *socket, const HostAddress *clientAddress=nullptr) const |
createNodeInfo This method create a nodeInfo object. override this method for create your own nodeInfo objects. for more in | |
virtual bool | registerSocket (QAbstractSocket *socket, const HostAddress *address=nullptr) |
registerSocket This method registration new socket object. | |
virtual bool | sendPackage (const Package &pkg, QAbstractSocket *target) const |
sendPackage This method prepare and send to target address a package. | |
virtual QString | getWorkStateString () const |
getWorkStateString This method generate string about work state of server. | |
virtual QString | connectionState () const |
connectionState This method return string value about the cocction state. | |
QList< HostAddress > | banedList () const |
banedList This method retrun list of banned clients of nodes. | |
virtual bool | isBanned (const AbstractNodeInfo *socket) const |
isBanned This method checks if the node is banned. | |
void | incomingConnection (qintptr handle) override final |
incomingConnection This is ovverided method of QTCPServer. | |
virtual bool | changeTrust (const HostAddress &id, int diff) |
changeTrust This method change trust of connected node. | |
QHash< HostAddress, AbstractNodeInfo * > | connections () const |
connections - Return hash map of all connections of this node. | |
virtual void | nodeConfirmend (AbstractNodeInfo *node) |
nodeConfirmend This method invocked when the node status changed to "confirmend" default implementatio do nothing. | |
virtual void | nodeConnected (AbstractNodeInfo *node) |
nodeConnected This method invocked when the node status changed to "connected" default implementatio do nothing. | |
virtual void | nodeDisconnected (AbstractNodeInfo *node) |
nodeConnected This method invocked when the node status changed to "disconnected" default implementatio do nothing. | |
void | prepareForDelete () override |
prepareForDelete This method must be prepare object for delete. Override this for working main functions of this class. For more information see the SoftDelete class and SoftDelete::~SoftDelete distructor. | |
QSharedPointer< PKG::AbstractData > | prepareData (const Package &pkg, AbstractNodeInfo *sender) const |
prepareData This is private method for preparing package from the byteArray. | |
QList< HostAddress > | connectionsList () const |
connectionsList This method return list of all node connections | |
QList< HostAddress > | activeConnectionsList () const |
activeConnectionsList This method return list of actived nodes connections | |
virtual void | addNodeFailed (AddNodeError error) |
addNodeFailed This method will be invoked when trying to add new node are failed. So override this method for handle this event. | |
virtual void | nodeAddedSucessful (AbstractNodeInfo *node) |
nodeAddedSucessful This method will be invoked when new node added successful. | |
template<class ApiType , class ... Args> | |
QSharedPointer< ApiType > | addApiParserNative (Args &&... arg) |
addApiParserNative This is template metod that add sipport of new apiparser ApiType | |
template<class ApiType , class ... Args> | |
const QSharedPointer< iParser > & | addApiParser (Args &&... arg) |
addApiParser This is template metod that add sipport of new apiparser ApiType | |
virtual void | nodeErrorOccured (QH::AbstractNodeInfo *nodeInfo, QAbstractSocket::SocketError errorCode, QString errorString) |
nodeErrorOccured This slot invoked when error ocured in the nodeInfo. | |
Friends | |
class | WebSocketController |
class | SocketFactory |
class | BigDataParser |
class | BigDataParserOld |
class | AbstractNodeParser |
class | AbstractNodeParserOld |
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send and receive data messages, and work with crypto method for create a security connections betwin nodes. AbstractNode - is thread save class.
Definition at line 100 of file abstractnode.h.
enum QH::AbstractNode::NodeType : int |
The NodeType enum contains types of the node. By default node contains only 3 types.
Enumerator | |
---|---|
Client | Node with this type is general clints nodes. |
Node | Node with this ytpe is midle nodes that can works as a client and as servers. |
Server | This is node can works only as a public server. |
Definition at line 109 of file abstractnode.h.
QH::AbstractNode::AbstractNode | ( | QObject * | ptr = nullptr | ) |
AbstractNode - Base constructor of node.
ptr | - Pointrt to parent Qt object, the AbstractNode class is Q_OBJECT. |
Definition at line 52 of file abstractnode.cpp.
|
override |
Definition at line 90 of file abstractnode.cpp.
|
protected |
activeConnectionsList This method return list of actived nodes connections
Definition at line 977 of file abstractnode.cpp.
|
inlineprotected |
addApiParser This is template metod that add sipport of new apiparser ApiType
ApiType | This is type of new apiParser that will be added to the main parser. |
Args | This is argumets that will forward to the Parser constructor. |
Definition at line 644 of file abstractnode.h.
bool QH::AbstractNode::addApiParser | ( | const QSharedPointer< iParser > & | parser | ) |
addApiParser This method add new Api parser for this node.
parserObject | This is bew api parser. |
Definition at line 1016 of file abstractnode.cpp.
|
inlineprotected |
addApiParserNative This is template metod that add sipport of new apiparser ApiType
ApiType | This is type of new apiParser that will be added to the main parser. |
Args | This is argumets that will forward to the Parser constructor. |
Definition at line 633 of file abstractnode.h.
bool QH::AbstractNode::addNode | ( | const HostAddress & | address | ) |
addNode - Connect to node (server) with address.
address | - This is Network address of node (server). |
Definition at line 205 of file abstractnode.cpp.
bool QH::AbstractNode::addNode | ( | const HostAddress & | address, |
const std::function< void(QH::AbstractNodeInfo *)> & | action, | ||
NodeCoonectionStatus | status = NodeCoonectionStatus::Connected |
||
) |
addNode This method add new peer connection to this node and execute the action when node status will be changed to the status.
address | This is address of peer node. |
action | This is action that will be executed when status will changed to required status. |
status | This is required status. |
Definition at line 234 of file abstractnode.cpp.
bool QH::AbstractNode::addNode | ( | const QString & | domain, |
unsigned short | port, | ||
const std::function< void(QH::AbstractNodeInfo *)> & | action = nullptr , |
||
NodeCoonectionStatus | status = NodeCoonectionStatus::Connected |
||
) |
addNode This method add new peer connection to this node and execute the action when node status will be changed to the status.
domain | - This is domain address of node (server). |
port | - This is target port of node (server). |
action | This is action that will be executed when status will changed to required status. You can ignore this argument for disable actions after connect. |
status | This is required status. You can ignore this argument. By default it is Connected state |
Example of use:
Definition at line 248 of file abstractnode.cpp.
|
protectedvirtual |
addNodeFailed This method will be invoked when trying to add new node are failed. So override this method for handle this event.
error | This is error code that occured after invoke of the AbstractNode::addNode method |
Definition at line 991 of file abstractnode.cpp.
HostAddress QH::AbstractNode::address | ( | ) | const |
address - Thim method return own network address of current node (server).
Definition at line 318 of file abstractnode.cpp.
|
virtual |
badRequest This method is send data about error of request.
address | This is addrees of receiver. |
req | This is header of incomming request. |
err | This is message and code of error. For more information see the ErrorData struct. |
diff | This is difference of current trust (currenTrus += diff). By default diff equals REQUEST_ERROR |
Definition at line 637 of file abstractnode.cpp.
|
virtual |
ban - This method set for target connection a trust property to 0 and target connection will been aborted.
target | - It is network address of target connection. |
Definition at line 188 of file abstractnode.cpp.
|
protected |
banedList This method retrun list of banned clients of nodes.
Definition at line 699 of file abstractnode.cpp.
|
protectedvirtual |
changeTrust This method change trust of connected node.
id | This is id of select node. |
diff | This is difference of current trust (currenTrus += diff). |
Definition at line 792 of file abstractnode.cpp.
int QH::AbstractNode::confirmendCount | ( | ) | const |
connectionsCount - Return count of nodes with status confirmend.
Definition at line 726 of file abstractnode.cpp.
|
protected |
connections - Return hash map of all connections of this node.
Definition at line 1116 of file abstractnode.cpp.
int QH::AbstractNode::connectionsCount | ( | ) | const |
connectionsCount - Return count fo connections (connections with status connected)
Definition at line 713 of file abstractnode.cpp.
|
protected |
connectionsList This method return list of all node connections
Definition at line 971 of file abstractnode.cpp.
|
protectedvirtual |
connectionState This method return string value about the cocction state.
Definition at line 695 of file abstractnode.cpp.
|
protectedvirtual |
createNodeInfo This method create a nodeInfo object. override this method for create your own nodeInfo objects. for more in
socket | This is socket of network address. |
clientAddress | This parameter need to set when the socket du not contains a address or invalid. |
Definition at line 482 of file abstractnode.cpp.
bool QH::AbstractNode::fCloseConnectionAfterBadRequest | ( | ) | const |
fCloseConnectionAfterBadRequest This propery enable or disable droping connection after badRequests. By default it is true.
Definition at line 461 of file abstractnode.cpp.
bool QH::AbstractNode::fSendBadRequestErrors | ( | ) | const |
fSendBadRequestErrors This property enable or disable sending feedback to connected node when them sent wrong packages.
Definition at line 469 of file abstractnode.cpp.
|
virtual |
getInfoPtr - This method return information class pointer about netwok connection. If Connection with id not found then return nullptr.
id | - It is network address of requested node. |
Definition at line 166 of file abstractnode.cpp.
|
virtual |
getInfoPtr - This is some that getInfoPtr(const HostAddress &id) bod it is constant implementation.
id | - It is network address of requested node. |
Definition at line 178 of file abstractnode.cpp.
SslMode QH::AbstractNode::getMode | ( | ) | const |
getMode - This method return SSL mode of corrent node (server).
Definition at line 1112 of file abstractnode.cpp.
|
virtual |
getWorkState - This method collect general information about this server. For more information about returned data see getWorkState
Definition at line 670 of file abstractnode.cpp.
|
protectedvirtual |
getWorkStateString This method generate string about work state of server.
Definition at line 683 of file abstractnode.cpp.
|
finaloverrideprotected |
incomingConnection This is ovverided method of QTCPServer.
handle | This is socket handle. |
Definition at line 753 of file abstractnode.cpp.
|
protectedvirtual |
isBanned This method checks if the node is banned.
socket | This is node info object for validation. |
Definition at line 745 of file abstractnode.cpp.
|
static |
mainThreadID This method return the pointer to main thread
Definition at line 1231 of file abstractnode.cpp.
|
protectedvirtual |
nodeAddedSucessful This method will be invoked when new node added successful.
node | This is pointer to added node. |
Definition at line 1012 of file abstractnode.cpp.
|
protectedvirtual |
nodeConfirmend This method invocked when the node status changed to "confirmend" default implementatio do nothing.
node | This is address of changed node. |
Definition at line 1160 of file abstractnode.cpp.
|
protectedvirtual |
nodeConnected This method invocked when the node status changed to "connected" default implementatio do nothing.
node | This is address of changed node. |
Definition at line 1168 of file abstractnode.cpp.
|
protectedvirtual |
nodeConnected This method invocked when the node status changed to "disconnected" default implementatio do nothing.
node | This is address of changed node. |
Definition at line 1179 of file abstractnode.cpp.
|
protectedvirtual |
nodeErrorOccured This slot invoked when error ocured in the nodeInfo.
nodeInfo | This is pinter to modeInfoObject. |
errorCode | This is error code. |
errorString | This is string value of the error. |
Definition at line 1183 of file abstractnode.cpp.
|
pure virtual |
nodeType This method should be return type of the serve.
bool QH::AbstractNode::ping | ( | const HostAddress & | address | ) |
ping This method send ping package to address for testing connection.
address | This is address of target node (server). |
Definition at line 739 of file abstractnode.cpp.
|
protected |
prepareData This is private method for preparing package from the byteArray.
pkg | This is a raw package value. |
sender | This is sender of the pkg. |
Definition at line 955 of file abstractnode.cpp.
|
overrideprotectedvirtual |
prepareForDelete This method must be prepare object for delete. Override this for working main functions of this class. For more information see the SoftDelete class and SoftDelete::~SoftDelete distructor.
Implements QH::SoftDelete.
Definition at line 1120 of file abstractnode.cpp.
|
protectedvirtualslot |
receivePing This method invoked when node receive new ping object.
ping | This is ping object. |
Definition at line 1024 of file abstractnode.cpp.
|
protectedvirtual |
registerSocket This method registration new socket object.
socket | This is incomming socket pointer. |
address | This is host address of socket. By default is nullptr. Set this value for nodes created on this host. |
Definition at line 487 of file abstractnode.cpp.
bool QH::AbstractNode::removeNode | ( | AbstractNodeInfo * | node | ) |
removeNode - Remove node and disconnected forom node (server).
node | - This is removed node (server). |
Definition at line 297 of file abstractnode.cpp.
bool QH::AbstractNode::removeNode | ( | const HostAddress & | nodeAdderess | ) |
removeNode - Remove node and disconnected forom node (server).
nodeAdderess | - This is network adddress of removed node (server). |
Definition at line 288 of file abstractnode.cpp.
void QH::AbstractNode::removeTask | ( | int | taskId | ) |
removeTask This method remove task from sheduler.
taskId | This is task id that will be removed. |
Definition at line 1030 of file abstractnode.cpp.
|
signal |
requestError This signal emited when client or node received from remoute server or node the BadRequest package.
code | This is code of error. |
msg | - received text of remoute node (server). |
|
virtual |
run This method implement deployment a network node (server) on selected address.
addres | This is network address of work node or server. If address is empty then server weel be listen all addreses of all interfaces else listen only selected address. |
port | This is port of deployment node (server) |
Definition at line 108 of file abstractnode.cpp.
QSharedPointer< iParser > QH::AbstractNode::selectParser | ( | const QString & | type, |
AbstractNodeInfo * | sender | ||
) | const |
selectParser This method select parser by command and sender.
type | this is parser type. |
sender | this is node that sent this command. |
Definition at line 136 of file abstractnode.cpp.
QSharedPointer< iParser > QH::AbstractNode::selectParser | ( | const QString & | type, |
int | version | ||
) | const |
selectParser This method select parser by command and sender.
type | this is parser type. |
version | this is node that sent this command. |
Definition at line 141 of file abstractnode.cpp.
QSharedPointer< iParser > QH::AbstractNode::selectParser | ( | unsigned short | cmd, |
AbstractNodeInfo * | sender | ||
) | const |
selectParser This method select parser by command and sender.
cmd | this is command that need to parse. |
sender | this is node that sent this command. |
Definition at line 131 of file abstractnode.cpp.
|
virtual |
sendData This method send data object another to node
resp | This is pointer to sendet object. |
address | This is target addres for sending. |
req | This is header of request. |
Definition at line 591 of file abstractnode.cpp.
|
virtual |
sendData This method send data object another to node
resp | This is pointer to sendet object. |
address | This is target addres for sending. |
req | This is header of request. |
Definition at line 585 of file abstractnode.cpp.
|
protectedvirtual |
sendPackage This method prepare and send to target address a package.
pkg | This is sendet pakcage to target node. |
target | This is target node. |
Definition at line 566 of file abstractnode.cpp.
void QH::AbstractNode::setCloseConnectionAfterBadRequest | ( | bool | value | ) |
setSendBadRequestErrors This method enable or disable the fcloseConnectionAfterBadRequest property.
value | This is new value of the fcloseConnectionAfterBadRequest property. |
Definition at line 465 of file abstractnode.cpp.
void QH::AbstractNode::setSendBadRequestErrors | ( | bool | value | ) |
setSendBadRequestErrors This method enable or disable the fSendBadRequestErrors property.
value | This is new value of the sendBadRequestErrors property. |
Definition at line 473 of file abstractnode.cpp.
int QH::AbstractNode::sheduledTaskCount | ( | ) | const |
sheduledTaskCount This method return count of sheduled tasks.
Definition at line 1034 of file abstractnode.cpp.
bool QH::AbstractNode::sheduleTask | ( | const QSharedPointer< AbstractTask > & | task | ) |
sheduleTask This method shedule execute task on this node.
task | This is task that will be sheduled. |
Definition at line 1026 of file abstractnode.cpp.
|
signal |
sigNoLongerSupport is some as a APIVersionParser::sigNoLongerSupport. This signal just retronslate this signal as direct connection.
ApiKey | see the APIVersionParser::sigNoLongerSupport description |
version | see the APIVersionParser::sigNoLongerSupport description |
|
virtual |
stop - Stopped this node and close all network connections.
Definition at line 145 of file abstractnode.cpp.
|
virtual |
unBan - This method set for target connection a trust property to 100.
target | - It is network address of target connection. |
Definition at line 195 of file abstractnode.cpp.
|
friend |
Definition at line 815 of file abstractnode.h.
|
friend |
Definition at line 816 of file abstractnode.h.
|
friend |
Definition at line 813 of file abstractnode.h.
|
friend |
Definition at line 814 of file abstractnode.h.
|
friend |
Definition at line 812 of file abstractnode.h.
|
friend |
Definition at line 811 of file abstractnode.h.