Skip to content

Commit

Permalink
Merge pull request #59 from QuasarApp/task_58
Browse files Browse the repository at this point in the history
Added new crc function
  • Loading branch information
EndrII authored Nov 30, 2022
2 parents 880fc43 + 1355e76 commit 774bf25
Show file tree
Hide file tree
Showing 25 changed files with 670 additions and 24 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ else()
endif()
# Use only for android debug builds with debugging from usb.
option(HEART_STATIC_SSL "This option enable or disabled static link ssl libraryes" OFF)
option(HEART_DEPRECATED_API "This option enable or disabled deprecated command api" OFF)
option(CMAKE_SHARE "This option enable or disabled ssl functions of nodes" OFF)
option(BUILD_SHARED_LIBS "Enable or disable shared libraryes" OFF)

Expand Down
1 change: 1 addition & 0 deletions HeartTests/units/bigdatatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class BigPackage: public QH::PKG::AbstractData {
QH_PACKAGE(BigPackage, "BigPackage")

public:
BigPackage(){
data = {};
Expand Down
13 changes: 11 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ set(CMAKE_AUTORCC ON)

add_definitions(-DHEART_LIBRARY)

if (HEART_DEPRECATED_API)
add_definitions(-DHEART_DEPRECATED_API)
endif()

set(SLL_DEFINE "WITHOUT_SSL")

if (HEART_SSL)
Expand All @@ -35,9 +39,15 @@ file(GLOB SOURCE_CPP
"private/*.cpp" "private/*.h" "private/*.qrc"
"public/hcrypto/*.cpp" "public/hcrypto/*.h" "public/hcrypto/*.qrc"
"public/hcryptoFeatures/*.cpp" "public/hcryptoFeatures/*.h" "public/hcryptoFeatures/*.qrc"

)

if (NOT HEART_DEPRECATED_API)
file(GLOB SOURCE_CPP_DEPRECATED
"private/*_old.cpp" "private/*_old.h"
)
list(REMOVE_ITEM SOURCE_CPP ${SOURCE_CPP_DEPRECATED})
endif()

set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PUBLIC_INCUDE_DIR ${PUBLIC_INCUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/public")
set(PUBLIC_INCUDE_DIR ${PUBLIC_INCUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/public/packages")
Expand Down Expand Up @@ -74,6 +84,5 @@ if (HEART_SSL)

endif()


target_include_directories(${PROJECT_NAME} PUBLIC ${PUBLIC_INCUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${PRIVATE_INCUDE_DIR})
2 changes: 1 addition & 1 deletion src/private/abstractnodeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ParserResult AbstractNodeParser::parsePackage(const QSharedPointer<PKG::Abstract
}

int AbstractNodeParser::version() const {
return 0;
return 1;
}

QString AbstractNodeParser::parserId() const {
Expand Down
86 changes: 86 additions & 0 deletions src/private/abstractnodeparser_old.cpp
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";
}
}
53 changes: 53 additions & 0 deletions src/private/abstractnodeparser_old.h
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
13 changes: 13 additions & 0 deletions src/private/apiversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,18 @@ void APIVersion::setVersion(const VersionData &newVersion) {
_version = newVersion;
}

bool APIVersion::isValid() const {
if (_version.isEmpty())
return false;

for (const auto & version: _version) {
if (version.max() < version.min()) {
return false;
}
}

return true;
}

}
}
5 changes: 5 additions & 0 deletions src/private/apiversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ class APIVersion: public QH::PKG::AbstractData
static unsigned short command(){return PROTOCKOL_VERSION_COMMAND;}
static QString commandText(){return "PROTOCKOL_VERSION_COMMAND";}
unsigned short cmd() const override {return APIVersion::command();}

unsigned short cmdOld() const override {return APIVersion::command();}

QString cmdString() const override {return APIVersion::commandText();}

const VersionData &version() const;
void setVersion(const VersionData &newVersion);

bool isValid() const override;

protected:
unsigned int localCode() const override {return typeid(APIVersion).hash_code();}
QDataStream &fromStream(QDataStream &stream) override;
Expand Down
2 changes: 1 addition & 1 deletion src/private/bigdataparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ParserResult BigDataParser::parsePackage(const QSharedPointer<PKG::AbstractData>
}

int BigDataParser::version() const {
return 0;
return 1;
}

QString BigDataParser::parserId() const {
Expand Down
Loading

0 comments on commit 774bf25

Please sign in to comment.