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

some fixes

This commit is contained in:
Andrei Yankovich 2020-12-08 17:51:30 +03:00
parent d6aa8ba383
commit 47568147aa
11 changed files with 38 additions and 34 deletions

@ -14,7 +14,7 @@ endif()
find_package(Qt5 COMPONENTS Core Test REQUIRED)
if(NOT DEFINED HEART_BUILD_LVL)
set(HEART_BUILD_LVL 2)
set(HEART_BUILD_LVL 1)
endif()
include(QuasarAppLib/CMake/ccache.cmake)

@ -497,7 +497,7 @@ bool AbstractNode::sendData(const AbstractData *resp,
}
void AbstractNode::badRequest(const HostAddress &address, const Header &req,
const ErrorData &err, quint8 diff) {
const ErrorData &err, qint8 diff) {
auto client = getInfoPtr(address);
if (!client) {
@ -713,45 +713,46 @@ void AbstractNode::avelableBytes() {
auto &hdrArray = _receiveData[id]->_hdrArray;
int workIndex = 0;
auto array = client->readAll();
const int headerSize = sizeof(Header);
// concat with old data of header.
array.insert(0, hdrArray);
const auto array = hdrArray + client->readAll();
const int arraySize = array.size();
hdrArray.clear();
while (array.size() > workIndex) {
while (arraySize > workIndex) {
unsigned int workSize = array.size() - workIndex;
int workSize = arraySize - workIndex;
if (pkg.hdr.isValid()) {
// CASE 1: The Package data is still not collected, but the header is already collected. performs full or partial filling of packet data.
unsigned int dataLength = std::min(pkg.hdr.size - pkg.data.size(),
array.size() - workIndex);
pkg.data.append(array.mid(workIndex + sizeof(Header), dataLength));
int dataLength = std::min(pkg.hdr.size - pkg.data.size(),
arraySize - workIndex);
pkg.data.append(array.mid(workIndex + headerSize, dataLength));
workIndex += dataLength;
} else if (workSize >= sizeof(Header)) {
} else if (workSize >= headerSize) {
// CASE 2: The header and package still do not exist and the amount of data allows you to create a new header. A header is created and will fill in all or part of the package data.
pkg.reset();
memcpy(&pkg.hdr,
array.data() + workIndex, sizeof(Header));
array.data() + workIndex, headerSize);
unsigned int dataLength = std::min(static_cast<unsigned long>(pkg.hdr.size),
array.size() - sizeof(Header) - workIndex);
int dataLength = std::min(static_cast<int>(pkg.hdr.size),
arraySize - headerSize - workIndex);
pkg.data.append(array.mid(workIndex + sizeof(Header), dataLength));
workIndex += sizeof(Header) + dataLength;
pkg.data.append(array.mid(workIndex + headerSize, dataLength));
workIndex += headerSize + dataLength;
} else {
// CASE 3: There is not enough data to initialize the header. The data will be placed in temporary storage and will be processed the next time the data is received.
unsigned char dataLength = array.size() - workIndex;
unsigned char dataLength = static_cast<unsigned char>(arraySize - workIndex);
hdrArray += array.mid(workIndex, dataLength);
workIndex += dataLength;
}
@ -964,7 +965,7 @@ QHash<HostAddress, AbstractNodeInfo *> AbstractNode::connections() const {
}
void AbstractNode::connectionRegistered(const AbstractNodeInfo *info) {
Q_UNUSED(info);
Q_UNUSED(info)
}
void AbstractNode::pushToQueue(const std::function<void()>& action,
@ -1012,15 +1013,15 @@ void AbstractNode::nodeStatusChanged(const HostAddress &node, NodeCoonectionStat
}
void AbstractNode::nodeConfirmend(const HostAddress &node) {
Q_UNUSED(node);
Q_UNUSED(node)
}
void AbstractNode::nodeConnected(const HostAddress &node) {
Q_UNUSED(node);
Q_UNUSED(node)
}
void AbstractNode::nodeDisconnected(const HostAddress &node) {
Q_UNUSED(node);
Q_UNUSED(node)
}
void AbstractNode::checkConfirmendOfNode(const HostAddress &node) {

@ -352,7 +352,7 @@ protected:
* By default diff equals REQUEST_ERROR
*/
virtual void badRequest(const HostAddress &address, const Header &req,
const PKG::ErrorData& err, quint8 diff = REQUEST_ERROR);
const PKG::ErrorData& err, qint8 diff = REQUEST_ERROR);
/**
* @brief getWorkStateString This method generate string about work state of server.
@ -441,7 +441,7 @@ protected:
* @note override this method for get a signals.
*/
virtual void incomingData(PKG::AbstractData* pkg,
const HostAddress& sender);
const HostAddress& sender);
/**
* @brief connections - return hash map of all connections of this node.

@ -58,7 +58,7 @@ void PackageManager::processed(const Package &pkg, char processResult) {
new Package(pkg)
});
_processTime.insert(static_cast<int>(time(0)), pkg.hdr.hash);
_processTime.insert(static_cast<int>(time(nullptr)), pkg.hdr.hash);
}
}

@ -9,9 +9,10 @@
#ifndef PAKCAGEMANAGER_H
#define PAKCAGEMANAGER_H
#include "package.h"
#include <QMutex>
#include <QSharedDataPointer>
#include <nodeid.h>
namespace QH {

@ -158,7 +158,7 @@ AbstractNodeInfo *DataBaseNode::createNodeInfo(QAbstractSocket *socket, const Ho
}
void DataBaseNode::badRequest(const HostAddress &address, const Header &req,
const ErrorData &err, quint8 diff) {
const ErrorData &err, qint8 diff) {
if (!changeTrust(address, diff)) {

@ -103,7 +103,7 @@ protected:
AbstractNodeInfo *createNodeInfo(QAbstractSocket *socket, const HostAddress *clientAddress) const override;
void badRequest(const HostAddress &address, const Header &req,
const PKG::ErrorData& err, quint8 diff = REQUEST_ERROR) override;
const PKG::ErrorData& err, qint8 diff = REQUEST_ERROR) override;
bool changeTrust(const HostAddress &id, int diff) override;

@ -532,12 +532,12 @@ AbstractNodeInfo *NetworkNode::createNodeInfo(QAbstractSocket *socket,
}
void NetworkNode::badRequest(const HostAddress &address, const Header &req,
const ErrorData &err, quint8 diff) {
const ErrorData &err, qint8 diff) {
DataBaseNode::badRequest(address, req, err, diff);
}
void NetworkNode::badRequest(const NodeId &address, const Header &req,
const ErrorData &err, quint8 diff) {
const ErrorData &err, qint8 diff) {
if (!changeTrust(address, diff)) {

@ -115,7 +115,7 @@ protected:
const Header *req = nullptr) override;
void badRequest(const HostAddress &address, const Header &req,
const PKG::ErrorData& err, quint8 diff = REQUEST_ERROR) override;
const PKG::ErrorData& err, qint8 diff = REQUEST_ERROR) override;
/**
* @brief badRequest This implementation of the AbstractNode::badRequest method
@ -127,7 +127,7 @@ protected:
* By default diff equals REQUEST_ERROR
*/
virtual void badRequest(const NodeId &address, const Header &req,
const PKG::ErrorData& err, quint8 diff = REQUEST_ERROR);
const PKG::ErrorData& err, qint8 diff = REQUEST_ERROR);
bool changeTrust(const QVariant &id, int diff) override;

@ -18,6 +18,7 @@
class TestingBaseClient: public QH::DataBaseNode {
Q_OBJECT
// AbstractNode interface
public:
@ -26,8 +27,8 @@ public:
}
protected:
void incomingData(QH::PKG::AbstractData *pkg, const QH::HostAddress& sender) {
Q_UNUSED(sender);
void incomingData(QH::PKG::AbstractData *pkg, const QH::HostAddress& sender) override {
Q_UNUSED(sender)
auto ping = dynamic_cast<QH::PKG::Ping*>(pkg);
if (ping)
@ -70,7 +71,7 @@ bool BaseNodeTest::powerTest() {
if (!_nodeAPtr->run(TEST_LOCAL_HOST, TEST_PORT, "powerTest")) {
return false;
};
}
delete _nodeAPtr;
@ -142,3 +143,4 @@ bool BaseNodeTest::securityTest() {
#include "basenodetest.moc"

@ -13,7 +13,7 @@
QByteArray randomArray(int length) {
QByteArray data;
for (int i = 0 ; i < length; ++i) {
data.push_back(rand() % 0xFF);
data.push_back(rand() % static_cast<char>(0xFF));
}
return data;