Heart 1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Loading...
Searching...
No Matches
abstractnodeinfo.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2025 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef ABSTRACTNODEINFO_H
9#define ABSTRACTNODEINFO_H
10
11#include "hostaddress.h"
12#include "distversion.h"
13#include "heart_global.h"
14#include "iparser.h"
15#include <QMutex>
16#include <hostaddress.h>
17
18
19class QAbstractSocket;
20class QHostInfo;
21
22namespace QH {
23
27enum class TrustNode: unsigned char {
29 Undefined = 0xFF,
30
32 Default = 100,
33
36 Restore = 20,
37
40};
41
54
60uint qHash(NodeCoonectionStatus status);
61
67class HEARTSHARED_EXPORT AbstractNodeInfo: public QObject
68{
69 Q_OBJECT
70public:
71
77 AbstractNodeInfo(QAbstractSocket *sct = nullptr,
78 const HostAddress* address = nullptr);
82 virtual ~AbstractNodeInfo();
83
88 QAbstractSocket *sct() const;
89
93 virtual void ban();
94
99 virtual bool isBanned() const;
100
105 virtual void unBan();
106
111 virtual int trust() const;
112
117 virtual void setTrust(int trust);
118
123 virtual bool isValid() const;
124
129 virtual bool isConnected() const;
130
135 virtual void reset();
136
142 QHostInfo *info() const;
143
148 void setInfo(const QHostInfo &info);
149
155
161
167
173
177 void updateConfirmStatus();
178
183 bool isLocal() const;
184
189 void setIsLocal(bool isLocal);
190
195 void setSct(QAbstractSocket *sct);
196
201 const VersionData &version() const;
202
207 void setVersion(const VersionData &newVersion);
208
213 bool fVersionReceived() const;
214
219 void setFVersionReceived(bool newFVersionReceived);
220
225 bool fVersionDelivered() const;
226
231 void setFVersionDelivered(bool newFVersionDelivered);
232
238 QSharedPointer<QH::iParser> getParser(unsigned short cmd);
239
245 QSharedPointer<QH::iParser> getParser(const QString& type);
246
253 void addParser(unsigned short cmd, QSharedPointer<QH::iParser> parser);
254
260 void addParser(QSharedPointer<QH::iParser> parser);
261
267
272 void setMultiVersionPackages(const PackagesVersionData &newMultiVersionPackages);
273
274public slots:
280 virtual void removeSocket();
281
282signals:
283
289
295
301
310 QAbstractSocket::SocketError socketError,
311 QString message);
312
318
325
326protected:
327
333 virtual bool confirmData() const;
334
335
336private:
337
338 QHostInfo *_info = nullptr;
339 HostAddress _networkAddress;
340
341 QAbstractSocket *_sct = nullptr;
342 int _trust = static_cast<int>(TrustNode::Default);
344 bool _isLocal = false;
345
346 QHash<unsigned short, QSharedPointer<iParser>> _parsersMap;
347 QHash<QString, QSharedPointer<iParser>> _parsersKeysMap;
348 QMutex _parsersListMutex;
349
353 PackagesVersionData _multiVersionPackages;
354 VersionData _version;
355 bool _fVersionReceived = false;
356 bool _fVersionDelivered = false;
357
358};
359
360}
361
363
364#endif // ABSTRACTNODEINFO_H
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
const PackagesVersionData & multiVersionPackages() const
multiVersionPackages This is list of packages of one api package tah support multiple versions.
bool isLocal() const
isLocal return true if connection opened on this node.
virtual void reset()
reset This method reset all fields of the nodeInfo.
void setStatus(const NodeCoonectionStatus &status)
setStatus This method Sets new value of status node.
void setVersion(const VersionData &newVersion)
setVersion This method sets new version data structure.
AbstractNodeInfo(QAbstractSocket *sct=nullptr, const HostAddress *address=nullptr)
AbstractNodeInfo.
NodeCoonectionStatus status() const
status This method return status of the node connection.
void setFVersionReceived(bool newFVersionReceived)
setFVersionReceived This method change the fVersionReceived flag.
void setMultiVersionPackages(const PackagesVersionData &newMultiVersionPackages)
setMultiVersionPackages This method sets new list of multi-version packages.
virtual int trust() const
trust - Show current value of trust level node or client.
void setInfo(const QHostInfo &info)
setInfo - Set new host info for this node.
void setSct(QAbstractSocket *sct)
setSct This method sets a new socket for this node or client.
bool fVersionDelivered() const
fVersionDelivered This method return true if this node delivere own version to the distanation node.
void sigReadyRead(QH::AbstractNodeInfo *thisNode)
sigReadyRead This is wrapper signal for the QAbstractSocket::readyRead signal.
HostAddress networkAddress() const
networkAddress This method return network address of current node or client.
void setNetworkAddress(const HostAddress &networkAddress)
setNetworkAddress This method update network address of the current node.
void addParser(unsigned short cmd, QSharedPointer< QH::iParser > parser)
addParser This method add to cache new parser for command .
virtual void setTrust(int trust)
setTrust This method set manually value of this node trust.
void addParser(QSharedPointer< QH::iParser > parser)
addParser This method add to cache new parser for command .
void statusChaned(QH::AbstractNodeInfo *thisNode, QH::NodeCoonectionStatus status)
statusChaned This signal emitted when nodes status is changed.
virtual bool confirmData() const
confirmData This method check all data of node and return true. If node is confirmed.
virtual void removeSocket()
removeSocket This method use for remove socket. You can override this method for handle this event.
void setFVersionDelivered(bool newFVersionDelivered)
setFVersionDelivered This method change the fVersionDelivered flag.
QHostInfo * info() const
info - This method return Host domain information. For more information see the Qt Documentation abou...
const VersionData & version() const
version This method return version data structure;
virtual void unBan()
unBan - Set trust value of node to TrustNode::Restore. See TrustNode enum for more information.
virtual void ban()
ban This node, set trust value to 0.
void updateConfirmStatus()
updateConfirmStatus This method invoked after process a received package and update confirm status of...
QSharedPointer< QH::iParser > getParser(unsigned short cmd)
getParser This method return parser of choosed command.
virtual bool isValid() const
isValid - Check valid of node. This method check connect status of socket.
void sigConfirmed(QH::AbstractNodeInfo *thisNode)
sigConfirmed This signal emitted when node is confirmnd. The confirm status sets in the confirmData m...
QAbstractSocket * sct() const
sct This method return socket of connection.
virtual bool isBanned() const
isBanned - check node which banned.
void setIsLocal(bool isLocal)
setIsLocal This method sets local status for this Node.
void sigConnected(QH::AbstractNodeInfo *thisNode)
sigConnected This is wrapper signal for the QAbstractSocket::connetced signal.
void sigErrorOccurred(QH::AbstractNodeInfo *thisNode, QAbstractSocket::SocketError socketError, QString message)
sigErrorOccurred This is wrapper signal for the QAbstractSocket::errorOccurred signal.
virtual bool isConnected() const
isConnected - Check of node connect status.
bool fVersionReceived() const
fVersionReceived This method return true if this node receive version information.
void sigDisconnected(QH::AbstractNodeInfo *thisNode)
sigDisconnected This is wrapper signal for the QAbstractSocket::disconnected signal.
The Host Address class this is wrapper of QHostAddress. Contains the NetworkAddress and network port.
Definition hostaddress.h:22
Q_DECLARE_METATYPE(QH::HostAddress)
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
uint qHash(NodeCoonectionStatus status)
qHash - Simple hash function of NodeCoonectionStatus
NodeCoonectionStatus
The AbstractNodeState enum - This is status of the known nodes or clients.
@ Connected
The node with this status has socket status is connected.
@ NotConnected
This node not sent data about its envirement and status of node socket is disconnected.
QHash< QString, DistVersion > VersionData
VersionData This is array of all available apis and supported its versions.
Definition distversion.h:78
TrustNode
The TrustNode enum contains cases for trust of the client or nodes.
@ Default
General trust of the node or client.
@ Baned
Node with this trust value is forbidden.
@ Undefined
Undefined node.
QHash< unsigned short, DistVersion > PackagesVersionData
PackagesVersionData This is some as VersionData but for int commands.
Definition distversion.h:83