10#include <QAbstractSocket>
36 auto socketPtr = _sct;
39 socketPtr->disconnect();
44 QMetaObject::invokeMethod(socketPtr,
45 "handleDisconnectFromHost",
46 Qt::QueuedConnection);
48 QMetaObject::invokeMethod(socketPtr,
50 Qt::QueuedConnection);
81 if (!_sct->peerAddress().isNull()) {
85 auto connectedF = [
this] () {
91 connect(_sct, &QAbstractSocket::connected,
92 this, connectedF, Qt::DirectConnection);
94 connect(_sct, &QAbstractSocket::disconnected,
97 connect(_sct, &QAbstractSocket::errorOccurred,
98 this, [
this] (QAbstractSocket::SocketError err){
100 }, Qt::DirectConnection);
102 connect(_sct, &QAbstractSocket::readyRead,
104 Qt::DirectConnection);
106 if (_sct->state() == QAbstractSocket::ConnectedState) {
134 return _multiVersionPackages;
138 _multiVersionPackages = newMultiVersionPackages;
142 return _fVersionDelivered;
146 _fVersionDelivered = newFVersionDelivered;
150 return _fVersionReceived;
154 _fVersionReceived = newFVersionReceived;
162 _version = newVersion;
175 return _networkAddress;
183 QHostInfo::lookupHost(_networkAddress.toString(), [
this] (QHostInfo
info){
184 if (dynamic_cast<AbstractNodeInfo*>(this)) {
193 _info =
new QHostInfo();
210 qDebug() <<
"The node" << _sct->peerAddress().toString() <<
"is banned!";
231 QMutexLocker lock(&_parsersListMutex);
237 QMutexLocker lock(&_parsersListMutex);
239 return _parsersMap.value(cmd,
nullptr);
243 QMutexLocker lock(&_parsersListMutex);
245 return _parsersKeysMap.value(type,
nullptr);
249 QSharedPointer<QH::iParser> parser) {
253 QMutexLocker lock(&_parsersListMutex);
255 _parsersMap[cmd] = parser;
256 _parsersKeysMap[parser->parserId()] = parser;
263 QMutexLocker lock(&_parsersListMutex);
265 _parsersKeysMap[parser->parserId()] = parser;
269 return static_cast<uint
>(status);
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 delivered own version to the destination 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.
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.
virtual ~AbstractNodeInfo()
~AbstractNodeInfo
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 chosen command.
virtual bool isValid() const
isValid - Check valid of node. This method check connect status of socket.
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::connected signal.
void statusChanged(QH::AbstractNodeInfo *thisNode, QH::NodeCoonectionStatus status)
statusChanged This signal emitted when nodes status is changed.
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.
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
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.
@ Default
General trust of the node or client.
@ Baned
Node with this trust value is forbidden.
QHash< unsigned short, DistVersion > PackagesVersionData
PackagesVersionData This is some as VersionData but for int commands.