16#include <QSslConfiguration>
17#include <easyssl/icertificate.h>
20#include <QAbstractSocket>
21#include <QFutureWatcher>
23#include <QSharedPointer>
31#include "heart_global.h"
80#define CRITICAL_ERROOR -50
81#define LOGICK_ERROOR -20
82#define REQUEST_ERROR -5
83#define NOTSUPPORT_ERROR -1
85#define BIG_DATA_HASH_ID 0xFFFF
141 virtual bool run(
const QString& addres,
unsigned short port);
149 QSharedPointer<QH::iParser>
selectParser(
unsigned short cmd,
158 QSharedPointer<QH::iParser>
selectParser(
const QString& type,
167 QSharedPointer<QH::iParser>
selectParser(
const QString& type,
210 const Header *req =
nullptr);
220 const Header *req =
nullptr);
270 bool addNode(
const QString &domain,
unsigned short port,
300 QSslConfiguration getSslConfig()
const;
348 bool sheduleTask(
const QSharedPointer<AbstractTask>& task);
384 const QList<QSslError> &ignoreSslErrors()
const;
392 bool addApiParser(
const QSharedPointer<iParser>& parser);
444 void setIgnoreSslErrors(
const QList<QSslError> &newIgnoreSslErrors);
451 virtual QSslConfiguration selfSignedSslConfiguration(
const EasySSL::SslSrtData& data = {});
471 virtual bool registerSocket(QAbstractSocket *socket,
const HostAddress* address =
nullptr);
482 virtual bool sendPackage(
const Package &pkg, QAbstractSocket *target)
const;
488 virtual QString getWorkStateString()
const;
494 virtual QString connectionState()
const;
500 QList<HostAddress> banedList()
const;
515 void incomingConnection(qintptr handle)
override final;
523 virtual bool changeTrust(
const HostAddress&
id,
int diff);
536 bool useSelfSignedSslConfiguration(
const EasySSL::SslSrtData& crtData);
545 bool useSystemSslConfiguration(QSslConfiguration config = QSslConfiguration::defaultConfiguration());
560 QHash<HostAddress, AbstractNodeInfo *> connections()
const;
583 void prepareForDelete()
override;
599 QList<HostAddress> connectionsList()
const;
606 QList<HostAddress> activeConnectionsList()
const;
632 template<
class ApiType,
class ... Args >
634 return addApiParserImpl(QSharedPointer<ApiType>::create(
this, std::forward<Args>(arg)...)).template staticCast<ApiType>();
643 template<
class ApiType,
class ... Args >
645 return addApiParserImpl(QSharedPointer<ApiType>::create(
this, std::forward<Args>(arg)...));
653 virtual void receivePing(
const QSharedPointer<QH::PKG::Ping>& ping);;
663 QAbstractSocket::SocketError errorCode,
664 QString errorString);
674 virtual void handleSslErrorOcurred(QH::SslSocket *scket,
const QSslError& error);
692 void handleWorkerStoped();
704 void handleBeginWork(QSharedPointer<QH::AbstractTask> work);
713 void handleSslErrorOcurredPrivate(QH::SslSocket *sender,
const QList<QSslError> & errors);
729 const QSharedPointer<iParser> & addApiParserImpl(
const QSharedPointer<QH::iParser>& parserObject);
732 ParserResult parsePackage(
const QSharedPointer<PKG::AbstractData> &pkg,
742 QSharedPointer<PKG::AbstractData>
743 genPackage(
unsigned short cmd,
749 bool listen(
const HostAddress& address = HostAddress::Any);
768 void initThreadId()
const;
773 void initThreadPool();
778 void deinitThreadPool();
784 QSslConfiguration _ssl;
785 QList<QSslError> _ignoreSslErrors;
787 QHash<HostAddress, AbstractNodeInfo*> _connections;
788 QHash<HostAddress, ReceiveData*> _receiveData;
799 QSet<QFutureWatcher <bool>*> _workers;
800 bool _sendBadRequestErrors =
true;
801 bool _closeConnectionAfterBadRequest =
false;
803 mutable QMutex _connectionsMutex;
804 mutable QMutex _confirmNodeMutex;
805 mutable QMutex _threadPoolMutex;
806 mutable QMutex _workersMutex;
808 QThreadPool *_threadPool =
nullptr;
The APIVersionParser class This is main parser forthe main command. This parsers work only with the A...
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send...
friend class AbstractNodeParser
int sheduledTaskCount() const
sheduledTaskCount This method return count of sheduled tasks.
QSharedPointer< ApiType > addApiParserNative(Args &&... arg)
addApiParserNative This is template metod that add sipport of new apiparser ApiType
friend class BigDataParserOld
bool fSendBadRequestErrors() const
fSendBadRequestErrors This property enable or disable sending feedback to connected node when them se...
QSharedPointer< QH::iParser > selectParser(unsigned short cmd, AbstractNodeInfo *sender) const
selectParser This method select parser by command and sender.
bool removeNode(const HostAddress &nodeAdderess)
removeNode - Remove node and disconnected forom node (server).
virtual void stop()
stop - Stopped this node and close all network connections.
friend class AbstractNodeParserOld
bool sheduleTask(const QSharedPointer< AbstractTask > &task)
sheduleTask This method shedule execute task on this node.
static QThread * mainThreadID()
mainThreadID This method return the pointer to main thread
bool addApiParser(const QSharedPointer< iParser > &parser)
addApiParser This method add new Api parser for this node.
bool addNode(const HostAddress &address)
addNode - Connect to node (server) with address.
void removeTask(int taskId)
removeTask This method remove task from sheduler.
virtual void ban(const HostAddress &target)
ban - This method set for target connection a trust property to 0 and target connection will been abo...
HostAddress address() const
address - Thim method return own network address of current node (server).
friend class BigDataParser
NodeType
The NodeType enum contains types of the node. By default node contains only 3 types.
@ 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.
const QSharedPointer< iParser > & addApiParser(Args &&... arg)
addApiParser This is template metod that add sipport of new apiparser ApiType
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.
SslMode getMode() const
getMode - This method return SSL mode of corrent node (server).
AbstractNode(QObject *ptr=nullptr)
AbstractNode - Base constructor of node.
virtual WorkState getWorkState() const
getWorkState - This method collect general information about this server. For more information about ...
virtual AbstractNodeInfo * getInfoPtr(const HostAddress &id)
getInfoPtr - This method return information class pointer about netwok connection....
void sigNoLongerSupport(const QString &ApiKey, unsigned short version)
sigNoLongerSupport is some as a APIVersionParser::sigNoLongerSupport. This signal just retronslate th...
friend class WebSocketController
void setSendBadRequestErrors(bool value)
setSendBadRequestErrors This method enable or disable the fSendBadRequestErrors property.
virtual bool run(const QString &addres, unsigned short port)
run This method implement deployment a network node (server) on selected address.
virtual void unBan(const HostAddress &target)
unBan - This method set for target connection a trust property to 100.
bool ping(const HostAddress &address)
ping This method send ping package to address for testing connection.
void setCloseConnectionAfterBadRequest(bool value)
setSendBadRequestErrors This method enable or disable the fcloseConnectionAfterBadRequest property.
int confirmendCount() const
connectionsCount - Return count of nodes with status confirmend.
bool fCloseConnectionAfterBadRequest() const
fCloseConnectionAfterBadRequest This propery enable or disable droping connection after badRequests....
int connectionsCount() const
connectionsCount - Return count fo connections (connections with status connected)
friend class SocketFactory
virtual unsigned int sendData(const PKG::AbstractData *resp, const HostAddress &address, const Header *req=nullptr)
sendData This method send data object another to node
void requestError(unsigned char code, QString msg)
requestError This signal emited when client or node received from remoute server or node the BadReque...
virtual NodeType nodeType() const =0
nodeType This method should be return type of the serve.
The AbstractTask class. All tasks executed on separate thread.
The AsyncLauncher class is wraper of the Async class for support moving invokes to thread of the curr...
The DataSender class this class create a queue for sendet data to network.
The Host Address class this is wrapper of QHostAddress. Contains the NetworkAddress and network port.
The AbstractData class is provide base functions for transport data by network For create you own pac...
The Package struct. This is base structure for transporting data by network between QH nodes....
The TaskScheduler class This class contains queue of all shedule tasks.
The WorkState class is simple class with data of work state of node.
The PKG namesapce - this namespace contains all default packages of the Heart library....
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
ParserResult
The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not kn...
NodeCoonectionStatus
The AbstractNodeState enum - This is status of the known nodes or clients.
@ Connected
The node with this status has socket status is connected.
AddNodeError
The AddNodeError enum contains error code that can be occured after invoke the AbstractNode::addNode ...
@ RegisterSocketFailed
This error ocurred when you try add baned node or server is overrload.
@ HostNotFound
This error ocurred when DNS server not responce to node or node can't find the server ip address by h...
SslMode
The SslMode enum This enum contatins options for set ssl mode of node (server). For more information ...
@ NoSSL
This is not secure connection without ssl encription. It is default value of new any node see Abstrac...
The ErrorData struct is simple structure for contains data of the error.
The ReceiveData struct This is private structure for contains informaton for parse packages.