10#include <QAbstractSocket>
37 auto socketPtr = _sct;
40 socketPtr->disconnect();
45 QMetaObject::invokeMethod(socketPtr,
46 "handleDisckonnetFromHost",
47 Qt::QueuedConnection);
49 QMetaObject::invokeMethod(socketPtr,
51 Qt::QueuedConnection);
82 if (!_sct->peerAddress().isNull()) {
86 auto connectedF = [
this] () {
92 connect(_sct, &QAbstractSocket::connected,
93 this, connectedF, Qt::DirectConnection);
95 connect(_sct, &QAbstractSocket::disconnected,
98 connect(_sct, &QAbstractSocket::errorOccurred,
99 this, [
this] (QAbstractSocket::SocketError err){
101 }, Qt::DirectConnection);
103 connect(_sct, &QAbstractSocket::readyRead,
105 Qt::DirectConnection);
107 if (_sct->state() == QAbstractSocket::ConnectedState) {
135 return _multiVersionPackages;
139 _multiVersionPackages = newMultiVersionPackages;
143 return _fVersionDelivered;
147 _fVersionDelivered = newFVersionDelivered;
151 return _fVersionReceived;
155 _fVersionReceived = newFVersionReceived;
163 _version = newVersion;
176 return _networkAddress;
184 QHostInfo::lookupHost(_networkAddress.
toString(), [
this] (QHostInfo
info){
185 if (dynamic_cast<AbstractNodeInfo*>(this)) {
192void AbstractNodeInfo::setInfo(
const QHostInfo &info) {
194 _info =
new QHostInfo();
199QHostInfo *AbstractNodeInfo::info()
const {
203int AbstractNodeInfo::trust()
const {
207void AbstractNodeInfo::setTrust(
int trust) {
210 if (isBanned() && _sct) {
211 qDebug() <<
"The node" << _sct->peerAddress().toString() <<
"is banned!";
217bool AbstractNodeInfo::isValid()
const {
221bool AbstractNodeInfo::isConnected()
const {
222 return isValid() && status() != NodeCoonectionStatus::NotConnected;
225void AbstractNodeInfo::reset() {
228 setTrust(
static_cast<int>(TrustNode::Default));
229 setStatus(NodeCoonectionStatus::NotConnected);
232 QMutexLocker lock(&_parsersListMutex);
237QSharedPointer<QH::iParser> AbstractNodeInfo::getParser(
unsigned short cmd) {
238 QMutexLocker lock(&_parsersListMutex);
240 return _parsersMap.value(cmd,
nullptr);
243QSharedPointer<iParser> AbstractNodeInfo::getParser(
const QString &type) {
244 QMutexLocker lock(&_parsersListMutex);
246 return _parsersKeysMap.value(type,
nullptr);
250 QSharedPointer<QH::iParser> parser) {
254 QMutexLocker lock(&_parsersListMutex);
256 _parsersMap[cmd] = parser;
257 _parsersKeysMap[parser->parserId()] = parser;
264 QMutexLocker lock(&_parsersListMutex);
266 _parsersKeysMap[parser->parserId()] = parser;
270 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.
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.
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 .
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.
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...
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.
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.
QString toString() const
toString this method convert the Host Address value to string value.
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.
@ Baned
Node with this trust value is forbidden.
QHash< unsigned short, DistVersion > PackagesVersionData
PackagesVersionData This is some as VersionData but for int commands.