-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from QuasarApp/task_58
Added new crc function
- Loading branch information
Showing
25 changed files
with
670 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//# | ||
//# Copyright (C) 2022-2022 QuasarApp. | ||
//# Distributed under the lgplv3 software license, see the accompanying | ||
//# Everyone is permitted to copy and distribute verbatim copies | ||
//# of this license document, but changing it is not allowed. | ||
//# | ||
|
||
#include "abstractnodeparser_old.h" | ||
#include "params.h" | ||
#include "abstractnode.h" | ||
#include "qaglobalutils.h" | ||
|
||
#include <badrequest.h> | ||
#include <bigdatarequest.h> | ||
#include <closeconnection.h> | ||
#include <ping.h> | ||
|
||
namespace QH { | ||
|
||
AbstractNodeParserOld::AbstractNodeParserOld(AbstractNode* parentNode): iParser(parentNode) { | ||
debug_assert(parentNode, "Node object can't be null!"); | ||
|
||
registerPackageTypeOld<PKG::Ping>(); | ||
registerPackageTypeOld<PKG::BadRequest>(); | ||
registerPackageTypeOld<PKG::CloseConnection>(); | ||
} | ||
|
||
AbstractNodeParserOld::~AbstractNodeParserOld() { | ||
} | ||
|
||
ParserResult AbstractNodeParserOld::parsePackage(const QSharedPointer<PKG::AbstractData> &pkg, | ||
const Header &pkgHeader, | ||
AbstractNodeInfo *sender) { | ||
auto nodePtr = node(); | ||
if (!nodePtr) { | ||
return ParserResult::NotProcessed; | ||
} | ||
|
||
if (!(sender)) { | ||
QuasarAppUtils::Params::log("sender socket is not valid!", | ||
QuasarAppUtils::Error); | ||
return ParserResult::Error; | ||
} | ||
|
||
if (!pkg->isValid()) { | ||
QuasarAppUtils::Params::log("incomming package is not valid!", | ||
QuasarAppUtils::Error); | ||
nodePtr->changeTrust(sender->networkAddress(), CRITICAL_ERROOR); | ||
return ParserResult::Error; | ||
} | ||
|
||
if (PKG::Ping::commandOld() == pkg->cmd()) { | ||
auto cmd = pkg.staticCast<PKG::Ping>(); | ||
if (!cmd->ansver()) { | ||
cmd->setAnsver(true); | ||
nodePtr->sendData(cmd.data(), sender, &pkgHeader); | ||
} | ||
|
||
emit sigPingReceived(cmd); | ||
|
||
return ParserResult::Processed; | ||
} else if (PKG::BadRequest::commandOld() == pkg->cmd()) { | ||
auto cmd = static_cast<PKG::BadRequest *>(pkg.data()); | ||
|
||
emit nodePtr->requestError(cmd->errCode(), cmd->err()); | ||
|
||
return ParserResult::Processed; | ||
|
||
} else if (PKG::CloseConnection::commandOld() == pkg->cmd()) { | ||
if (sender->isLocal()) { | ||
nodePtr->removeNode(sender->networkAddress()); | ||
} | ||
return ParserResult::Processed; | ||
} | ||
|
||
return ParserResult::NotProcessed; | ||
} | ||
|
||
int AbstractNodeParserOld::version() const { | ||
return 0; | ||
} | ||
|
||
QString AbstractNodeParserOld::parserId() const { | ||
return "HeartLibAbstractAPI"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//# | ||
//# Copyright (C) 2022-2022 QuasarApp. | ||
//# Distributed under the lgplv3 software license, see the accompanying | ||
//# Everyone is permitted to copy and distribute verbatim copies | ||
//# of this license document, but changing it is not allowed. | ||
//# | ||
|
||
#ifndef ABSTRACTNODEPARSER_OLD_H | ||
#define ABSTRACTNODEPARSER_OLD_H | ||
|
||
#include <iparser.h> | ||
#include <ping.h> | ||
|
||
namespace QH { | ||
|
||
/** | ||
* @brief The AbstractNodeParserOld class is main parser of the abstract level of the hear lib. | ||
* @note This class some as AbstractNodeParser | ||
*/ | ||
class AbstractNodeParserOld: public iParser | ||
{ | ||
Q_OBJECT | ||
public: | ||
template<class T> | ||
/** | ||
* @brief registerPackageTypeOld This method register package type T. | ||
* This is need to prepare pacakge for parsing in the parsePackage method. | ||
*/ | ||
void registerPackageTypeOld() { | ||
_registeredTypes[T::commandOld()] = [](){ | ||
return new T(); | ||
}; | ||
}; | ||
|
||
AbstractNodeParserOld(AbstractNode *parentNode); | ||
~AbstractNodeParserOld() override; | ||
ParserResult parsePackage(const QSharedPointer<PKG::AbstractData> &pkg, | ||
const Header &pkgHeader, | ||
AbstractNodeInfo *sender) override; | ||
int version() const override; | ||
QString parserId() const override; | ||
|
||
signals: | ||
|
||
/** | ||
* @brief sigPingReceived This method emited | ||
* @param ping this is received ping object. | ||
*/ | ||
void sigPingReceived(const QSharedPointer<QH::PKG::Ping> &ping); | ||
|
||
}; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.