4
1
mirror of https://github.com/QuasarApp/Heart.git synced 2025-05-05 14:09:43 +00:00

fix build

This commit is contained in:
Andrei Yankovich 2022-11-25 21:12:36 +03:00
parent 7d5aa6070e
commit 6a63544375
29 changed files with 119 additions and 1109 deletions

@ -69,8 +69,8 @@ AbstractNode::AbstractNode( QObject *ptr):
_tasksheduller = new TaskScheduler();
_apiVersionParser = new APIVersionParser(this);
_apiVersionParser->addApiParser<BigDataParser>();
_apiVersionParser->addApiParser<AbstractNodeParser>();
_apiVersionParser->addApiParser<BigDataParser>(this);
_apiVersionParser->addApiParser<AbstractNodeParser>(this);
qRegisterMetaType<QSharedPointer<QH::AbstractTask>>();
#ifdef USE_HEART_SSL

@ -12,6 +12,7 @@
#include <QHostInfo>
#include <QMetaObject>
#include <quasarapp.h>
#include <iparser.h>
namespace QH {

@ -9,7 +9,9 @@
#define ABSTRACTNODEINFO_H
#include "hostaddress.h"
#include "distversion.h"
#include "heart_global.h"
#include "iparser.h"
#include <hostaddress.h>
@ -18,25 +20,6 @@ class QHostInfo;
namespace QH {
class iParser;
/**
* @brief The DistVersion class This is infirmation of supported versions of the distanation api.
*/
struct DistVersion {
/// This is monimum supported version.
unsigned short min = 0;
/// This is maximum supported version.
unsigned short max = 0;
};
/**
* @brief VersionData This is array of all avalable apis and supported its versions.
*/
typedef QHash<QString, unsigned int> VersionData;
/**
* @brief The TrustNode enum contains cases for trust of the client or nodes.
*/
@ -246,6 +229,22 @@ public:
*/
void setFVersionDelivered(bool newFVersionDelivered);
/**
* @brief getParser This method return parser of choosed command.
* @param cmd This is command that need to parse.
* @return parser of the @a cmd comand.
*/
QSharedPointer<QH::iParser> getParser(unsigned short cmd);
/**
* @brief addParser This method add to cache new parser for command .
* @param cmd
* @param parser
* @note All parsers will be removed after reconnect of this node.
*/
void addParser(unsigned short cmd, QSharedPointer<QH::iParser> parser);
public slots:
/**
* @brief removeSocket This method use for remove socket.
@ -298,22 +297,6 @@ signals:
*/
void statusChaned(QH::AbstractNodeInfo* thisNode, QH::NodeCoonectionStatus status);
/**
* @brief getParser This method return parser of choosed command.
* @param cmd This is command that need to parse.
* @return parser of the @a cmd comand.
*/
QSharedPointer<iParser> getParser(unsigned short cmd);
/**
* @brief addParser This method add to cache new parser for command .
* @param cmd
* @param parser
* @note All parsers will be removed after reconnect of this node.
*/
void addParser(unsigned short cmd, QSharedPointer<QH::iParser> parser);
protected:
/**

@ -7,6 +7,7 @@
#include "apiversionparser.h"
#include "abstractnodeinfo.h"
#include "distversion.h"
#include <apiversion.h>
#include <versionisreceived.h>
@ -107,7 +108,7 @@ APIVersionParser::selectParser(const VersionData &distVersion) const {
QHash<QString, QSharedPointer<iParser>> result;
for (auto it = distVersion.begin(); it != distVersion.end(); ++it) {
for (int version = it->max; version >= it->min; --version) {
for (int version = it->max(); version >= it->min(); --version) {
auto parser = _apiParsers[it.key()].value(version, nullptr);
if (parser)
result[it.key()] = parser;
@ -175,11 +176,11 @@ bool APIVersionParser::processAppVersion(const QSharedPointer<APIVersion> &messa
QuasarAppUtils::Params::log(QString("Can't found %0 parser for versions: %1-%2").
arg(parserKey).
arg(requiredApi.min).
arg(requiredApi.max),
arg(requiredApi.min()).
arg(requiredApi.max()),
QuasarAppUtils::Error);
unsigned short distMinVersion = sender->version().value(parserKey).min;
unsigned short distMinVersion = sender->version().value(parserKey).min();
if (distMinVersion > maximumApiVersion(parserKey)) {
emit sigNoLongerSupport(parserKey, distMinVersion);

@ -62,9 +62,9 @@ public:
* @brief addApiParser This is template metod that add sipport of new apiparser @a ApiType
* @tparam ApiType This is type of new apiParser that will be added to the main parser.
*/
template<class ApiType>
void addApiParser() {
addApiParser(QSharedPointer<ApiType>::create(this));
template<class ApiType, class ... Args >
void addApiParser(Args&&... arg) {
addApiParser(QSharedPointer<ApiType>::create(std::forward<Args>(arg)...));
}
/**

@ -0,0 +1,39 @@
/*
* Copyright (C) 2018-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 "distversion.h"
namespace QH {
unsigned short DistVersion::max() const {
return _max;
}
void DistVersion::setMax(unsigned short newMax) {
_max = newMax;
}
QDataStream &DistVersion::fromStream(QDataStream &stream) {
stream >> _min;
stream >> _max;
return stream;
}
QDataStream &DistVersion::toStream(QDataStream &stream) const {
stream << _min;
stream << _max;
return stream;
}
unsigned short DistVersion::min() const {
return _min;
}
void DistVersion::setMin(unsigned short newMin) {
_min = newMin;
}
}

@ -0,0 +1,51 @@
/*
* Copyright (C) 2018-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 DISTVERSION_H
#define DISTVERSION_H
#include <QHash>
#include <streambase.h>
namespace QH {
/**
* @brief The DistVersion class This is infirmation of supported versions of the distanation api.
*/
class DistVersion: public StreamBase {
public:
unsigned short min() const;
void setMin(unsigned short newMin);
unsigned short max() const;
void setMax(unsigned short newMax);
protected:
QDataStream &fromStream(QDataStream &stream) override;
QDataStream &toStream(QDataStream &stream) const override;
private:
/// This is monimum supported version.
unsigned short _min = 0;
/// This is maximum supported version.
unsigned short _max = 0;
};
/**
* @brief VersionData This is array of all avalable apis and supported its versions.
*/
typedef QHash<QString, DistVersion> VersionData;
}
#endif // DISTVERSION_H

@ -1,35 +1,5 @@
-- This is base table of network member (clients)
-- all additional information must be conteins in the another tables with links to the NetworkMembers table.
CREATE TABLE IF NOT EXISTS NetworkMembers (
id VARCHAR(32) PRIMARY KEY,
authenticationData BLOB NOT NULL,
trust INTEGER default 0
);
-- The MemberPermisions table contains link to anothe database object and links to users of the database with permission lvl.
CREATE TABLE IF NOT EXISTS MemberPermisions (
memberId VARCHAR(32) NOT NULL,
-- This field contatins a base64 implementation of a sha256 (requariment 44 bytes) hash code of a database address
dbAddress VARCHAR(44) NOT NULL,
lvl tinyint NOT NULL,
FOREIGN KEY(memberId) REFERENCES NetworkMembers(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS MemberPermisionsIndex ON MemberPermisions(memberId, dbAddress);
-- The DefaultPermissions table contains addresses of tables. and default permisions for all network members
CREATE TABLE IF NOT EXISTS DefaultPermissions (
dbAddress VARCHAR(44) NOT NULL UNIQUE,
lvl tinyint NOT NULL,
FOREIGN KEY(dbAddress) REFERENCES MemberPermisions(dbAddress)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS DataBaseAttributes (
name TEXT NOT NULL PRIMARY KEY,

@ -1,39 +0,0 @@
-- This is base table of network member (users)
-- id is unique fiels for login and execute select queries (for get user information without user id).
-- all additional information must be conteins in the another tables with links to the NetworkMembers table.
CREATE TABLE IF NOT EXISTS NetworkMembers (
id VARCHAR(32) PRIMARY KEY,
authenticationData BLOB NOT NULL,
trust INTEGER default 0,
token BLOB default NULL
);
-- The MemberPermisions table contains link to anothe database object and links to users of the database with permission lvl.
CREATE TABLE IF NOT EXISTS MemberPermisions (
memberId VARCHAR(32) NOT NULL,
-- This field contatins a base64 implementation of a sha256 (requariment 44 bytes) hash code of a database address
dbAddress VARCHAR(44) NOT NULL,
lvl tinyint NOT NULL,
FOREIGN KEY(memberId) REFERENCES NetworkMembers(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS MemberPermisionsIndex ON MemberPermisions(memberId, dbAddress);
-- The DefaultPermissions table contains addresses of tables. and default permisions for all network members
CREATE TABLE IF NOT EXISTS DefaultPermissions (
dbAddress VARCHAR(44) NOT NULL UNIQUE,
lvl tinyint NOT NULL,
FOREIGN KEY(dbAddress) REFERENCES MemberPermisions(dbAddress)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS DataBaseAttributes (
name TEXT NOT NULL PRIMARY KEY,
value INT NOT NULL UNIQUE
);

@ -6,14 +6,11 @@
*/
#include "database.h"
#include "sqldbcache.h"
#include "sqldbwriter.h"
#include "asyncsqldbwriter.h"
#include <quasarapp.h>
#include <QCoreApplication>
#include <abstractnetworkmember.h>
#include <networkmember.h>
#include <deleteobject.h>
#include <QSet>
#include <itoken.h>
@ -132,16 +129,6 @@ bool DataBase::welcomeAddress(AbstractNodeInfo *) {
return true;
}
bool DataBase::isBanned(const QString &node) const {
NetworkMember member(node);
auto objectFromDataBase = db()->getObject<AbstractNetworkMember>(member);
if (!objectFromDataBase)
return false;
return objectFromDataBase->trust() <= 0;
}
QStringList DataBase::SQLSources() const{
return {
DEFAULT_DB_INIT_FILE_PATH
@ -186,24 +173,6 @@ QString DataBase::dbLocation() const {
return "";
}
bool DataBase::changeTrust(const QString &id, int diff) {
if (!_db)
return false;
auto action = [diff](const QSharedPointer<DBObject> &object) {
auto obj = object.dynamicCast<AbstractNetworkMember>();
if (!obj) {
return false;
}
obj->changeTrust(diff);
return true;
};
return _db->changeObjects(NetworkMember{id}, action);
}
ISqlDB *DataBase::db() const {
return _db;
}

@ -89,28 +89,12 @@ public:
*/
virtual QVariantMap defaultDbParams() const;
/**
* @brief isBanned This method check trust of node, if node trust is lover of 0 return true.
* @param member This is member of network (node, client or server).
* @return true if node is banned.
*/
bool isBanned(const QString &member) const;
/**
* @brief dbLocation This method return location of nodes or clients database.
* @return path to the location of database.
*/
QString dbLocation() const;
/**
* @brief changeTrust This implementation of change trust is change trust node or user by self id.
* All changes of trust saving into local database.
* @param id This is id of user of other network member object.
* @param diff This is difference of trust.
* @return true if trust of user changed successful.
*/
bool changeTrust(const QString &id, int diff);
signals:
/**

@ -1,57 +0,0 @@
/*
* Copyright (C) 2020-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 "dberrorcodes.h"
namespace QH {
namespace ErrorCodes {
QString DBErrorCodesHelper::toString(QH::ErrorCodes::Code enumData) {
switch (enumData) {
case ErrorCodes::InternalError: {
return "Internal server error."
" Please create issue about this problem in the support page "
" https://github.com/QuasarApp/Heart/issues/new";
}
case ErrorCodes::UserExits: {
return "Such user already exists ";
}
case ErrorCodes::UserNotExits: {
return "Such user not exists ";
}
case ErrorCodes::UserInvalidPasswoed: {
return "Invalid password ";
}
case ErrorCodes::UserAlreadyLogged: {
return "User Already Logged";
}
case ErrorCodes::UserNotLogged: {
return "User is not Logged";
}
case ErrorCodes::TimeOutError: {
return "Server response timed out ";
}
case OperatioForbiden: {
return "Permission denied";
}
default: return AbstractErrorCodesHelper::toString(enumData);
}
}
}
}

@ -9,7 +9,6 @@
#include "quasarapp.h"
#include "sqldbwriter.h"
#include "dbaddresskey.h"
#include "permisiondata.h"
#include <dbobject.h>
#include <asyncsqldbwriter.h>

@ -161,10 +161,6 @@ bool DBObject::isBundle() const {
return false;
}
uint DBObject::dbKey() const {
return HASH_KEY(DbAddressKey(dbAddress()));
}
QString DBObject::condition() const {
// prepare key value to string condition

@ -320,14 +320,6 @@ public:
*/
virtual bool isBundle() const;
/**
* @brief dbKey This method return unique key for this object.
* For more information see AbstractKey::hash method.
* This method calc hash of {id:table} data.
* @return unique key of this object.
*/
virtual uint dbKey() const;
/**
* @brief dbAddress This method return address of the database object.
* IF the object is not valid then this method return an invalid database address.

@ -2,7 +2,5 @@
<qresource prefix="/sql">
<file>DataBaseSpace/Res/DbConfig.json</file>
<file>DataBaseSpace/Res/BaseDB.sql</file>
<file>NetworkSpace/Res/NetworkDB.sql</file>
<file>DataBaseSpace/Res/UserDB.sql</file>
</qresource>
</RCC>

@ -9,18 +9,7 @@
#define NETWORKPROTOCOL_H
#include "package.h"
#if HEART_BUILD_LVL >= 0
#include "abstractnode.h"
#endif
#if HEART_BUILD_LVL >= 1
#include "databasenode.h"
#endif
#if HEART_BUILD_LVL >= 2
#include "networknode.h"
#endif
inline void initResources() { Q_INIT_RESOURCE(ProtockolResusces); }

@ -1,20 +0,0 @@
/*
* Copyright (C) 2020-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 "testsingleserver.h"
const QH::PKG::Ping &TestSingleServer::getPing() const {
return _ping;
}
void TestSingleServer::incomingData(const QH::PKG::AbstractData *pkg, const QH::AbstractNodeInfo *sender) {
Q_UNUSED(sender)
auto ping = dynamic_cast<const QH::PKG::Ping*>(pkg);
if (ping)
_ping.setAnsver(ping->ansver());
}

@ -1,31 +0,0 @@
/*
* Copyright (C) 2020-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 TESTSINGLESERVER_H
#define TESTSINGLESERVER_H
#include <QObject>
#include <ping.h>
#include <singleserver.h>
class TestSingleServer: public QH::SingleServer {
Q_OBJECT
// AbstractNode interface
public:
const QH::PKG::Ping& getPing() const;
protected:
void incomingData(const QH::PKG::AbstractData *pkg, const QH::AbstractNodeInfo* sender) override;
private:
QH::PKG::Ping _ping;
friend class SingleServerTest;
};
#endif // TESTSINGLESERVER_H

@ -1,31 +0,0 @@
/*
* Copyright (C) 2020-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 "testsingleserverclient.h"
#include "test.h"
const QH::PKG::Ping &TestSingleServerClient::getPing() const {
return _ping;
}
void TestSingleServerClient::setStatus(const QH::ClientStatus &status) {
QH::SingleClient::setStatus(status);
}
QPair<QString, unsigned short> TestSingleServerClient::serverAddress() const {
return {TEST_LOCAL_HOST, LOCAL_TEST_PORT};
}
void TestSingleServerClient::incomingData(const QH::PKG::AbstractData *pkg,
const QH::AbstractNodeInfo *sender) {
Q_UNUSED(sender)
auto ping = dynamic_cast<const QH::PKG::Ping*>(pkg);
if (ping)
_ping.setAnsver(ping->ansver());
}

@ -1,36 +0,0 @@
/*
* Copyright (C) 2020-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 TESTSINGLESERVERCLIENT_H
#define TESTSINGLESERVERCLIENT_H
#include <singleclient.h>
#include <ping.h>
#define LOCAL_TEST_PORT TEST_PORT + 3
class TestSingleServerClient: public QH::SingleClient
{
public:
Q_OBJECT
// AbstractNode interface
public:
const QH::PKG::Ping& getPing() const;
void setStatus(const QH::ClientStatus &status);;
protected:
QPair<QString, unsigned short> serverAddress() const override;
void incomingData(const QH::PKG::AbstractData *pkg, const QH::AbstractNodeInfo* sender) override;
private:
QH::PKG::Ping _ping;
friend class SingleServerTest;
};
#endif // TESTSINGLESERVERCLIENT_H

@ -1,224 +0,0 @@
/*
* Copyright (C) 2020-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 "singleservertest.h"
#include <singleserver.h>
#include <private/testsingleserver.h>
#include <private/testsingleserverclient.h>
SingleServerTest::SingleServerTest() {
_client = new TestSingleServerClient();
_server = new TestSingleServer();
}
SingleServerTest::~SingleServerTest() {
_client->softDelete();
_server->softDelete();
}
void SingleServerTest::test() {
QVERIFY(initTest());
loginTest();
}
void SingleServerTest::loginTest() {
// Init default client and server objects.
auto client = dynamic_cast<TestSingleServerClient*>(_client);
auto server = dynamic_cast<TestSingleServer*>(_server);
const QString user = "client";
const QString userPassword = "123";
// init using lymbda functions.
auto connectToserver = [client](){
return client->connectToServer();
};
auto removeRequest = [client]() {
return client->removeUser();
};
auto loginRequestWithPassword = [client, &user, &userPassword]() {
return client->login(user, userPassword);
};
auto loginRequestWithInvalidPassword = [client, &user]() {
return client->login(user, "zz");
};
auto loginRequestUsesToken = [client, &user]() {
return client->login(user);
};
auto logout = [client]() {
return client->logout();
};
auto sigupRequest = [client, &user, &userPassword]() {
return client->signup(user, userPassword);
};
auto dissconnectRequest = [client]() {
client->disconnectFromServer();
return true;
};
auto checkLoginedStatus = [client](){
return client->getStatus() == QH::ClientStatus::Logined;
};
auto checkDisconnectedStatus = [client](){
return client->getStatus() == QH::ClientStatus::Dissconnected;
};
auto checkConnectedStatus = [client](){
return client->getStatus() == QH::ClientStatus::Connected;
};
auto checkLoginNonExitsUser = [client](){
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserNotExits);
};
auto checksigupExitsUser = [client](){
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserExits);
};
auto checkLoginInvalidPassword = [client](){
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserInvalidPasswoed);
};
auto checkRemoveNotLoginningClient = [client](){
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserNotLogged);
};
QVERIFY(client && server);
if (!client)
return;
// Client must be gat a QH::ClientStatus::Dissconnected status.
QVERIFY(client->getStatus() == QH::ClientStatus::Dissconnected);
QVERIFY(client->connectToServer());
// Client must be gat a QH::ClientStatus::Connecting status after connect.
QVERIFY(client->getStatus() == QH::ClientStatus::Connecting);
// All attempts of the loginor or registered must be failed because the client have an offline status.
QVERIFY(!client->login(user));
QVERIFY(!client->login(user, userPassword));
QVERIFY(!client->signup(user, userPassword));
// Run server
QVERIFY(server->run(TEST_LOCAL_HOST, LOCAL_TEST_PORT, "SingleServer"));
// Clent must be connected because the server alredy started successful.
QVERIFY(funcPrivateConnect(connectToserver, checkConnectedStatus));
// The attempt of the login must be failed bacause the server do not have a user with wroted name.
QVERIFY(client->login(user, userPassword));
// Client must be gat a QH::ClientStatus::Loginning status after a successful login.
QVERIFY(client->getStatus() == QH::ClientStatus::Loginning);
QVERIFY(funcPrivateConnect([](){return true;}, checkLoginNonExitsUser));
QVERIFY(funcPrivateConnect(loginRequestWithPassword, checkLoginNonExitsUser));
// The attempt of the signup must be finished successful bacause user with wroted name not exists.
QVERIFY(funcPrivateConnect(sigupRequest, checkLoginedStatus));
// logout client and try login again.
QVERIFY(funcPrivateConnect(logout, checkConnectedStatus));
// waiting of the reflection of the server. This needed because server do not responce about successful logout.
wait([](){return false;}, 500);
// This login must be failed bacause clients token is removed after logout mehod.
QVERIFY(!client->login(user));
// must be finished successful because client is unlogined.
QVERIFY(funcPrivateConnect(loginRequestWithPassword, checkLoginedStatus));
// disconnect client and try login again with login without password.
QVERIFY(funcPrivateConnect(dissconnectRequest, checkDisconnectedStatus));
// Client must be gat a QH::ClientStatus::Dissconnected status.
QVERIFY(client->getStatus() == QH::ClientStatus::Dissconnected);
// Clent must be connected because the server alredy started successful.
QVERIFY(funcPrivateConnect(connectToserver, checkConnectedStatus));
// must be finished successful because an unlogined client have a valid token.
QVERIFY(funcPrivateConnect(loginRequestUsesToken, checkLoginedStatus));
// logout client and try login again.
QVERIFY(funcPrivateConnect(logout, checkConnectedStatus));
// waiting of the reflection of the server. This needed because server do not responce about successful logout.
wait([](){return false;}, 500);
// must be finished failed because client wrote invalid password.
QVERIFY(funcPrivateConnect(loginRequestWithInvalidPassword, checkLoginInvalidPassword));
// check client status after invalid login. status must be equal Connected because client receive a error message from server.
QVERIFY(client->getStatus() == QH::ClientStatus::Connected);
// must be finished failed because client with wroted name is exists.
QVERIFY(funcPrivateConnect(sigupRequest, checksigupExitsUser));
//must be failed
QVERIFY(!client->removeUser());
// force set status loginned for testing validation on server.
client->setStatus(QH::ClientStatus::Logined);
// must be finished failed because client is not loginned. and failed
QVERIFY(!funcPrivateConnect(removeRequest, checkRemoveNotLoginningClient));
client->setStatus(QH::ClientStatus::Connected);
// must be finished successful because client is unlogined.
QVERIFY(funcPrivateConnect(loginRequestWithPassword, checkLoginedStatus));
//must be finished successful bacause client is loginned
QVERIFY(client->removeUser());
// waiting of the reflection of the server. This needed because server do not responce about successful operation.
wait([](){return false;}, 500);
// must be finished successful because old user is removeed.
QVERIFY(funcPrivateConnect(sigupRequest, checkLoginedStatus));
// all tests is completed
}
bool SingleServerTest::initTest() {
auto server = dynamic_cast<TestSingleServer*>(_server);
if (!server->run(TEST_LOCAL_HOST, LOCAL_TEST_PORT, "SingleServer")) {
return false;
}
QString database = server->dbLocation();
server->stop();
if (QFileInfo::exists(database) && !QFile::remove(database)) {
return false;
}
return true;
}

@ -1,47 +0,0 @@
/*
* Copyright (C) 2020-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 SINGLESERVERTESTS_H
#define SINGLESERVERTESTS_H
#include "basetestutils.h"
#include "test.h"
#include "testutils.h"
#include <QtTest>
/**
* @brief The SingleServerTest class testing the QH::SingleServer and QH::SingleClient clases.
* This test case check next situations:
* 1. connect client to sercer
* 2. signup client to server
* 3. login client to server
* 4. remove clent record from server.
*/
class SingleServerTest: public Test, protected BaseTestUtils
{
public:
SingleServerTest();
~SingleServerTest();
void test() override;
private:
/**
* @brief connectNetworkTest
* this test check nodes connections greatThen 3 node
* @return
*/
void loginTest();
bool initTest();
QH::AbstractNode *_server = nullptr;
QH::AbstractNode *_client = nullptr;
};
#endif // SINGLESERVERTESTS_H

@ -1,175 +0,0 @@
/*
* Copyright (C) 2018-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 "networknodetest.h"
#include "networknodeunittests.h"
#include "testutils.h"
#include <networknode.h>
#include <keystorage.h>
#include <ping.h>
#include <qsecretrsa2048.h>
#include <keystoragetest.h>
class TestingNetworkClient: public QH::NetworkNode {
// AbstractNode interface
public:
const QH::PKG::Ping& getPing() const {
return _ping;
}
protected:
void incomingData(QH::PKG::AbstractData *pkg, const QH::NodeId &sender) {
Q_UNUSED(sender);
auto ping = dynamic_cast<QH::PKG::Ping*>(pkg);
if (ping)
_ping.setAnsver(ping->ansver());
}
private:
QH::PKG::Ping _ping;
};
NetworkNodeTest::NetworkNodeTest() {
_nodeA = new TestingNetworkClient();
_nodeB = new QH::NetworkNode();
_nodeC = new TestingNetworkClient();
}
NetworkNodeTest::~NetworkNodeTest() {
_nodeA->softDelete();
_nodeB->softDelete();
_nodeC->softDelete();
}
void NetworkNodeTest::test() {
QVERIFY(dbTest());
QVERIFY(powerTest());
QVERIFY(connectNetworkTest());
QVERIFY(transportDataTest());
// QVERIFY(performanceTest());
// QVERIFY(securityTest());
}
bool NetworkNodeTest::powerTest() {
auto _nodeAPtr = new QH::NetworkNode();
if (!_nodeAPtr->run(TEST_LOCAL_HOST, TEST_PORT, "powerTest")) {
return false;
};
_nodeAPtr->softDelete();
return true;
}
bool NetworkNodeTest::dbTest() {
auto node = new NetworkNodeUnitTests;
if (!node->test()) {
return false;
}
node->softDelete();
return true;
}
bool NetworkNodeTest::connectNetworkTest() {
int nodeAPort = TEST_PORT + 0;
int nodeBPort = TEST_PORT + 1;
int nodeCPort = TEST_PORT + 2;
auto _nodeAPtr = dynamic_cast<QH::NetworkNode*>(_nodeA);
auto _nodeBPtr = dynamic_cast<QH::NetworkNode*>(_nodeB);
auto _nodeCPtr = dynamic_cast<QH::NetworkNode*>(_nodeC);
if (!_nodeAPtr->run(TEST_LOCAL_HOST, nodeAPort, "TestNodeA")) {
return false;
}
if (!_nodeBPtr->run(TEST_LOCAL_HOST, nodeBPort, "TestNodeB")) {
return false;
};
if (!_nodeCPtr->run(TEST_LOCAL_HOST, nodeCPort, "TestNodeC")) {
return false;
};
auto nodeA = _nodeAPtr->nodeId();
auto nodeB = _nodeBPtr->nodeId();
auto nodeC = _nodeCPtr->nodeId();
auto addNodeRequest = [_nodeAPtr, nodeBPort, nodeCPort, _nodeBPtr, nodeC]() {
_nodeAPtr->addNode(QH::HostAddress(TEST_LOCAL_HOST, nodeBPort));
_nodeBPtr->addNode(QH::HostAddress(TEST_LOCAL_HOST, nodeCPort));
return true;
};
auto checkNode = [_nodeAPtr, _nodeBPtr](){
return _nodeAPtr->confirmendCount() && _nodeBPtr->confirmendCount();
};
if (!funcPrivateConnect(addNodeRequest, checkNode)) {
return false;
}
// need to wait for add node
auto request = [_nodeAPtr, nodeC]() {
return _nodeAPtr->ping(nodeC);
};
auto client = dynamic_cast<TestingNetworkClient*>(_nodeAPtr);
auto check = [client](){
return client->getPing().ansver();
};
return funcPrivateConnect(request, check);
}
bool NetworkNodeTest::transportDataTest() {
auto coreNode = getCoreNode();
auto network = generateNetworkNode(30);
if (!(network.size() && coreNode->confirmendCount() == 30)) {
return false;
}
return true;
}
bool NetworkNodeTest::performanceTest() {
return false;
}
bool NetworkNodeTest::securityTest() {
return false;
}
bool NetworkNodeTest::testICtypto() {
// check
if (!validationCrypto<QH::QSecretRSA2048>()) {
return false;
}
return true;
}

@ -1,81 +0,0 @@
/*
* Copyright (C) 2018-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 NETWORKNODETEST_H
#define NETWORKNODETEST_H
#include "networktestutils.h"
#include "test.h"
#include "testutils.h"
#include <QtTest>
class NetworkNodeTest: public Test, protected NetworkTestUtils
{
public:
NetworkNodeTest();
~NetworkNodeTest();
void test();
private:
QH::AbstractNode *_nodeA = nullptr;
QH::AbstractNode *_nodeB = nullptr;
QH::AbstractNode *_nodeC = nullptr;
/**
* @brief testICtypto This test checks a working of the keyStorages (QtSecret2048)
* @return true if tewst fifnished succesful
*/
bool testICtypto();
/**
* @brief powerTest - this test just create a new object of node and distruct it.
* check constructors and distructors of nodes objects.
* @return true if the test finished successful
*/
bool powerTest();
/**
* @brief dbTest - test base functions of database of nodes.
* @return true if test finished successful.
*/
bool dbTest();
/**
* @brief connectNetworkTest
* this test check nodes connections greatThen 3 node
* @return
*/
bool connectNetworkTest();
/**
* @brief transportDataTest
* this test create a small network and sending data to next route : A >> B >> C and C >> B >> A
* @return
*/
bool transportDataTest();
/**
* @brief performanceTest
* this test crate a big network from 100 or biger nodes count and send data for all nodes of network.
* @return
*/
bool performanceTest();
/**
* @brief securityTest - this test create big network and create not valid nodes. After created the network a not valid nodes try conquer network.
* @return
*/
bool securityTest();
};
#endif // NETWORKNODETEST_H

@ -1,33 +0,0 @@
/*
* Copyright (C) 2018-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 "networknodeunittests.h"
#include "test.h"
#include "sqldbcache.h"
#include <QFileInfo>
#include <QFile>
#define DB_NODE_NAME "DbTestNetworkNode"
NetworkNodeUnitTests::NetworkNodeUnitTests():
TemplateDataBaseNodeUnitTests<QH::NetworkNode, QH::PKG::NodeObject>(DB_NODE_NAME) {
}
QH::PKG::NodeObject *NetworkNodeUnitTests::randomMember() const {
srand(time(nullptr));
QH::PKG::NodeObject * res = new QH::PKG::NodeObject();
res->setAuthenticationData(randomArray(64));
res->setTrust(0);
res->prepareToSend();
return res;
}

@ -1,27 +0,0 @@
/*
* Copyright (C) 2018-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 NETWORK_DBTESTS_H
#define NETWORK_DBTESTS_H
#include <networknode.h>
#include <templatedatabasenodeunittests.h>
/**
* @brief The DbTestsNode class - this implementation of node gor testing database
*/
class NetworkNodeUnitTests: public TemplateDataBaseNodeUnitTests<QH::NetworkNode, QH::PKG::NodeObject>
{
public:
NetworkNodeUnitTests();
protected:
QH::PKG::NodeObject *randomMember() const override;
};
#endif // NETWORK_DBTESTS_H

@ -1,124 +0,0 @@
/*
* Copyright (C) 2018-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 "networktestutils.h"
#include <networknode.h>
#include "test.h"
NetworkTestUtils::NetworkTestUtils() {
}
NetworkTestUtils::~NetworkTestUtils() {
if (coreNode) {
delete coreNode;
}
}
QH::NetworkNode *NetworkTestUtils::initNewNode() const {
int port = nextPort();
QString name = (coreNode)? QString("TestNode-%0").arg(port): QString("CoreNode-%0").arg(port);
auto node = new QH::NetworkNode();
if (!node->run(TEST_LOCAL_HOST, port, name)) {
delete node;
return nullptr;
}
return node;
}
const QH::NetworkNode *NetworkTestUtils::getCoreNode() {
if (!coreNode)
coreNode = initNewNode();
return coreNode;
}
bool NetworkTestUtils::deployNewNode(QH::NetworkNode* node) const {
if (!node)
return false;
if (coreNode) {
auto addNodeRequest = [node, this]() {
node->addNode(coreNode->address());
return true;
};
auto checkNode = [node](){
return node->confirmendCount();
};
if (!funcPrivateConnect(addNodeRequest, checkNode)) {
delete node;
return false;
}
}
return true;
}
QHash<QH::NodeId, QH::NetworkNode *>
NetworkTestUtils::generateNetworkNode(int count) const {
QHash<QH::NodeId, QH::NetworkNode *> result;
QSet<QH::NetworkNode *> tmp;
auto deinit = [&tmp]() {
for (QH::NetworkNode * node : tmp) {
delete node;
}
tmp.clear();
};
for (int i = 0; i < count; ++i) {
QH::NetworkNode *tmpNode = initNewNode();
if (tmpNode)
tmp.insert(tmpNode);
}
if (tmp.size() != count) {
deinit();
return {};
}
for (QH::NetworkNode *node: tmp) {
if (!deployNewNode(node)) {
deinit();
return {};
}
}
for (auto i : tmp) {
result.insert(i->nodeId(), i);
}
auto check = [this, count](){
return coreNode->confirmendCount() == count;
};
if (!funcPrivateConnect(nullptr, check)) {
deinit();
return {};
}
result.insert(coreNode->nodeId(), coreNode);
return result;
}
int NetworkTestUtils::nextPort() const {
static int port = 0;
int baseTestPort = TEST_PORT + 1000;
return baseTestPort + port++;
}

@ -1,37 +0,0 @@
/*
* Copyright (C) 2018-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 NETWORKTESTUTILS_H
#define NETWORKTESTUTILS_H
#include <basetestutils.h>
namespace QH {
class NetworkNode;
class NodeId;
}
class NetworkTestUtils: public BaseTestUtils
{
public:
NetworkTestUtils();
~NetworkTestUtils();
bool deployNewNode(QH::NetworkNode* node) const;
QHash<QH::NodeId, QH::NetworkNode*> generateNetworkNode(int count) const;
QH::NetworkNode *initNewNode() const;
protected:
const QH::NetworkNode* getCoreNode();
private:
int nextPort() const;
QH::NetworkNode* coreNode = nullptr;
};
#endif // NETWORKTESTUTILS_H