Разработка продолжена
На самом деле, она и не заканчивалась, просто я вот вчера пошёл в магазин ну типа в пятёрочку тут есть у меня недалеко на углу улицы и короче вот я пошёл иду такой а мне навстречу сам илон макс правда я не шучу реально илон маз к идёт такой и я ему такой привет а он такой тоже здравствуйте я спрашиваю типа как там с теслой и спайс икс а он перебивает меня и говорит смотри сейчас будет фокус ну я такой ладно и он типа раз и взрывается нахуй пиздец я тогда умер кстати
This commit is contained in:
parent
c84c62400b
commit
09aff0e709
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
src/.old
|
||||||
|
src/test.cpp
|
||||||
|
libstadium.so
|
||||||
|
libstadiumtest_release
|
||||||
|
libstadiumtest_sanitizer
|
||||||
|
libstadiumtest_fortified
|
17
Makefile
17
Makefile
@ -2,16 +2,21 @@
|
|||||||
|
|
||||||
CC = g++
|
CC = g++
|
||||||
CFLAGS_DEFAULT = -march=native -std=c++23
|
CFLAGS_DEFAULT = -march=native -std=c++23
|
||||||
CFLAGS_DEBUG = -Wall -Werror -Wno-uninitialized -Wno-analyzer-use-of-uninitialized-value -fanalyzer -ggdb
|
CFLAGS_DEBUG = -ggdb -Wall -Werror -Wno-reorder -Wno-uninitialized -fanalyzer -Wno-analyzer-use-of-uninitialized-value
|
||||||
CFLAGS_DEBUG_S = -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
#CFLAGS_DEBUG_S = -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
||||||
CFLAGS_DEBUG_F = -O1 -D_FORTIFY_SOURCE=3
|
CFLAGS_DEBUG_F = -O1 -D_FORTIFY_SOURCE=3
|
||||||
CFLAGS_RELEASE = -static-libgcc -static-libstdc++ -static -Ofast -fdevirtualize-speculatively -fdata-sections -ffunction-sections -Wl,-gc-sections -Wl,-strip-all -Wl,-strip-discarded -flto -s -D_FORTIFY_SOURCE=3
|
CFLAGS_RELEASE = -static-libgcc -static-libstdc++ -static -Ofast -fdevirtualize-speculatively -fdata-sections -ffunction-sections -Wl,-gc-sections -Wl,-strip-all -Wl,-strip-discarded -flto -s -D_FORTIFY_SOURCE=3
|
||||||
|
|
||||||
SOURCES = src/stadium.hpp src/stadium.cpp src/kldr.hpp
|
SOURCES = src/Stadium.hpp src/Stadium.cpp \
|
||||||
|
src/Event.hpp src/Event.cpp \
|
||||||
|
src/Worker.hpp src/Worker.cpp \
|
||||||
|
src/KLDR.hpp \
|
||||||
|
src/Utils.hpp
|
||||||
SOURCES_TEST = src/test.cpp
|
SOURCES_TEST = src/test.cpp
|
||||||
#LINKED_LIBS = -l
|
#LINKED_LIBS = -l
|
||||||
OUTPUT_LIB = libstadium.so
|
OUTPUT_LIB = libstadium.so
|
||||||
OUTPUT_TEST_BIN_S = libstadiumtest_sanitizer
|
OUTPUT_TEST_BIN = libstadiumtest_release
|
||||||
|
#OUTPUT_TEST_BIN_S = libstadiumtest_sanitizer
|
||||||
OUTPUT_TEST_BIN_F = libstadiumtest_fortified
|
OUTPUT_TEST_BIN_F = libstadiumtest_fortified
|
||||||
|
|
||||||
|
|
||||||
@ -19,9 +24,7 @@ default: clean release_test
|
|||||||
|
|
||||||
|
|
||||||
debug_test: $(SOURCES) $(SOURCES_TEST)
|
debug_test: $(SOURCES) $(SOURCES_TEST)
|
||||||
$(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(CFLAGS_DEBUG_S) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN_S)
|
|
||||||
$(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(CFLAGS_DEBUG_F) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN_F)
|
$(CC) $(CFLAGS_DEFAULT) $(CFLAGS_DEBUG) $(CFLAGS_DEBUG_F) $(SOURCES) $(SOURCES_TEST) -o $(OUTPUT_TEST_BIN_F)
|
||||||
#$(LINKED_LIBS)
|
|
||||||
|
|
||||||
debug: $(SOURCES)
|
debug: $(SOURCES)
|
||||||
echo "NYI"
|
echo "NYI"
|
||||||
@ -34,4 +37,4 @@ release: $(SOURCES)
|
|||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OUTPUT_LIB) $(OUTPUT_TEST_BIN_S) $(OUTPUT_TEST_BIN_F)
|
rm -f $(OUTPUT_LIB) $(OUTPUT_TEST_BIN_F) $(OUTPUT_TEST_BIN)
|
@ -3,9 +3,3 @@
|
|||||||
_Эталонная имплементация библиотеки с реализацией протокола Stadium на языке C++._
|
_Эталонная имплементация библиотеки с реализацией протокола Stadium на языке C++._
|
||||||
|
|
||||||
**В процессе активной разработки!/Under active development!**
|
**В процессе активной разработки!/Under active development!**
|
||||||
|
|
||||||
|
|
||||||
## Пространства имён
|
|
||||||
|
|
||||||
`Stadium::Base`: базовые инструменты, не подлежащие принципиальному изменению в будущем.
|
|
||||||
`Stadium::v1`: то, что может быть изменено в последующих версиях.
|
|
53
src/Event.cpp
Normal file
53
src/Event.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Event.cpp
|
||||||
|
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Stadium::v1 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Default ctor
|
||||||
|
Event::Event () {
|
||||||
|
this->Type.Category = this->Type.Subcategory = this->AsyncID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctor with parsing of raw char array
|
||||||
|
Event::Event (const char* data, size_t data_sz) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctor with positional arguments
|
||||||
|
Event::Event (EventType type, KLDRArray<> data, uint16_t id = 0) : Type(std::move(type)), Payload(std::move(data)), AsyncID(id) {
|
||||||
|
// TODO: calculate hash
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctor with positional arguments number two
|
||||||
|
Event::Event (uint8_t cat, uint8_t subcat, KLDRArray<> data, uint16_t id = 0) : Payload(std::move(data)), AsyncID(id) {
|
||||||
|
this->Type.Category = cat;
|
||||||
|
this->Type.Subcategory = subcat;
|
||||||
|
// TODO: calculate hash
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to stdout info about event
|
||||||
|
void
|
||||||
|
Event::Print () {
|
||||||
|
printf(
|
||||||
|
"[Event] Object at: %lu; Category: 0x%.2hhx; Subcategory: 0x%.2hhx; AsyncID: %hu; Payload size: cells: %lu, bytes:%lu\n", // TODO: add hash
|
||||||
|
reinterpret_cast<size_t>(this),
|
||||||
|
this->Type.Category,
|
||||||
|
this->Type.Subcategory,
|
||||||
|
this->AsyncID,
|
||||||
|
this->Payload.CellsAmount(),
|
||||||
|
this->Payload.FlatSize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -9,25 +9,49 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <vector>
|
||||||
#include "KLDR.hpp"
|
#include "KLDR.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Stadium {
|
namespace Stadium::v1 {
|
||||||
namespace v1 {
|
|
||||||
|
|
||||||
class Event {
|
|
||||||
public:
|
|
||||||
struct {
|
// Asynchronous ID of event
|
||||||
|
typedef uint16_t EventAsyncID;
|
||||||
|
|
||||||
|
// Type of event
|
||||||
|
struct EventType {
|
||||||
uint8_t Category;
|
uint8_t Category;
|
||||||
uint8_t Subcategory;
|
uint8_t Subcategory;
|
||||||
} Type; // ???
|
|
||||||
uint32_t ServerSession;
|
|
||||||
// TODO: payload hash
|
|
||||||
Base::KLDRArray<> Payload;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
// Event class
|
||||||
|
class Event {
|
||||||
|
public:
|
||||||
|
uint32_t Lifetime = 0; // Lifetime of event in seconds
|
||||||
|
|
||||||
|
private:
|
||||||
|
// These are the "physical" members that will be packed to binary
|
||||||
|
std::vector<char> Hash;
|
||||||
|
// CryptoAlgo HashAlgo; // TODO
|
||||||
|
KLDRArray<> Payload;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EventType Type;
|
||||||
|
EventAsyncID AsyncID;
|
||||||
|
|
||||||
|
Event ();
|
||||||
|
Event (const char*, size_t);
|
||||||
|
Event (EventType, KLDRArray<>, uint16_t);
|
||||||
|
Event (uint8_t, uint8_t, KLDRArray<>, uint16_t);
|
||||||
|
void Print ();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* EventQueue.hpp
|
|
||||||
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBSTADIUM_EVENTQUEUE_HPP
|
|
||||||
#define LIBSTADIUM_EVENTQUEUE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "Event.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Stadium {
|
|
||||||
namespace v1 {
|
|
||||||
|
|
||||||
class EventQueue {
|
|
||||||
protected:
|
|
||||||
std::vector<Event> Array;
|
|
||||||
|
|
||||||
public:
|
|
||||||
//void Add (Event);
|
|
||||||
//Event Get ();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
158
src/KLDR.hpp
158
src/KLDR.hpp
@ -17,34 +17,33 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Stadium {
|
namespace Stadium::v1 {
|
||||||
|
|
||||||
|
|
||||||
namespace v1 {
|
|
||||||
|
|
||||||
enum KLDRDefaultKeys : uint8_t {
|
enum KLDRDefaultKeys : uint8_t {
|
||||||
Data = 0x01,
|
Data = 0x01, // Main data of event
|
||||||
ObjectID = 0x02,
|
ObjectID = 0x02, // ID of object in local context
|
||||||
SrcEventAuthor = 0x03,
|
SrcEventAuthor = 0x03, // Source author of event
|
||||||
PrevEvent = 0x04,
|
PrevEvent = 0x04, // ID of previous event, logically connected to this
|
||||||
NextEvent = 0x05,
|
NextEvent = 0x05, // ID of next event
|
||||||
BatchNumber = 0x06,
|
BatchNumber = 0x06, // Number of event in chain of events
|
||||||
Path = 0x07,
|
Path = 0x07, // Path to requested/uploaded resource
|
||||||
Power = 0x08,
|
Power = 0x08, // Access right to object
|
||||||
|
ServerSession = 0x09, // ID of server-side session
|
||||||
// Crypto-related
|
// Crypto-related
|
||||||
CryptoAlgos = 0x11,
|
CryptoAlgos = 0x11, // Array of used cryptography algos
|
||||||
CryptoKeyID = 0x12,
|
CryptoKeyID = 0x12, // ID of crypto key used for data encryption in this event
|
||||||
SignedDataHash = 0x13
|
SignedDataHash = 0x13 // Signed by sender hash of data
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Base {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* KLDR stands for "Key-Length-Data-Repeat"
|
* KLDR stands for "Key-Length-Data-Repeat".
|
||||||
* Schematically, binary array with KLDR-formatted data looks like this.
|
* Schematically, binary array with KLDR-formatted data looks like this.
|
||||||
* Single cell:
|
* Single cell:
|
||||||
* [key: 1/2 bytes][length of data: 1/2/4 bytes][data: <length of data> bytes]
|
* [key: 1 or 2 bytes][length of data: 1/2/4 bytes][data: <length of data> bytes]
|
||||||
* Whole array:
|
* Whole array:
|
||||||
* [cell 1][cell 2]...[cell n]
|
* [cell 1][cell 2]...[cell n]
|
||||||
*
|
*
|
||||||
@ -54,22 +53,64 @@ namespace Base {
|
|||||||
*/
|
*/
|
||||||
template <typename KeyT = uint8_t, typename LengthT = uint16_t>
|
template <typename KeyT = uint8_t, typename LengthT = uint16_t>
|
||||||
class KLDRArray {
|
class KLDRArray {
|
||||||
protected:
|
private:
|
||||||
std::vector<KeyT> Keys;
|
std::vector<KeyT> Keys;
|
||||||
std::vector<LengthT> Lengths;
|
std::vector<LengthT> Lengths;
|
||||||
std::vector<void*> Values;
|
std::vector<char*> Values;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//KLDRArray (); // TODO: check used types and/or parse given char array/vector
|
// Constructor
|
||||||
|
KLDRArray () {}; // TODO: check used types and/or parse given char array/vector
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~KLDRArray () {
|
~KLDRArray () {
|
||||||
// Freeing all pointers if vector is not empty
|
// Freeing all pointers if vector is not empty
|
||||||
for (size_t i = 0; i < this->Keys.size(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
operator delete(this->Values[i]);
|
delete[] this->Values[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move operator WARNING: есть шанс, что я тут сделал ложно, ибо мб мув просто продлевает время жизни вместо перемещения. Ассигнмента тоже касается
|
||||||
|
KLDRArray (KLDRArray&& src) : Keys(std::move(src.Keys)), Lengths(std::move(src.Lengths)), Values(std::move(src.Values)) {}
|
||||||
|
|
||||||
|
// Move assignment operator
|
||||||
|
KLDRArray& operator= (KLDRArray&& src) {
|
||||||
|
if (this == &src)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
this->Keys = std::move(src.Keys);
|
||||||
|
this->Lengths = std::move(src.Lengths);
|
||||||
|
this->Values = std::move(src.Values);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy operator (creating deep copy)
|
||||||
|
KLDRArray (KLDRArray& src) : Keys(src.Keys), Lengths(src.Lengths)
|
||||||
|
{
|
||||||
|
size_t valSize = 0;
|
||||||
|
for (size_t i = 0; i < src.Values.size(); i++) {
|
||||||
|
valSize = src.Lengths[i];
|
||||||
|
this->Values.push_back(new char[valSize]);
|
||||||
|
std::copy(src.Values[i], src.Values[i] + valSize, this->Values[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy assignment operator (creating deep copy)
|
||||||
|
KLDRArray& operator= (const KLDRArray& src) {
|
||||||
|
if (this == &src)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
this->Keys = src.Keys;
|
||||||
|
this->Lengths = src.Lengths;
|
||||||
|
size_t valSize = 0;
|
||||||
|
for (size_t i = 0; i < src.Values.size(); i++) {
|
||||||
|
valSize = src.Lengths[i];
|
||||||
|
this->Values.push_back(new char[valSize]);
|
||||||
|
std::copy(src.Values[i], src.Values[i] + valSize, this->Values[i]);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// Write data to PREALLOCATED char array
|
// Write data to PREALLOCATED char array
|
||||||
// WARNING: unsafe and probably UB (may be i test this later but who knows)
|
// WARNING: unsafe and probably UB (may be i test this later but who knows)
|
||||||
void AsArrayF (char* arr) {
|
void AsArrayF (char* arr) {
|
||||||
@ -79,13 +120,13 @@ class KLDRArray {
|
|||||||
ptr += sizeof(KeyT);
|
ptr += sizeof(KeyT);
|
||||||
std::copy((char*)&this->Lengths[i], (char*)(&this->Lengths[i] + sizeof(LengthT)), ptr);
|
std::copy((char*)&this->Lengths[i], (char*)(&this->Lengths[i] + sizeof(LengthT)), ptr);
|
||||||
ptr += sizeof(LengthT);
|
ptr += sizeof(LengthT);
|
||||||
std::copy((char*)this->Values[i], ((char*)this->Values[i]) + this->Lengths[i], ptr);
|
std::copy(this->Values[i], this->Values[i] + this->Lengths[i], ptr);
|
||||||
ptr += this->Lengths[i];
|
ptr += this->Lengths[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return contents as char vector
|
// Return contents as char vector
|
||||||
std::vector<char> AsArray () {
|
std::vector<char> AsArray () const {
|
||||||
std::vector<char> result;
|
std::vector<char> result;
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
for (uint j = 0; j < sizeof(KeyT); j++)
|
for (uint j = 0; j < sizeof(KeyT); j++)
|
||||||
@ -99,49 +140,61 @@ class KLDRArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print all contents of array to stdout
|
// Print all contents of array to stdout
|
||||||
void Print () {
|
void Print () const {
|
||||||
printf("Elements amount: %lu\n", this->CellsAmount());
|
printf(
|
||||||
|
"[KLDRArray] Object at: %lu; "
|
||||||
|
"KeyT size: %lu; "
|
||||||
|
"LengthT size: %lu; "
|
||||||
|
"Elements amount: %lu\n",
|
||||||
|
(size_t)this,
|
||||||
|
sizeof(KeyT),
|
||||||
|
sizeof(LengthT),
|
||||||
|
this->CellsAmount()
|
||||||
|
);
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
printf("Key: ");
|
printf("\tKey: ");
|
||||||
switch (this->Keys[i]) {
|
switch (this->Keys[i]) {
|
||||||
case KLDRDefaultKeys::Data:
|
case v1::KLDRDefaultKeys::Data:
|
||||||
printf("Data");
|
printf("Data");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::ObjectID:
|
case v1::KLDRDefaultKeys::ObjectID:
|
||||||
printf("ObjectID");
|
printf("ObjectID");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::SrcEventAuthor:
|
case v1::KLDRDefaultKeys::SrcEventAuthor:
|
||||||
printf("SrcEventAuthor");
|
printf("SrcEventAuthor");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::PrevEvent:
|
case v1::KLDRDefaultKeys::PrevEvent:
|
||||||
printf("PrevEvent");
|
printf("PrevEvent");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::NextEvent:
|
case v1::KLDRDefaultKeys::NextEvent:
|
||||||
printf("NextEvent");
|
printf("NextEvent");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::BatchNumber:
|
case v1::KLDRDefaultKeys::BatchNumber:
|
||||||
printf("BatchNumber");
|
printf("BatchNumber");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::Path:
|
case v1::KLDRDefaultKeys::Path:
|
||||||
printf("Path");
|
printf("Path");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::Power:
|
case v1::KLDRDefaultKeys::Power:
|
||||||
printf("Power");
|
printf("Power");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::CryptoAlgos:
|
case v1::KLDRDefaultKeys::ServerSession:
|
||||||
|
printf("ServerSession");
|
||||||
|
break;
|
||||||
|
case v1::KLDRDefaultKeys::CryptoAlgos:
|
||||||
printf("CryptoAlgos");
|
printf("CryptoAlgos");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::CryptoKeyID:
|
case v1::KLDRDefaultKeys::CryptoKeyID:
|
||||||
printf("CryptoKeyID");
|
printf("CryptoKeyID");
|
||||||
break;
|
break;
|
||||||
case KLDRDefaultKeys::SignedDataHash:
|
case v1::KLDRDefaultKeys::SignedDataHash:
|
||||||
printf("SignedDataHash");
|
printf("SignedDataHash");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("0x%.2X", (KeyT)this->Keys[i]);
|
printf("0x%.2X", (KeyT)this->Keys[i]);
|
||||||
}
|
}
|
||||||
printf("; Length: %u; ", (LengthT)this->Lengths[i]);
|
printf("; Length: %u; ", (uint)this->Lengths[i]);
|
||||||
printf("Value: ");
|
printf("ValuePtr: %lu; Value: ", (uint64_t)this->Values[i]);
|
||||||
for (LengthT j = 0; j < this->Lengths[i]; j++)
|
for (LengthT j = 0; j < this->Lengths[i]; j++)
|
||||||
printf("%.2X ", ((uint8_t*)this->Values[i])[j]);
|
printf("%.2X ", ((uint8_t*)this->Values[i])[j]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -149,12 +202,12 @@ class KLDRArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get amount of cells in array
|
// Get amount of cells in array
|
||||||
inline size_t CellsAmount () {
|
inline size_t CellsAmount () const {
|
||||||
return this->Keys.size();
|
return this->Keys.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get size of all data in array as if they in packed condition
|
// Get size of all data in array as if they in packed condition
|
||||||
size_t FlatSize () {
|
size_t FlatSize () const {
|
||||||
size_t result = this->Keys.size() * sizeof(KeyT) + this->Lengths.size() * sizeof(LengthT);
|
size_t result = this->Keys.size() * sizeof(KeyT) + this->Lengths.size() * sizeof(LengthT);
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++)
|
for (size_t i = 0; i < this->CellsAmount(); i++)
|
||||||
result += this->Lengths[i];
|
result += this->Lengths[i];
|
||||||
@ -162,7 +215,7 @@ class KLDRArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there are specified key
|
// If there are specified key
|
||||||
bool KeyExists (KeyT key) {
|
bool KeyExists (KeyT key) const {
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
if (this->Keys[i] == key) {
|
if (this->Keys[i] == key) {
|
||||||
return true;
|
return true;
|
||||||
@ -171,25 +224,24 @@ class KLDRArray {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new cell to array, fast version without key checks
|
// Add new cell to array, fast version without key checks, data will be copied
|
||||||
void AddF (KeyT key, LengthT length, void* data) {
|
void AddF (KeyT key, LengthT length, char* data) {
|
||||||
this->Keys.push_back(key);
|
this->Keys.push_back(key);
|
||||||
this->Lengths.push_back(length);
|
this->Lengths.push_back(length);
|
||||||
void* newData = operator new(length); // Yes, allocating memory for void pointer really looks like this
|
char* newData = new char[length];
|
||||||
std::copy((char*)data, (char*)data + length, (char*)newData); // Dirty hacks, YES!
|
std::copy(data, data + length, newData);
|
||||||
this->Values.push_back(newData);
|
this->Values.push_back(newData);
|
||||||
// NOTICE: there is `std::is_pod<SomeType>()`, so may be we can use one more template to make this a little more safe (may be)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new cell to array, but only if key is unique
|
// Add new cell to array, but only if key is unique
|
||||||
void Add (KeyT key, LengthT length, void* data) {
|
void Add (KeyT key, LengthT length, char* data) {
|
||||||
if (this->KeyExists(key))
|
if (this->KeyExists(key))
|
||||||
throw std::invalid_argument("supplied key already exist");
|
throw std::invalid_argument("supplied key already exist");
|
||||||
this->AddF(key, length, data);
|
this->AddF(key, length, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get just pointer to value from array by key
|
// Get just pointer to value from array by key
|
||||||
void* Get (KeyT key) {
|
char* Get (KeyT key) const {
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
if (this->Keys[i] == key) {
|
if (this->Keys[i] == key) {
|
||||||
return this->Values[i];
|
return this->Values[i];
|
||||||
@ -199,7 +251,7 @@ class KLDRArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get pointer to value and length from array by key
|
// Get pointer to value and length from array by key
|
||||||
void* Get (KeyT key, LengthT* length) {
|
char* Get (KeyT key, LengthT* length) const {
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
if (this->Keys[i] == key) {
|
if (this->Keys[i] == key) {
|
||||||
*length = this->Lengths[i];
|
*length = this->Lengths[i];
|
||||||
@ -209,6 +261,8 @@ class KLDRArray {
|
|||||||
throw std::invalid_argument("invalid KLDRArray key");
|
throw std::invalid_argument("invalid KLDRArray key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: get copy of value
|
||||||
|
|
||||||
// Delete cell from array by key
|
// Delete cell from array by key
|
||||||
void Del (KeyT key) {
|
void Del (KeyT key) {
|
||||||
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
for (size_t i = 0; i < this->CellsAmount(); i++) {
|
||||||
@ -240,7 +294,7 @@ class KLDRArray {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,24 @@
|
|||||||
* Stadium.cpp
|
* Stadium.cpp
|
||||||
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
||||||
*
|
*
|
||||||
* -> [ Incoming Events Queue ] --> [ Base Event Handlers ]
|
* API logic:
|
||||||
|
*
|
||||||
|
* -> [ Incoming Events Queue ] ---> [ Base Event Handlers ]
|
||||||
* / \-> [ Custom Event Handlers ]
|
* / \-> [ Custom Event Handlers ]
|
||||||
* [ Transport ] <-> [ StadiumCrypto (optional) ] <- -> [ Expected Event Handlers ]
|
* [ Transport ] <-> [ StadiumCrypto (optional) ] <-> -> [ Expected Event Handlers ]
|
||||||
* \
|
* \
|
||||||
* <- [ Outcoming Events Queue ] <--- [ Base Methods ]
|
* <- [ Outcoming Events Queue ] <--- [ Base Methods ]
|
||||||
* \
|
* \
|
||||||
* <- [ Custom Methods ]
|
* <- [ Custom Methods ]
|
||||||
|
*
|
||||||
|
* Arch logic:
|
||||||
|
*
|
||||||
|
* [ Base Event Handlers ] [ Custom Event Handlers ] [ Base Methods ] [ Custom Methods ]
|
||||||
|
* [ Base Event Management ] [ E2EE ] [ Far-Visibility Integrity Checks ] [ DoS Protection ]
|
||||||
|
* [ Session Management ] [ Direct-Visibility Integrity Checks ] [ DoS Protection ]
|
||||||
|
* [ Several Workers ] [ Event Parser ] [ DoS Protection ]
|
||||||
|
* [ Various Transport Adapters ]
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Stadium.hpp"
|
#include "Stadium.hpp"
|
||||||
|
@ -9,17 +9,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "EventQueue.hpp"
|
#include "Utils.hpp"
|
||||||
|
#include "KLDR.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
#include "Worker.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Stadium {
|
namespace Stadium::v1 {
|
||||||
namespace v1 {
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
// __DATE__ __TIME__
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,28 +10,29 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Stadium {
|
namespace Stadium::Utils {
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
void PrintArray (std::vector<char> arr) {
|
|
||||||
printf("Length: %lu\n", arr.size());
|
|
||||||
|
// Print information about any std-compatible container to stdout
|
||||||
|
template<typename Container>
|
||||||
|
void
|
||||||
|
PrintArray (Container& arr) {
|
||||||
|
printf("Array at %lu; length: %lu\n",
|
||||||
|
reinterpret_cast<size_t>(&arr),
|
||||||
|
arr.size()
|
||||||
|
);
|
||||||
for (size_t i = 0; i < arr.size(); i++)
|
for (size_t i = 0; i < arr.size(); i++)
|
||||||
printf("%.2X ", (uint8_t)arr[i]);
|
printf("%.2X ", (uint8_t)arr[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintArray (char* arr, size_t len) {
|
|
||||||
printf("Length: %lu\n", len);
|
|
||||||
for (size_t i = 0; i < len; i++)
|
|
||||||
printf("%.2X ", (uint8_t)arr[i]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
54
src/Worker.cpp
Normal file
54
src/Worker.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Worker.cpp
|
||||||
|
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Worker.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Stadium::v1 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Create event from raw bytes (ATTENTION: maybe move this method to Event class)
|
||||||
|
Event
|
||||||
|
Worker::ParseRawData (const char* data) {
|
||||||
|
// TODO
|
||||||
|
return Event{};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse ingoing packet data to event, check its properties and put it to queue if all okay
|
||||||
|
void
|
||||||
|
Worker::PutIngoing (const char* data) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send outgoing event (NOTICE: maybe rework)
|
||||||
|
void
|
||||||
|
Worker::PutOutgoing (EventType type, KLDRArray<> data) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind handler for ingoing events
|
||||||
|
void
|
||||||
|
Worker::BindHandler (EventType, void()) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start ingoing event processing loop
|
||||||
|
void
|
||||||
|
Worker::IngoingLoop () {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get single outgoing event from queue and form it to binary
|
||||||
|
std::vector<char>
|
||||||
|
Worker::GetOutgoingDataVec () {
|
||||||
|
return std::vector<char>{}; // TODO: remove
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
52
src/Worker.hpp
Normal file
52
src/Worker.hpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Worker.hpp
|
||||||
|
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBSTADIUM_WORKER_HPP
|
||||||
|
#define LIBSTADIUM_WORKER_HPP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <queue>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "KLDR.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Stadium::v1 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Working class
|
||||||
|
class Worker {
|
||||||
|
private:
|
||||||
|
static bool Running; // If workers are running
|
||||||
|
|
||||||
|
static std::unordered_map<EventType, void()> Handlers; // Map of handlers associated with packet types TODO: may be it can be more optimized with reloaded operators
|
||||||
|
static std::unordered_map<EventAsyncID, Event> ExpectedEvents; // Map of expected events and their async IDs
|
||||||
|
static std::atomic<EventAsyncID> LastAsyncID; // Increments every use of Expect()
|
||||||
|
|
||||||
|
static std::queue<Event> OutgoingEvents; // FIFO of outgoing events
|
||||||
|
static std::queue<Event> IngoingEvents; // FIFO of ingoing events
|
||||||
|
|
||||||
|
public:
|
||||||
|
Event ParseRawData (const char*);
|
||||||
|
void PutIngoing (const char*);
|
||||||
|
void PutOutgoing (EventType, KLDRArray<>);
|
||||||
|
void BindHandler (EventType, void());
|
||||||
|
void IngoingLoop ();
|
||||||
|
std::vector<char> GetOutgoingDataVec ();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
18
src/test.cpp
18
src/test.cpp
@ -4,20 +4,24 @@
|
|||||||
|
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
Stadium::Base::KLDRArray<> arr;
|
Stadium::v1::KLDRArray<> arr;
|
||||||
char str1[] = "goodbye, var?\n";
|
char str1[] = "goodbye, var?\n";
|
||||||
char str2[] = "hello, world!\n";
|
char str2[] = "hello, world!\n";
|
||||||
char str3[] = "fisting\n";
|
char str3[] = "fisting\n";
|
||||||
char str4[] = "IS 300$!!!!!!!!!!!!!!!!!!\n";
|
char str4[] = "IS 300$!!!!!!!!!!!!!!!!!!\n";
|
||||||
char str5[] = "a)\n";
|
char str5[] = "a)\n";
|
||||||
arr.Add(Stadium::Base::KLDRDefaultKeys::Data, sizeof(str1), (void*)&str1);
|
arr.Add(Stadium::v1::KLDRDefaultKeys::Data, sizeof(str1), (char*)&str1);
|
||||||
arr.Add(Stadium::Base::KLDRDefaultKeys::ObjectID, sizeof(str2), (void*)&str2);
|
arr.Add(Stadium::v1::KLDRDefaultKeys::ObjectID, sizeof(str2), (char*)&str2);
|
||||||
arr.Add(0xF4, sizeof(str3), (void*)&str3);
|
arr.Add(0xF4, sizeof(str3), (char*)&str3);
|
||||||
arr.Add(0x6a, sizeof(str4), (void*)&str4);
|
arr.Add(0x6a, sizeof(str4), (char*)&str4);
|
||||||
arr.Add(Stadium::Base::KLDRDefaultKeys::SignedDataHash, sizeof(str5), (void*)&str5);
|
arr.Add(Stadium::v1::KLDRDefaultKeys::SignedDataHash, sizeof(str5), (char*)&str5);
|
||||||
std::cout << "Shuffling!" << std::endl;
|
|
||||||
arr.Shuffle();
|
arr.Shuffle();
|
||||||
arr.Print();
|
arr.Print();
|
||||||
|
|
||||||
|
Stadium::v1::Event e{0x01, 0xf4, std::move(arr), 54};
|
||||||
|
e.Print();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user