From 76da2ebe6d26e140b22f2690301e09c164861836 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Sun, 7 Jun 2026 16:10:03 +0200 Subject: [PATCH 01/53] update: fix viewport --- flake.nix | 2 +- lib/ttp2/src/networking.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 1b9edca..1362824 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.3"; + version = "1.9.4"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 488caf5..b6e9148 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -192,10 +192,10 @@ namespace ttp2 { // Y int yStart = std::get(payload).yStart; - status = asn1_write_value(packet, "payload.viewport.xStart", + status = asn1_write_value(packet, "payload.viewport.yStart", &yStart, sizeof(yStart)); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport xStart failed!" << std::endl; + std::wcout << "ASN1 set viewport yStart failed!" << std::endl; } int yEnd = std::get(payload).yEnd; From 0b8cb05399fa95d46e4b5de5222982f6d1c97def Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Sun, 7 Jun 2026 16:13:26 +0200 Subject: [PATCH 02/53] update: fix viewport --- flake.nix | 2 +- lib/ttp2/src/networking.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 1362824..381787b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.4"; + version = "1.9.5"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index b6e9148..5d28c1f 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -207,7 +207,7 @@ namespace ttp2 { std::string filePayload = std::get(payload).payload; const char *filePayloadChar = filePayload.c_str(); - status = asn1_write_value(packet, "payload.file.filePath", + status = asn1_write_value(packet, "payload.viewport.payload", filePayloadChar, strlen(filePayloadChar)); if (status != ASN1_SUCCESS) { std::wcout << "ASN1 set viewport payload failed!" << std::endl; From 1acf7894c20e81f401f92b04645a1f0e80912548 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Wed, 10 Jun 2026 16:10:20 +0200 Subject: [PATCH 03/53] update: fix struct viewport --- lib/ttp2/include/networking.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 3bfccf9..4a93a7d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -23,11 +23,11 @@ namespace ttp2 { }; struct Viewport { - int xStart; - int xEnd; - int yStart; - int yEnd; - std::string payload; + int xStart = 0; + int xEnd = 0; + int yStart = 0; + int yEnd = 0; + std::string payload = ""; }; typedef std::variant payloadVariants; From 3f83c560612ea67586b789107c3e88a5952be9f7 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Wed, 10 Jun 2026 16:10:53 +0200 Subject: [PATCH 04/53] update: flake version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 381787b..5e3efa3 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.5"; + version = "1.9.6"; commonDeps = with pkgs; [ cmake From dc2a9043414c380d1cbfeb691c42881770e8e848 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 11 Jun 2026 08:46:05 +0200 Subject: [PATCH 05/53] update: generalize asn1_write_value, #19 --- lib/ttp2/include/networking.h | 8 +++ lib/ttp2/src/networking.cpp | 94 ++++++++++++++--------------------- 2 files changed, 44 insertions(+), 58 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 4a93a7d..e06ef60 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -7,6 +7,11 @@ #include #include +extern "C" { +#include +extern const asn1_static_node packets_asn1_tab[]; +} + namespace ttp2 { class Networking { @@ -70,6 +75,9 @@ namespace ttp2 { std::map> sessionBuffers; int autoId; + + asn1_node asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key); + asn1_node asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key); }; } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 5d28c1f..bffc1c1 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -118,14 +118,8 @@ namespace ttp2 { // Write contents std::string standardPayloadString = std::get(payload).payload; - const char *standardPayload = standardPayloadString.c_str(); + packet = asn1EncodePayload(standardPayloadString, packet, "payload.standard.payload"); - status = asn1_write_value(packet, "payload.standard.payload", - standardPayload, strlen(standardPayload)); - - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set standard payload failed!" << std::endl; - } } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "file", 0); @@ -136,36 +130,17 @@ namespace ttp2 { // Write contents std::string filePathString = std::get(payload).filePath; - const char *filePath = filePathString.c_str(); - status = asn1_write_value(packet, "payload.file.filePath", - filePath, strlen(filePath)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set filepath failed!" << std::endl; - } - - int start = std::get(payload).start; - status = asn1_write_value(packet, "payload.file.start", - &start, sizeof(start)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set file start failed!" << std::endl; - } + packet = asn1EncodePayload(filePathString, packet, "payload.file.filePath"); + int start = std::get(payload).start; + packet = asn1EncodePayload(start, packet, "payload.file.start"); int end = std::get(payload).end; - status = asn1_write_value(packet, "payload.file.end", - &end, sizeof(end)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set file end failed!" << std::endl; - } - + packet = asn1EncodePayload(end, packet, "payload.file.end"); std::string filePayloadString = std::get(payload).payload; - const char *filePayload = filePayloadString.c_str(); - status = asn1_write_value(packet, "payload.file.payload", - filePayload, strlen(filePayload)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set file payload failed!" << std::endl; - } + packet = asn1EncodePayload(filePayloadString, packet, "payload.file.payload"); + } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "viewport", 0); @@ -177,41 +152,20 @@ namespace ttp2 { // Write content // X int xStart = std::get(payload).xStart; - status = asn1_write_value(packet, "payload.viewport.xStart", - &xStart, sizeof(xStart)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport xStart failed!" << std::endl; - } + packet = asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); int xEnd = std::get(payload).xEnd; - status = asn1_write_value(packet, "payload.viewport.xEnd", - &xEnd, sizeof(xEnd)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport xEnd failed!" << std::endl; - } + packet = asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); // Y int yStart = std::get(payload).yStart; - status = asn1_write_value(packet, "payload.viewport.yStart", - &yStart, sizeof(yStart)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport yStart failed!" << std::endl; - } + packet = asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); int yEnd = std::get(payload).yEnd; - status = asn1_write_value(packet, "payload.viewport.yEnd", - &yEnd, sizeof(yEnd)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport yEnd failed!" << std::endl; - } + packet = asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); std::string filePayload = std::get(payload).payload; - const char *filePayloadChar = filePayload.c_str(); - status = asn1_write_value(packet, "payload.viewport.payload", - filePayloadChar, strlen(filePayloadChar)); - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set viewport payload failed!" << std::endl; - } + packet = asn1EncodePayload(filePayload, packet, "payload.viewport.payload"); } int derLen = 0; @@ -557,4 +511,28 @@ namespace ttp2 { } return result; } + + asn1_node Networking::asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key) { + const char *standardPayload = payload.c_str(); + + int status = asn1_write_value(packet, asn1Key, + standardPayload, strlen(standardPayload)); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + } + + return packet; + } + + asn1_node Networking::asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key) { + int status = asn1_write_value(packet, asn1Key, + &payload, sizeof(payload)); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + } + + return packet; + } } From ffc203712e2629ea01228e07a4af736c18d6a509 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 11 Jun 2026 09:46:50 +0200 Subject: [PATCH 06/53] update: generalize asn1_read_value, closes #19 --- lib/ttp2/include/networking.h | 3 + lib/ttp2/src/networking.cpp | 148 +++++++++------------------------- 2 files changed, 41 insertions(+), 110 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index e06ef60..2dc6347 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -78,6 +78,9 @@ namespace ttp2 { asn1_node asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key); asn1_node asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key); + + std::string asn1DecodePayloadString(asn1_node packet, const char* asn1Key); + int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); }; } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index bffc1c1..3f6822e 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -257,123 +257,25 @@ namespace ttp2 { int status = asn1_read_value(packet, "payload", typeName, &branchSize); std::string typeNameString = typeName; if (typeNameString == "standard") { - int payloadLen = 0; - asn1_read_value(packet, "payload.standard.payload", nullptr, &payloadLen); - if (payloadLen > 0) { - std::vector payloadStr(payloadLen); - asn1_read_value(packet, "payload.standard.payload", payloadStr.data(), - &payloadLen); + Networking::Standard standard; + standard.payload = asn1DecodePayloadString(packet, "payload.standard.payload"); - Networking::Standard standard; - standard.payload.assign(payloadStr.data(), payloadLen); - - data.payload = standard; - } + data.payload = standard; } else if (typeNameString == "file") { - int filePathLen = 0; - std::vector filePathStr(filePathLen); - asn1_read_value(packet, "payload.file.filePath", nullptr, &filePathLen); - if (filePathLen > 0) { - filePathStr.resize(filePathLen); - asn1_read_value(packet, "payload.file.filePath", filePathStr.data(), - &filePathLen); - } - - int fileStartLen = 0; - std::vector fileStartBytes(fileStartLen); - asn1_read_value(packet, "payload.file.start", nullptr, &fileStartLen); - if (fileStartLen > 0) { - fileStartBytes.resize(fileStartLen); - asn1_read_value(packet, "payload.file.start", fileStartBytes.data(), - &fileStartLen); - } - int fileStart = bytesToInt(fileStartBytes, fileStartLen); - - int fileEndLen = 0; - std::vector fileEndBytes(fileEndLen); - asn1_read_value(packet, "payload.file.end", nullptr, &fileEndLen); - if (fileEndLen > 0) { - fileEndBytes.resize(fileEndLen); - asn1_read_value(packet, "payload.file.end", fileEndBytes.data(), - &fileEndLen); - } - int fileEnd = bytesToInt(fileEndBytes, fileEndLen); - - int payloadLen = 0; - std::vector payloadStr(payloadLen); - asn1_read_value(packet, "payload.file.payload", nullptr, &payloadLen); - if (payloadLen > 0) { - payloadStr.resize(payloadLen); - asn1_read_value(packet, "payload.file.payload", payloadStr.data(), - &payloadLen); - } - Networking::File file; - file.payload.assign(filePathStr.data(), filePathLen); - file.start = fileStart; - file.end = fileEnd; - file.payload.assign(payloadStr.data(), payloadLen); + file.filePath = asn1DecodePayloadString(packet, "payload.file.filePath"); + file.start = asn1DecodePayloadInt(packet, "payload.file.start"); + file.end = asn1DecodePayloadInt(packet, "payload.file.end"); + file.payload = asn1DecodePayloadString(packet, "payload.file.payload"); data.payload = file; } else if (typeNameString == "viewport") { - // X - int xStartLen = 0; - std::vector xStartBytes(xStartLen); - asn1_read_value(packet, "payload.viewport.xStart", nullptr, &xStartLen); - if (xStartLen > 0) { - xStartBytes.resize(xStartLen); - asn1_read_value(packet, "payload.viewport.xStart", xStartBytes.data(), - &xStartLen); - } - int xStart = bytesToInt(xStartBytes, xStartLen); - - int xEndLen = 0; - std::vector xEndBytes(xEndLen); - asn1_read_value(packet, "payload.viewport.xEnd", nullptr, &xEndLen); - if (xEndLen > 0) { - xEndBytes.resize(xEndLen); - asn1_read_value(packet, "payload.viewport.xEnd", xEndBytes.data(), - &xEndLen); - } - int xEnd = bytesToInt(xEndBytes, xEndLen); - - // Y - int yStartLen = 0; - std::vector yStartBytes(yStartLen); - asn1_read_value(packet, "payload.viewport.yStart", nullptr, &yStartLen); - if (yStartLen > 0) { - yStartBytes.resize(yStartLen); - asn1_read_value(packet, "payload.viewport.yStart", yStartBytes.data(), - &yStartLen); - } - int yStart = bytesToInt(yStartBytes, yStartLen); - - int yEndLen = 0; - std::vector yEndBytes(yEndLen); - asn1_read_value(packet, "payload.viewport.yEnd", nullptr, &yEndLen); - if (yEndLen > 0) { - yEndBytes.resize(yEndLen); - asn1_read_value(packet, "payload.viewport.yEnd", yEndBytes.data(), - &yEndLen); - } - int yEnd = bytesToInt(yEndBytes, yEndLen); - - // Payload - int payloadLen = 0; - std::vector payloadStr(payloadLen); - asn1_read_value(packet, "payload.viewport.payload", nullptr, &payloadLen); - if (payloadLen > 0) { - payloadStr.resize(payloadLen); - asn1_read_value(packet, "payload.viewport.payload", payloadStr.data(), - &payloadLen); - } - Networking::Viewport viewport; - viewport.xStart = xStart; - viewport.xEnd = xEnd; - viewport.yStart = yStart; - viewport.yEnd = yEnd; - viewport.payload.assign(payloadStr.data(), payloadLen); + viewport.xStart = asn1DecodePayloadInt(packet, "payload.viewport.xStart"); + viewport.xEnd = asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); + viewport.yStart = asn1DecodePayloadInt(packet, "payload.viewport.yStart"); + viewport.yEnd = asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); + viewport.payload = asn1DecodePayloadString(packet, "payload.viewport.payload"); data.payload = viewport; } else { @@ -535,4 +437,30 @@ namespace ttp2 { return packet; } + + std::string Networking::asn1DecodePayloadString(asn1_node packet, const char* asn1Key) { + int payloadLen = 0; + std::vector payloadStr(payloadLen); + asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + if (payloadLen > 0) { + payloadStr.resize(payloadLen); + asn1_read_value(packet, asn1Key, payloadStr.data(), + &payloadLen); + } + std::string result = ""; + result.assign(payloadStr.data(), payloadLen); + return result; + } + + int Networking::asn1DecodePayloadInt(asn1_node packet, const char* asn1Key) { + int payloadLen = 0; + std::vector payloadBytes(payloadLen); + asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + if (payloadLen > 0) { + payloadBytes.resize(payloadLen); + asn1_read_value(packet, asn1Key, payloadBytes.data(), + &payloadLen); + } + return bytesToInt(payloadBytes, payloadLen); + } } From b8c6f944bf9137063577dfc7c3184201e38982f0 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 11 Jun 2026 09:47:20 +0200 Subject: [PATCH 07/53] update: flake version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5e3efa3..5f2d5d0 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.6"; + version = "1.9.7"; commonDeps = with pkgs; [ cmake From 79d67aa2c872c3736e0fbc941cae782a83e8cb74 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 11 Jun 2026 20:41:54 +0200 Subject: [PATCH 08/53] update: move ans1 read and write value to asn1_helpers --- lib/ttp2/include/asn1_helpers.h | 26 ++++++++++ lib/ttp2/include/networking.h | 11 ---- lib/ttp2/src/asn1_helpers.cpp | 75 +++++++++++++++++++++++++++ lib/ttp2/src/networking.cpp | 91 ++++++++------------------------- 4 files changed, 122 insertions(+), 81 deletions(-) create mode 100644 lib/ttp2/include/asn1_helpers.h create mode 100644 lib/ttp2/src/asn1_helpers.cpp diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h new file mode 100644 index 0000000..ca5ae13 --- /dev/null +++ b/lib/ttp2/include/asn1_helpers.h @@ -0,0 +1,26 @@ +#ifndef ASN1_HELPERS_H +#define ASN1_HELPERS_H + +#include +#include + +extern "C" { +#include +extern const asn1_static_node packets_asn1_tab[]; +} + +namespace ttp2 { + class Asn1Helpers { + public: + static asn1_node asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key); + static asn1_node asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key); + + static std::string asn1DecodePayloadString(asn1_node packet, const char* asn1Key); + static int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); + + private: + static int bytesToInt(std::vector bytes, int size); + }; +} + +#endif diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 2dc6347..4a93a7d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -7,11 +7,6 @@ #include #include -extern "C" { -#include -extern const asn1_static_node packets_asn1_tab[]; -} - namespace ttp2 { class Networking { @@ -75,12 +70,6 @@ namespace ttp2 { std::map> sessionBuffers; int autoId; - - asn1_node asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key); - asn1_node asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key); - - std::string asn1DecodePayloadString(asn1_node packet, const char* asn1Key); - int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); }; } diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp new file mode 100644 index 0000000..8e39188 --- /dev/null +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -0,0 +1,75 @@ +#include "../include/asn1_helpers.h" + +#include +#include +#include +#include + +extern "C" { +#include +extern const asn1_static_node packets_asn1_tab[]; +} + +using namespace std; + +namespace ttp2 { + asn1_node Asn1Helpers::asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key) { + const char *standardPayload = payload.c_str(); + + int status = asn1_write_value(packet, asn1Key, + standardPayload, std::strlen(standardPayload)); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + } + + return packet; + } + + asn1_node Asn1Helpers::asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key) { + int status = asn1_write_value(packet, asn1Key, + &payload, sizeof(payload)); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + } + + return packet; + } + + std::string Asn1Helpers::asn1DecodePayloadString(asn1_node packet, const char* asn1Key) { + int payloadLen = 0; + std::vector payloadStr(payloadLen); + asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + if (payloadLen > 0) { + payloadStr.resize(payloadLen); + asn1_read_value(packet, asn1Key, payloadStr.data(), + &payloadLen); + } + std::string result = ""; + result.assign(payloadStr.data(), payloadLen); + return result; + } + + int Asn1Helpers::asn1DecodePayloadInt(asn1_node packet, const char* asn1Key) { + int payloadLen = 0; + std::vector payloadBytes(payloadLen); + asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + if (payloadLen > 0) { + payloadBytes.resize(payloadLen); + asn1_read_value(packet, asn1Key, payloadBytes.data(), + &payloadLen); + } + return bytesToInt(payloadBytes, payloadLen); + } + + int Asn1Helpers::bytesToInt(std::vector bytes, int size) { + int result = 0; + for (int index = 0; index < size; index++) + { + result <<= 8; + result |= (bytes[index] & 0xFF); + } + return result; + } +} diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 3f6822e..02cf990 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -1,4 +1,5 @@ #include "../include/networking.h" +#include "../include/asn1_helpers.h" #include #include @@ -118,7 +119,7 @@ namespace ttp2 { // Write contents std::string standardPayloadString = std::get(payload).payload; - packet = asn1EncodePayload(standardPayloadString, packet, "payload.standard.payload"); + packet = Asn1Helpers::asn1EncodePayload(standardPayloadString, packet, "payload.standard.payload"); } else if (std::holds_alternative(payload)) { // Write structure @@ -130,16 +131,16 @@ namespace ttp2 { // Write contents std::string filePathString = std::get(payload).filePath; - packet = asn1EncodePayload(filePathString, packet, "payload.file.filePath"); + packet = Asn1Helpers::asn1EncodePayload(filePathString, packet, "payload.file.filePath"); int start = std::get(payload).start; - packet = asn1EncodePayload(start, packet, "payload.file.start"); + packet = Asn1Helpers::asn1EncodePayload(start, packet, "payload.file.start"); int end = std::get(payload).end; - packet = asn1EncodePayload(end, packet, "payload.file.end"); + packet = Asn1Helpers::asn1EncodePayload(end, packet, "payload.file.end"); std::string filePayloadString = std::get(payload).payload; - packet = asn1EncodePayload(filePayloadString, packet, "payload.file.payload"); + packet = Asn1Helpers::asn1EncodePayload(filePayloadString, packet, "payload.file.payload"); } else if (std::holds_alternative(payload)) { // Write structure @@ -152,20 +153,20 @@ namespace ttp2 { // Write content // X int xStart = std::get(payload).xStart; - packet = asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); + packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); int xEnd = std::get(payload).xEnd; - packet = asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); + packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); // Y int yStart = std::get(payload).yStart; - packet = asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); + packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); int yEnd = std::get(payload).yEnd; - packet = asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); + packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); std::string filePayload = std::get(payload).payload; - packet = asn1EncodePayload(filePayload, packet, "payload.viewport.payload"); + packet = Asn1Helpers::asn1EncodePayload(filePayload, packet, "payload.viewport.payload"); } int derLen = 0; @@ -258,24 +259,24 @@ namespace ttp2 { std::string typeNameString = typeName; if (typeNameString == "standard") { Networking::Standard standard; - standard.payload = asn1DecodePayloadString(packet, "payload.standard.payload"); + standard.payload = Asn1Helpers::asn1DecodePayloadString(packet, "payload.standard.payload"); data.payload = standard; } else if (typeNameString == "file") { Networking::File file; - file.filePath = asn1DecodePayloadString(packet, "payload.file.filePath"); - file.start = asn1DecodePayloadInt(packet, "payload.file.start"); - file.end = asn1DecodePayloadInt(packet, "payload.file.end"); - file.payload = asn1DecodePayloadString(packet, "payload.file.payload"); + file.filePath = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.filePath"); + file.start = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.start"); + file.end = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.end"); + file.payload = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.payload"); data.payload = file; } else if (typeNameString == "viewport") { Networking::Viewport viewport; - viewport.xStart = asn1DecodePayloadInt(packet, "payload.viewport.xStart"); - viewport.xEnd = asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); - viewport.yStart = asn1DecodePayloadInt(packet, "payload.viewport.yStart"); - viewport.yEnd = asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); - viewport.payload = asn1DecodePayloadString(packet, "payload.viewport.payload"); + viewport.xStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xStart"); + viewport.xEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); + viewport.yStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yStart"); + viewport.yEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); + viewport.payload = Asn1Helpers::asn1DecodePayloadString(packet, "payload.viewport.payload"); data.payload = viewport; } else { @@ -413,54 +414,4 @@ namespace ttp2 { } return result; } - - asn1_node Networking::asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key) { - const char *standardPayload = payload.c_str(); - - int status = asn1_write_value(packet, asn1Key, - standardPayload, strlen(standardPayload)); - - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; - } - - return packet; - } - - asn1_node Networking::asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key) { - int status = asn1_write_value(packet, asn1Key, - &payload, sizeof(payload)); - - if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; - } - - return packet; - } - - std::string Networking::asn1DecodePayloadString(asn1_node packet, const char* asn1Key) { - int payloadLen = 0; - std::vector payloadStr(payloadLen); - asn1_read_value(packet, asn1Key, nullptr, &payloadLen); - if (payloadLen > 0) { - payloadStr.resize(payloadLen); - asn1_read_value(packet, asn1Key, payloadStr.data(), - &payloadLen); - } - std::string result = ""; - result.assign(payloadStr.data(), payloadLen); - return result; - } - - int Networking::asn1DecodePayloadInt(asn1_node packet, const char* asn1Key) { - int payloadLen = 0; - std::vector payloadBytes(payloadLen); - asn1_read_value(packet, asn1Key, nullptr, &payloadLen); - if (payloadLen > 0) { - payloadBytes.resize(payloadLen); - asn1_read_value(packet, asn1Key, payloadBytes.data(), - &payloadLen); - } - return bytesToInt(payloadBytes, payloadLen); - } } From 6c68f6ad6baa9bfc595efdfffef269b7f3f84da9 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 11 Jun 2026 20:42:19 +0200 Subject: [PATCH 09/53] update: flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5f2d5d0..dcda559 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.7"; + version = "1.9.8"; commonDeps = with pkgs; [ cmake From 4cedd96e258d04a48a994e75f0e01eb404c6d3d6 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 12 Jun 2026 19:32:02 +0200 Subject: [PATCH 10/53] update: make helper functions static --- lib/ttp2/include/networking.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 4a93a7d..0b27ef1 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -52,9 +52,9 @@ namespace ttp2 { int sendPacket(int socket, Packet packet); Packet receiveMessage(int socket); - std::string getBroadcastIpAddress(); - std::string getLocalIpAddress(std::string interface); - bool isValidIpV4(std::string &ipString); + static std::string getBroadcastIpAddress(); + static std::string getLocalIpAddress(std::string interface); + static bool isValidIpV4(std::string &ipString); protected: bool connected = true; From 5b6b6864d3fce60a47337956e2a7c61d2b98d704 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 12 Jun 2026 19:32:28 +0200 Subject: [PATCH 11/53] update: update version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index dcda559..03ad8b4 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.8"; + version = "1.9.9"; commonDeps = with pkgs; [ cmake From af25b69cc7059e50af49992304a63f90e9ef2f59 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Sun, 14 Jun 2026 11:16:05 +0200 Subject: [PATCH 12/53] update: add isValidInterface --- flake.nix | 2 +- lib/ttp2/include/networking.h | 1 + lib/ttp2/src/networking.cpp | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 03ad8b4..54ad6e3 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.9"; + version = "1.9.10"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 0b27ef1..0326a44 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -55,6 +55,7 @@ namespace ttp2 { static std::string getBroadcastIpAddress(); static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); + static bool isValidInterface(std::string interface); protected: bool connected = true; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 02cf990..6415f56 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -13,6 +13,7 @@ #include #include #include +#include extern "C" { #include @@ -414,4 +415,21 @@ namespace ttp2 { } return result; } + + bool isValidInterface(std::string interface) { + struct ifaddrs *addresses; + getifaddrs(&addresses); + + bool isValid = false; + for (struct ifaddrs *address = addresses; address != nullptr; address = address->ifa_next) { + if (address->ifa_addr && address->ifa_addr->sa_family == AF_PACKET) { + if (address->ifa_name == interface) { + isValid = true; + } + } + } + + freeifaddrs(addresses); + return isValid; + } } From 39ea85c8afbd4be46766259c977eee0c5d347490 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Sun, 14 Jun 2026 11:28:19 +0200 Subject: [PATCH 13/53] update: fixup isValidInterface --- flake.nix | 2 +- lib/ttp2/include/networking.h | 2 +- lib/ttp2/src/networking.cpp | 2 +- test/server/main.cpp | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 54ad6e3..c8b02d6 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.10"; + version = "1.9.11"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 0326a44..0dae5d9 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -55,7 +55,7 @@ namespace ttp2 { static std::string getBroadcastIpAddress(); static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); - static bool isValidInterface(std::string interface); + static bool isValidInterface(std::string &interface); protected: bool connected = true; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 6415f56..54fd919 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -416,7 +416,7 @@ namespace ttp2 { return result; } - bool isValidInterface(std::string interface) { + bool Networking::isValidInterface(std::string &interface) { struct ifaddrs *addresses; getifaddrs(&addresses); diff --git a/test/server/main.cpp b/test/server/main.cpp index fb0c384..03c381f 100644 --- a/test/server/main.cpp +++ b/test/server/main.cpp @@ -62,6 +62,11 @@ int main() { std::string interface = requestString("Interface (string): "); int port = requestInt("Server port (int): "); + if (!ServerSessionController::isValidInterface(interface)) { + std::wcout << "Please provide a correct interface" << std::endl; + return -1; + } + ServerSessionController tempServerSessionController; std::string containerIP = tempServerSessionController.getLocalIpAddress(interface); From 2541989eaf72d7bd865e8d7011b521a3c0395ff7 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 21 Jun 2026 14:08:41 +0200 Subject: [PATCH 14/53] update: add apache arrow --- flake.nix | 1 + test/client/CMakeLists.txt | 2 ++ test/server/CMakeLists.txt | 2 ++ 3 files changed, 5 insertions(+) diff --git a/flake.nix b/flake.nix index c8b02d6..9deb5c9 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ gcc gnumake libtasn1 + arrow-cpp ]; mkTTP2Package = diff --git a/test/client/CMakeLists.txt b/test/client/CMakeLists.txt index fc92da1..cd28d80 100644 --- a/test/client/CMakeLists.txt +++ b/test/client/CMakeLists.txt @@ -9,5 +9,7 @@ file(GLOB_RECURSE SOURCES "./*.cpp" "./*.h") add_executable(ttp2-client ${SOURCES}) target_link_libraries(ttp2-client PRIVATE ttp2) +find_package(Arrow REQUIRED) +target_link_libraries(ttp2-client PRIVATE Arrow::arrow_shared) install(TARGETS ttp2-client DESTINATION bin) diff --git a/test/server/CMakeLists.txt b/test/server/CMakeLists.txt index d3f4c2e..41bf1a7 100644 --- a/test/server/CMakeLists.txt +++ b/test/server/CMakeLists.txt @@ -9,5 +9,7 @@ file(GLOB_RECURSE SOURCES "./*.cpp" "./*.h") add_executable(ttp2-server ${SOURCES}) target_link_libraries(ttp2-server PRIVATE ttp2) +find_package(Arrow REQUIRED) +target_link_libraries(ttp2-server PRIVATE Arrow::arrow_shared) install(TARGETS ttp2-server DESTINATION bin) From 2d76e2e88f4e9895af5458ded0f46b4b29bda961 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 21 Jun 2026 14:27:24 +0200 Subject: [PATCH 15/53] update: add open file option --- test/client/main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/client/main.cpp b/test/client/main.cpp index 689f194..1049fef 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace ttp2; @@ -68,7 +69,7 @@ int main() { break; } - int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Exit\nnumber: "); + int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) Exit\nnumber: "); if (option == 1) { std::string payload = requestString("(string) Payload: "); @@ -138,6 +139,16 @@ int main() { std::wcout << "Invalid!" << std::endl; } } else if (option == 4) { + std::string filePath { "" }; + do { + if (filePath.length() > 0 && !std::filesystem::exists(filePath)) { + std::wcout << "Incorrect filepath!" << std::endl; + } + filePath = requestString("(string) Filepath: "); + } while (!std::filesystem::exists(filePath)); + std::wcout << "Success!" << std::endl; + + } else if (option == 5) { clientSessionController->disconnect(); } else { std::wcout << "Invalid!" << std::endl; From 28ba25b9778e02fb7a0fb3da2897fb0e5649df2a Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 21 Jun 2026 15:51:38 +0200 Subject: [PATCH 16/53] update: open csv file --- test/client/main.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/client/main.cpp b/test/client/main.cpp index 1049fef..f90bdab 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -1,5 +1,6 @@ #include "client_session_controller.h" +#include #include #include #include @@ -8,6 +9,8 @@ #include #include #include +#include +#include using namespace ttp2; @@ -146,8 +149,43 @@ int main() { } filePath = requestString("(string) Filepath: "); } while (!std::filesystem::exists(filePath)); - std::wcout << "Success!" << std::endl; + arrow::io::IOContext ioContext = arrow::io::default_io_context(); + + arrow::Result> maybeFile = arrow::io::ReadableFile::Open(filePath); + std::shared_ptr fileInput = *maybeFile; + + arrow::csv::ReadOptions readOptions = arrow::csv::ReadOptions::Defaults(); + arrow::csv::ParseOptions parseOptions = arrow::csv::ParseOptions::Defaults(); + arrow::csv::ConvertOptions convertOptions = arrow::csv::ConvertOptions::Defaults(); + + arrow::Result> maybeReader = arrow::csv::TableReader::Make(ioContext, + fileInput, + readOptions, + parseOptions, + convertOptions); + if (!maybeReader.ok()) { + std::wcout << "Error while instantiating TableReader!" << std::endl; + continue; + } + std::shared_ptr reader = *maybeReader; + + arrow::Result> maybeTable = reader->Read(); + if (!maybeTable.ok()) { + std::wcout << "Error while read table from CSV file!" << std::endl; + continue; + } + std::shared_ptr table = *maybeTable; + std::wcout << table->ToString().c_str() << std::endl; + + // TODO: + // ClientSessionController::Packet packet; + // clientSessionController::File file; + // file.start = 0; + // file.end = table->num_rows(); + // file.payload = table; + // packet.payload = file; + // clientSessionController->pushRequest(packet); } else if (option == 5) { clientSessionController->disconnect(); } else { From 82bc8ec4f8a154714e1b269da16649ca5b7e480e Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 23 Jun 2026 16:08:33 +0200 Subject: [PATCH 17/53] update: add tableToBuffer --- lib/ttp2/include/networking.h | 7 +++++++ lib/ttp2/src/networking.cpp | 30 ++++++++++++++++++++++++++++++ test/client/main.cpp | 2 ++ 3 files changed, 39 insertions(+) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 0dae5d9..4719db5 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -6,6 +6,10 @@ #include #include #include +#include +#include +#include +#include namespace ttp2 { class Networking @@ -56,6 +60,9 @@ namespace ttp2 { static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); static bool isValidInterface(std::string &interface); + + // TODO: move to protected later + static std::shared_ptr tableToBuffer(const std::shared_ptr& table); protected: bool connected = true; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 54fd919..65c28d4 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -2,10 +2,17 @@ #include "../include/asn1_helpers.h" #include +#include +#include +#include +#include +#include +#include #include #include #include #include +#include #include #include #include @@ -14,6 +21,9 @@ #include #include #include +#include +#include +#include extern "C" { #include @@ -432,4 +442,24 @@ namespace ttp2 { freeifaddrs(addresses); return isValid; } + + std::shared_ptr Networking::tableToBuffer(const std::shared_ptr& table) { + // Create output buffer with table structure + std::shared_ptr outputStream = *arrow::io::BufferOutputStream::Create(); + std::shared_ptr streamWriter = *arrow::ipc::MakeStreamWriter(outputStream, table->schema()); + arrow::Status status = streamWriter->WriteTable(*table); + + if (!status.ok()) { + std::wcout << "Something went wrong while writing the structure!" << std::endl; + } + + streamWriter->Close(); + arrow::Result> buffer = outputStream->Finish(); + + if (!buffer.ok()) { + std::wcout << "Something went wrong while converting table to buffer!" << std::endl; + } + + return *buffer; + } } diff --git a/test/client/main.cpp b/test/client/main.cpp index f90bdab..95163d3 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -178,6 +178,8 @@ int main() { std::shared_ptr table = *maybeTable; std::wcout << table->ToString().c_str() << std::endl; + std::shared_ptr buffer = ClientSessionController::tableToBuffer(table); + // TODO: // ClientSessionController::Packet packet; // clientSessionController::File file; From 74b2158100f801ff0ea7eae38502a34e23817343 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 23 Jun 2026 16:49:42 +0200 Subject: [PATCH 18/53] update: add bufferToTable --- lib/ttp2/include/networking.h | 1 + lib/ttp2/src/networking.cpp | 10 ++++++++++ test/client/main.cpp | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 4719db5..b71dbaf 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -63,6 +63,7 @@ namespace ttp2 { // TODO: move to protected later static std::shared_ptr tableToBuffer(const std::shared_ptr& table); + static std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); protected: bool connected = true; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 65c28d4..6dd1f61 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include extern "C" { #include @@ -462,4 +464,12 @@ namespace ttp2 { return *buffer; } + + std::shared_ptr Networking::bufferToTable(const uint8_t* rawData, int64_t dataSize) { + std::shared_ptr buffer = arrow::Buffer::Wrap(rawData, dataSize); + std::shared_ptr inputStream = std::make_shared(buffer); + std::shared_ptr stream_reader = *arrow::ipc::RecordBatchStreamReader::Open(inputStream); + std::shared_ptr table = *stream_reader->ToTable(); + return table; + } } diff --git a/test/client/main.cpp b/test/client/main.cpp index 95163d3..98fee25 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -179,7 +179,13 @@ int main() { std::wcout << table->ToString().c_str() << std::endl; std::shared_ptr buffer = ClientSessionController::tableToBuffer(table); + const uint8_t* bufferData = buffer->data(); + int64_t bufferSize = buffer->size(); + + std::shared_ptr table2 = ClientSessionController::bufferToTable(bufferData, bufferSize); + std::wcout << "Table2 " << table2->ToString().c_str() << std::endl; + // TODO: // ClientSessionController::Packet packet; // clientSessionController::File file; From 30c5ac6e87bec4f0c0f4d034ab72137346fca6a1 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:24:03 +0200 Subject: [PATCH 19/53] update: asn1 encode table buffer --- lib/ttp2/include/asn1_helpers.h | 2 ++ lib/ttp2/src/asn1_helpers.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h index ca5ae13..b6b3280 100644 --- a/lib/ttp2/include/asn1_helpers.h +++ b/lib/ttp2/include/asn1_helpers.h @@ -3,6 +3,7 @@ #include #include +#include extern "C" { #include @@ -14,6 +15,7 @@ namespace ttp2 { public: static asn1_node asn1EncodePayload(std::string payload, asn1_node packet, const char* asn1Key); static asn1_node asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key); + static asn1_node asn1EncodePayload(const uint8_t* buffer, int size, asn1_node packet, const char* asn1Key); static std::string asn1DecodePayloadString(asn1_node packet, const char* asn1Key); static int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 8e39188..0de2800 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -4,6 +4,7 @@ #include #include #include +#include extern "C" { #include @@ -37,6 +38,19 @@ namespace ttp2 { return packet; } + asn1_node Asn1Helpers::asn1EncodePayload(const uint8_t* buffer, int size, asn1_node packet, const char* asn1Key) { + void* targetBuffer = const_cast(buffer); + + int status = asn1_write_value(packet, asn1Key, targetBuffer, size); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + } + + return packet; + + } + std::string Asn1Helpers::asn1DecodePayloadString(asn1_node packet, const char* asn1Key) { int payloadLen = 0; std::vector payloadStr(payloadLen); From 9a401ab6dcda78cd15fca2b5c9806acca7d8dea9 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:32:19 +0200 Subject: [PATCH 20/53] update: asn1 decode buffer --- lib/ttp2/include/asn1_helpers.h | 1 + lib/ttp2/src/asn1_helpers.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h index b6b3280..7f4a3c8 100644 --- a/lib/ttp2/include/asn1_helpers.h +++ b/lib/ttp2/include/asn1_helpers.h @@ -19,6 +19,7 @@ namespace ttp2 { static std::string asn1DecodePayloadString(asn1_node packet, const char* asn1Key); static int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); + static std::vector asn1DecodePayloadBuffer(asn1_node packet, const char* asn1Key); private: static int bytesToInt(std::vector bytes, int size); diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 0de2800..1bb4243 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -86,4 +86,16 @@ namespace ttp2 { } return result; } + + std::vector Asn1Helpers::asn1DecodePayloadBuffer(asn1_node packet, const char* asn1Key) { + int payloadLen = 0; + int status2 = asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + std::vector buffer(payloadLen); + + if (status2 == ASN1_MEM_ERROR && payloadLen > 0) { + status2 = asn1_read_value(packet, asn1Key, buffer.data(), &payloadLen); + return buffer; + } + return buffer; + } } From 1ffd09d56b3c039fd316c8aaa6f3a1d997498133 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:54:27 +0200 Subject: [PATCH 21/53] update: implement arrow::table in networking --- lib/ttp2/include/networking.h | 11 +++++------ lib/ttp2/src/networking.cpp | 10 +++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index b71dbaf..6dbdbc2 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -23,7 +23,7 @@ namespace ttp2 { std::string filePath = ""; int start = -1; int end = -1; - std::string payload = ""; + std::shared_ptr payload; }; struct Viewport { @@ -60,17 +60,16 @@ namespace ttp2 { static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); static bool isValidInterface(std::string &interface); - - // TODO: move to protected later - static std::shared_ptr tableToBuffer(const std::shared_ptr& table); - static std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); - + protected: bool connected = true; bool isNumeric(const std::string& string); int bytesToInt(std::vector bytes, int size); + static std::shared_ptr tableToBuffer(const std::shared_ptr& table); + static std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); + std::vector requestQueue; std::vector responseQueue; std::mutex mtx; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 6dd1f61..7a4e2c1 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -152,8 +152,9 @@ namespace ttp2 { int end = std::get(payload).end; packet = Asn1Helpers::asn1EncodePayload(end, packet, "payload.file.end"); - std::string filePayloadString = std::get(payload).payload; - packet = Asn1Helpers::asn1EncodePayload(filePayloadString, packet, "payload.file.payload"); + std::shared_ptr table = std::get(payload).payload; + std::shared_ptr buffer = tableToBuffer(table); + packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.file.payload"); } else if (std::holds_alternative(payload)) { // Write structure @@ -280,7 +281,10 @@ namespace ttp2 { file.filePath = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.filePath"); file.start = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.start"); file.end = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.end"); - file.payload = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.payload"); + + std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.file.payload"); + // const uint8_t* bufferConst = buffer.data(); + file.payload = bufferToTable(buffer.data(), buffer.size()); data.payload = file; } else if (typeNameString == "viewport") { From d5822849e8fc5fc566d6a5521ceb7f1fca08f92d Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:54:50 +0200 Subject: [PATCH 22/53] update: add arrow::table to test client --- test/client/main.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/test/client/main.cpp b/test/client/main.cpp index 98fee25..d0595e1 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -88,11 +88,20 @@ int main() { } while(clientSessionController->hasResponse()) { ClientSessionController::Packet packet = clientSessionController->popResponse(); - Networking::Standard standard = std::get(packet.payload); - std::wcout << "------ Message ------" << std::endl; - std::wcout << "ID: " << packet.id << std::endl; - std::wcout << "Payload: " << standard.payload.c_str() << std::endl; - std::wcout << "---------------------" << std::endl; + + if (std::holds_alternative(packet.payload)) { + Networking::Standard standard = std::get(packet.payload); + std::wcout << "------ Message ------" << std::endl; + std::wcout << "ID: " << packet.id << std::endl; + std::wcout << "Payload: " << standard.payload.c_str() << std::endl; + std::wcout << "---------------------" << std::endl; + } else if (std::holds_alternative(packet.payload)) { + Networking::File file = std::get(packet.payload); + std::wcout << "------ Message ------" << std::endl; + std::wcout << "ID: " << packet.id << std::endl; + std::wcout << file.payload->ToString().c_str() << std::endl; + std::wcout << "---------------------" << std::endl; + } } } else if (option == 3) { std::wcout << "~~~~~~ ~~~~~~ Benchmark ~~~~~~ ~~~~~~" << std::endl; @@ -178,22 +187,15 @@ int main() { std::shared_ptr table = *maybeTable; std::wcout << table->ToString().c_str() << std::endl; - std::shared_ptr buffer = ClientSessionController::tableToBuffer(table); - const uint8_t* bufferData = buffer->data(); - int64_t bufferSize = buffer->size(); + ClientSessionController::Packet packet; + ClientSessionController::File file; + file.start = 0; + file.end = table->num_rows(); + file.payload = table; + packet.payload = file; + clientSessionController->pushRequest(packet); - - std::shared_ptr table2 = ClientSessionController::bufferToTable(bufferData, bufferSize); - std::wcout << "Table2 " << table2->ToString().c_str() << std::endl; - - // TODO: - // ClientSessionController::Packet packet; - // clientSessionController::File file; - // file.start = 0; - // file.end = table->num_rows(); - // file.payload = table; - // packet.payload = file; - // clientSessionController->pushRequest(packet); + std::wcout << "Done!" << std::endl; } else if (option == 5) { clientSessionController->disconnect(); } else { From 3422cfc7d26f83cf8737b7aedd8c83159d1bbfa8 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:56:51 +0200 Subject: [PATCH 23/53] update: remove unnecessary print of table --- test/client/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/client/main.cpp b/test/client/main.cpp index d0595e1..7566873 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -185,7 +185,6 @@ int main() { continue; } std::shared_ptr table = *maybeTable; - std::wcout << table->ToString().c_str() << std::endl; ClientSessionController::Packet packet; ClientSessionController::File file; From dcd5104977aaf62889ec2f053f404f9533746eb5 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 16:57:16 +0200 Subject: [PATCH 24/53] update: version 2 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9deb5c9..8721313 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "1.9.11"; + version = "2.0"; commonDeps = with pkgs; [ cmake From 47a466bd61c5a0e7c8dfa2df139e9b2ce55d6edc Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 17:06:56 +0200 Subject: [PATCH 25/53] update: set viewport to new filetype --- lib/ttp2/include/networking.h | 2 +- lib/ttp2/src/networking.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 6dbdbc2..d552e5d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -31,7 +31,7 @@ namespace ttp2 { int xEnd = 0; int yStart = 0; int yEnd = 0; - std::string payload = ""; + std::shared_ptr payload; }; typedef std::variant payloadVariants; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 7a4e2c1..a5514a9 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -155,7 +155,6 @@ namespace ttp2 { std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.file.payload"); - } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "viewport", 0); @@ -179,8 +178,9 @@ namespace ttp2 { int yEnd = std::get(payload).yEnd; packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); - std::string filePayload = std::get(payload).payload; - packet = Asn1Helpers::asn1EncodePayload(filePayload, packet, "payload.viewport.payload"); + std::shared_ptr table = std::get(payload).payload; + std::shared_ptr buffer = tableToBuffer(table); + packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.viewport.payload"); } int derLen = 0; @@ -293,7 +293,8 @@ namespace ttp2 { viewport.xEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); viewport.yStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yStart"); viewport.yEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); - viewport.payload = Asn1Helpers::asn1DecodePayloadString(packet, "payload.viewport.payload"); + std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.viewport.payload"); + viewport.payload = bufferToTable(buffer.data(), buffer.size()); data.payload = viewport; } else { From ac1580f6d92177f6a0e471f749b9193e292075ea Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 24 Jun 2026 17:07:34 +0200 Subject: [PATCH 26/53] update: version 2.0.1 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 8721313..6b47b5d 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0"; + version = "2.0.1"; commonDeps = with pkgs; [ cmake From 1845f2c39ea336626081fae435fb7fe28c18dbc4 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 26 Jun 2026 12:55:32 +0200 Subject: [PATCH 27/53] update: init empty table instead of nullptr --- flake.nix | 2 +- lib/ttp2/include/networking.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 6b47b5d..0ce8f98 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.1"; + version = "2.0.2"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index d552e5d..bda722d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -23,7 +23,7 @@ namespace ttp2 { std::string filePath = ""; int start = -1; int end = -1; - std::shared_ptr payload; + std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; struct Viewport { @@ -31,7 +31,7 @@ namespace ttp2 { int xEnd = 0; int yStart = 0; int yEnd = 0; - std::shared_ptr payload; + std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; typedef std::variant payloadVariants; From 9e74daef34ca410c9d32cf5d80c7ce665d3761a9 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 3 Jul 2026 14:41:51 +0200 Subject: [PATCH 28/53] update: fix init of autoid --- lib/ttp2/include/networking.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index bda722d..2c9c70f 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -77,7 +77,7 @@ namespace ttp2 { std::map> sessionBuffers; - int autoId; + int autoId = 0; }; } From fe62ec7250eacdd177cdbc3b4a1c4238f08d3c71 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 3 Jul 2026 14:42:17 +0200 Subject: [PATCH 29/53] update: update version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0ce8f98..603858f 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.2"; + version = "2.0.3"; commonDeps = with pkgs; [ cmake From ba62c7dab45c624b4ac56094b27700962e1da92d Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 5 Jul 2026 18:19:14 +0200 Subject: [PATCH 30/53] update: fix asn1 encoding of type int --- lib/ttp2/src/asn1_helpers.cpp | 3 ++- lib/ttp2/src/networking.cpp | 13 ++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 1bb4243..f88ae69 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -28,8 +28,9 @@ namespace ttp2 { } asn1_node Asn1Helpers::asn1EncodePayload(int payload, asn1_node packet, const char* asn1Key) { + std::string payloadString = std::to_string(payload); int status = asn1_write_value(packet, asn1Key, - &payload, sizeof(payload)); + payloadString.c_str(), 0); if (status != ASN1_SUCCESS) { std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index a5514a9..d6e0bd1 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -119,8 +119,7 @@ namespace ttp2 { autoId++; } - std::string idString = std::to_string(id); - asn1_write_value(packet, "id", idString.c_str(), 0); + packet = Asn1Helpers::asn1EncodePayload(id, packet, "id"); if (std::holds_alternative(payload)) { // Write structure @@ -257,15 +256,7 @@ namespace ttp2 { if (asn1_der_decoding(&packet, derBuffer.data(), derLen, errorDescription) == ASN1_SUCCESS) { - unsigned char idBin[8]; - int idLen = sizeof(idBin); - if (asn1_read_value(packet, "id", idBin, &idLen) == ASN1_SUCCESS) { - long idValue = 0; - for (int i = 0; i < idLen; i++) { - idValue = (idValue << 8) | idBin[i]; - } - data.id = static_cast(idValue); - } + data.id = Asn1Helpers::asn1DecodePayloadInt(packet, "id"); char typeName[64]; int branchSize = sizeof(typeName); From 291d3e16a31449c37460cf5fd63fa909f78dd110 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 5 Jul 2026 18:20:03 +0200 Subject: [PATCH 31/53] update: version 2.0.4 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 603858f..fea60e3 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.3"; + version = "2.0.4"; commonDeps = with pkgs; [ cmake From cf6d19c08e083e928ff5c8b7d47463c33845ec45 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 6 Jul 2026 15:39:00 +0200 Subject: [PATCH 32/53] update: fix disconnet, closes #23 --- lib/ttp2/include/client_session_controller.h | 1 + lib/ttp2/include/networking.h | 3 ++- lib/ttp2/include/server_session_controller.h | 2 ++ lib/ttp2/src/client_session_controller.cpp | 6 ++++++ lib/ttp2/src/networking.cpp | 11 +++++------ lib/ttp2/src/server_session_controller.cpp | 7 +++++++ test/client/main.cpp | 12 +++++------- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/ttp2/include/client_session_controller.h b/lib/ttp2/include/client_session_controller.h index 1575e9e..7636384 100644 --- a/lib/ttp2/include/client_session_controller.h +++ b/lib/ttp2/include/client_session_controller.h @@ -11,6 +11,7 @@ namespace ttp2 { ClientSessionController(); ClientSessionController(int &socket); void networkingSession(); + void disconnect() override; private: int socket; diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 2c9c70f..c39ef4e 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -42,7 +42,6 @@ namespace ttp2 { }; bool isConnected(); - void disconnect(); bool hasRequest(); bool hasResponse(); Packet popRequest(); @@ -60,6 +59,8 @@ namespace ttp2 { static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); static bool isValidInterface(std::string &interface); + + virtual void disconnect(); protected: bool connected = true; diff --git a/lib/ttp2/include/server_session_controller.h b/lib/ttp2/include/server_session_controller.h index 7ff82b9..4266847 100644 --- a/lib/ttp2/include/server_session_controller.h +++ b/lib/ttp2/include/server_session_controller.h @@ -11,6 +11,8 @@ namespace ttp2 { ServerSessionController(); ServerSessionController(int serverSocket, int clientSocket); void networkingSession(); + void disconnect() override; + private: int serverSocket; int clientSocket; diff --git a/lib/ttp2/src/client_session_controller.cpp b/lib/ttp2/src/client_session_controller.cpp index 485b1d8..c7d706b 100644 --- a/lib/ttp2/src/client_session_controller.cpp +++ b/lib/ttp2/src/client_session_controller.cpp @@ -83,4 +83,10 @@ namespace ttp2 { } } } + + void ClientSessionController::disconnect() { + std::lock_guard lock(mtx); + close(this->socket); + connected = false; + } } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index d6e0bd1..15131ce 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -48,11 +49,6 @@ namespace ttp2 { return connected; } - void Networking::disconnect() { - std::lock_guard lock(mtx); - connected = false; - } - Networking::Packet Networking::popRequest() { std::lock_guard lock(mtx); if (!requestQueue.empty()) { @@ -216,10 +212,11 @@ namespace ttp2 { if (errno == EAGAIN || errno == EWOULDBLOCK) { break; } - // std::wcout << "Error while receiving!" << std::endl; + std::wcout << "Error while receiving bytes!" << std::endl; return data; } else { // std::wcout << "Socket closed!" << std::endl; + disconnect(); return data; } } @@ -468,4 +465,6 @@ namespace ttp2 { std::shared_ptr table = *stream_reader->ToTable(); return table; } + + void Networking::disconnect() {} } diff --git a/lib/ttp2/src/server_session_controller.cpp b/lib/ttp2/src/server_session_controller.cpp index 992f600..96389aa 100644 --- a/lib/ttp2/src/server_session_controller.cpp +++ b/lib/ttp2/src/server_session_controller.cpp @@ -72,6 +72,7 @@ namespace ttp2 { if (incomingEvents[index].events & (EPOLLHUP | EPOLLERR)) { sessionBuffers.erase(fd); close(fd); + disconnect(); continue; } if (incomingEvents[index].events & EPOLLIN) { @@ -86,4 +87,10 @@ namespace ttp2 { } } } + + void ServerSessionController::disconnect() { + std::lock_guard lock(mtx); + close(this->clientSocket); + connected = false; + } } diff --git a/test/client/main.cpp b/test/client/main.cpp index 7566873..65435ba 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -66,12 +66,7 @@ int main() { clientSessionController->networkingSession(); }); - while (true) { - if (!clientSessionController->isConnected()) { - std::wcout << "Disconnect!" << std::endl; - break; - } - + while (clientSessionController->isConnected()) { int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) Exit\nnumber: "); if (option == 1) { std::string payload = requestString("(string) Payload: "); @@ -201,7 +196,10 @@ int main() { std::wcout << "Invalid!" << std::endl; } } - networkThread.detach(); + + std::wcout << "Terminated!" << std::endl; + + networkThread.join(); return 0; } From 2f55faaf009ef26c8b3d14c4b3da896e45698014 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 6 Jul 2026 15:39:46 +0200 Subject: [PATCH 33/53] update: version 2.0.5 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index fea60e3..5279f59 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.4"; + version = "2.0.5"; commonDeps = with pkgs; [ cmake From 15ddced8d8bd20bcb8013f4711fabf1161a22b93 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 9 Jul 2026 17:14:07 +0200 Subject: [PATCH 34/53] update: add peek functions --- flake.nix | 2 +- lib/ttp2/include/networking.h | 13 ++++++++++++- lib/ttp2/src/networking.cpp | 34 ++++++++++++++++++++++++++++++++++ test/client/main.cpp | 28 +++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 5279f59..66685fa 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.5"; + version = "2.0.6"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index c39ef4e..2209016 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -14,7 +14,8 @@ namespace ttp2 { class Networking { - public: + public: + // Packet Payloads struct Standard { std::string payload = ""; }; @@ -55,6 +56,16 @@ namespace ttp2 { int sendPacket(int socket, Packet packet); Packet receiveMessage(int socket); + // WARNING: This struct cant be send as a payload type! + struct PacketInfo { + int id; + payloadVariants payloadType; + }; + PacketInfo peekResponse(); + PacketInfo peekResponse(int index); + PacketInfo peekRequest(); + PacketInfo peekRequest(int index); + static std::string getBroadcastIpAddress(); static std::string getLocalIpAddress(std::string interface); static bool isValidIpV4(std::string &ipString); diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 15131ce..404244e 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -343,6 +343,40 @@ namespace ttp2 { return result; } + Networking::PacketInfo Networking::peekResponse() { + return peekResponse(0); + } + + Networking::PacketInfo Networking::peekResponse(int index) { + Networking::PacketInfo packetInfo; + if (index > getResponseQueueSize() - 1 || index < 0) { + std::wcout << "Invalid peek request: " << index << std::endl; + return packetInfo; + } + + std::lock_guard lock(mtx); + packetInfo.id = responseQueue[index].id; + packetInfo.payloadType = responseQueue[index].payload; + return packetInfo; + } + + Networking::PacketInfo Networking::peekRequest() { + return peekRequest(0); + } + + Networking::PacketInfo Networking::peekRequest(int index) { + Networking::PacketInfo packetInfo; + if (index > getRequestQueueSize() - 1 || index < 0) { + std::wcout << "Invalid peek request: " << index << std::endl; + return packetInfo; + } + + std::lock_guard lock(mtx); + packetInfo.id = requestQueue[index].id; + packetInfo.payloadType = requestQueue[index].payload; + return packetInfo; + } + std::string Networking::getBroadcastIpAddress() { struct ifaddrs *ifaddr = nullptr; std::string broadcastIP; diff --git a/test/client/main.cpp b/test/client/main.cpp index 65435ba..1977489 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -67,7 +67,7 @@ int main() { }); while (clientSessionController->isConnected()) { - int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) Exit\nnumber: "); + int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) peek index\n(6) Exit\nnumber: "); if (option == 1) { std::string payload = requestString("(string) Payload: "); @@ -191,6 +191,32 @@ int main() { std::wcout << "Done!" << std::endl; } else if (option == 5) { + int responseQueueSize = clientSessionController->getResponseQueueSize(); + int index = 0; + do { + std::wcout << "Peek index: 0 to " << responseQueueSize << " | -1 to exit" << std::endl; + index = requestInt("(int) index: "); + } while (index < -1 || index > responseQueueSize); + + if (index == -1) { + continue; + } + + ClientSessionController::PacketInfo packetInfo = clientSessionController->peekResponse(index); + std::wcout << "--- PacketInfo ---" << std::endl; + std::string payloadType = ""; + if (std::holds_alternative(packetInfo.payloadType)) + payloadType = "Standard"; + else if (std::holds_alternative(packetInfo.payloadType)) + payloadType = "File"; + else if (std::holds_alternative(packetInfo.payloadType)) + payloadType = "Viewport"; + else + payloadType = "Invalid"; + + std::wcout << "id: " << packetInfo.id << "\npacketType: " << payloadType.c_str() << std::endl; + std::wcout << "--- --- ---" << std::endl; + } else if (option == 6) { clientSessionController->disconnect(); } else { std::wcout << "Invalid!" << std::endl; From 1381d9ca94db1d6b6fe8ac2033af8e2ec2e2b834 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 13 Jul 2026 16:19:39 +0200 Subject: [PATCH 35/53] update: add writeViewportCoordinates to asn1 helpers --- lib/ttp2/include/asn1_helpers.h | 2 ++ lib/ttp2/include/networking.h | 5 ++++- lib/ttp2/src/asn1_helpers.cpp | 12 ++++++++++++ lib/ttp2/src/networking.cpp | 16 +++------------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h index 7f4a3c8..bb43117 100644 --- a/lib/ttp2/include/asn1_helpers.h +++ b/lib/ttp2/include/asn1_helpers.h @@ -21,6 +21,8 @@ namespace ttp2 { static int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); static std::vector asn1DecodePayloadBuffer(asn1_node packet, const char* asn1Key); + static asn1_node writeViewportCoordinates(asn1_node packet, int xStart, int xEnd, int yStart, int yEnd); + private: static int bytesToInt(std::vector bytes, int size); }; diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 2209016..d1ce16d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -27,11 +27,14 @@ namespace ttp2 { std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; - struct Viewport { + struct ViewportRequest { int xStart = 0; int xEnd = 0; int yStart = 0; int yEnd = 0; + }; + + struct Viewport: public ViewportRequest { std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index f88ae69..9e47124 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -99,4 +99,16 @@ namespace ttp2 { } return buffer; } + + asn1_node Asn1Helpers::writeViewportCoordinates(asn1_node packet, int xStart, int xEnd, int yStart, int yEnd) { + // X + packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); + packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); + + // Y + packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); + packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); + + return packet; + } } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 404244e..5deeb04 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -159,19 +159,9 @@ namespace ttp2 { } // Write content - // X - int xStart = std::get(payload).xStart; - packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); - - int xEnd = std::get(payload).xEnd; - packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); - - // Y - int yStart = std::get(payload).yStart; - packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); - - int yEnd = std::get(payload).yEnd; - packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); + packet = Asn1Helpers::writeViewportCoordinates(packet, + std::get(payload).xStart, std::get(payload).xEnd, + std::get(payload).yStart, std::get(payload).yEnd); std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); From cd4a725489f377caafac20bdbc6355cf81d96f5e Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 13 Jul 2026 16:38:18 +0200 Subject: [PATCH 36/53] update: add viewport request --- flake.nix | 2 +- lib/ttp2/include/asn1_helpers.h | 2 -- lib/ttp2/include/networking.h | 2 +- lib/ttp2/src/asn1_helpers.cpp | 12 ----------- lib/ttp2/src/networking.cpp | 35 ++++++++++++++++++++++++++++++--- lib/ttp2/src/packets.asn1 | 10 +++++++++- lib/ttp2/src/packets_asn1_tab.c | 9 ++++++++- 7 files changed, 51 insertions(+), 21 deletions(-) diff --git a/flake.nix b/flake.nix index 66685fa..63f35a8 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.6"; + version = "2.0.7"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h index bb43117..7f4a3c8 100644 --- a/lib/ttp2/include/asn1_helpers.h +++ b/lib/ttp2/include/asn1_helpers.h @@ -21,8 +21,6 @@ namespace ttp2 { static int asn1DecodePayloadInt(asn1_node packet, const char* asn1Key); static std::vector asn1DecodePayloadBuffer(asn1_node packet, const char* asn1Key); - static asn1_node writeViewportCoordinates(asn1_node packet, int xStart, int xEnd, int yStart, int yEnd); - private: static int bytesToInt(std::vector bytes, int size); }; diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index d1ce16d..7464201 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -38,7 +38,7 @@ namespace ttp2 { std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; - typedef std::variant payloadVariants; + typedef std::variant payloadVariants; struct Packet { int id = -1; diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 9e47124..f88ae69 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -99,16 +99,4 @@ namespace ttp2 { } return buffer; } - - asn1_node Asn1Helpers::writeViewportCoordinates(asn1_node packet, int xStart, int xEnd, int yStart, int yEnd) { - // X - packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); - packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); - - // Y - packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); - packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); - - return packet; - } } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 5deeb04..3e542ff 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -150,6 +150,22 @@ namespace ttp2 { std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.file.payload"); + } else if (std::holds_alternative(payload)) { + // Write structure + int status = asn1_write_value(packet, "payload", "viewportRequest", 0); + + if (status != ASN1_SUCCESS) { + std::wcout << "ASN1 set payload as viewport request failed!" << std::endl; + } + + // Write content + // X + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xStart, packet, "payload.viewportRequest.xStart"); + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xEnd, packet, "payload.viewportRequest.xEnd"); + + // Y + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yStart, packet, "payload.viewportRequest.yStart"); + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yEnd, packet, "payload.viewportRequest.yEnd"); } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "viewport", 0); @@ -159,9 +175,13 @@ namespace ttp2 { } // Write content - packet = Asn1Helpers::writeViewportCoordinates(packet, - std::get(payload).xStart, std::get(payload).xEnd, - std::get(payload).yStart, std::get(payload).yEnd); + // X + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xStart, packet, "payload.viewport.xStart"); + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xEnd, packet, "payload.viewport.xEnd"); + + // Y + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yStart, packet, "payload.viewport.yStart"); + packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yEnd, packet, "payload.viewport.yEnd"); std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); @@ -265,6 +285,15 @@ namespace ttp2 { file.payload = bufferToTable(buffer.data(), buffer.size()); data.payload = file; + } else if (typeNameString == "viewportRequest") { + Networking::ViewportRequest viewportRequest; + + viewportRequest.xStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewportRequest.xStart"); + viewportRequest.xEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewportRequest.xEnd"); + viewportRequest.yStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewportRequest.yStart"); + viewportRequest.yEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewportRequest.yEnd"); + + data.payload = viewportRequest; } else if (typeNameString == "viewport") { Networking::Viewport viewport; viewport.xStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xStart"); diff --git a/lib/ttp2/src/packets.asn1 b/lib/ttp2/src/packets.asn1 index f4c228d..ad12bfb 100644 --- a/lib/ttp2/src/packets.asn1 +++ b/lib/ttp2/src/packets.asn1 @@ -11,6 +11,13 @@ File ::= SEQUENCE { payload OCTET STRING } +ViewportRequest ::= SEQUENCE { + xStart INTEGER, + xEnd INTEGER, + yStart INTEGER, + yEnd INTEGER +} + Viewport ::= SEQUENCE { xStart INTEGER, xEnd INTEGER, @@ -24,7 +31,8 @@ Packet ::= SEQUENCE { payload CHOICE { standard [0] Standard, file [1] File, - viewport [2] Viewport + viewport [2] Viewport, + viewportRequest [3] ViewportRequest } } diff --git a/lib/ttp2/src/packets_asn1_tab.c b/lib/ttp2/src/packets_asn1_tab.c index 8e77560..3919d69 100644 --- a/lib/ttp2/src/packets_asn1_tab.c +++ b/lib/ttp2/src/packets_asn1_tab.c @@ -14,6 +14,11 @@ const asn1_static_node packets_asn1_tab[] = { { "start", 1073741827, NULL }, { "end", 1073741827, NULL }, { "payload", 7, NULL }, + { "ViewportRequest", 1610612741, NULL }, + { "xStart", 1073741827, NULL }, + { "xEnd", 1073741827, NULL }, + { "yStart", 1073741827, NULL }, + { "yEnd", 3, NULL }, { "Viewport", 1610612741, NULL }, { "xStart", 1073741827, NULL }, { "xEnd", 1073741827, NULL }, @@ -27,7 +32,9 @@ const asn1_static_node packets_asn1_tab[] = { { NULL, 2056, "0"}, { "file", 1610620930, "File"}, { NULL, 2056, "1"}, - { "viewport", 536879106, "Viewport"}, + { "viewport", 1610620930, "Viewport"}, { NULL, 2056, "2"}, + { "viewportRequest", 536879106, "ViewportRequest"}, + { NULL, 2056, "3"}, { NULL, 0, NULL } }; From 03ed739c7039fbc2de5e9f407ce7db45579c18db Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 14 Jul 2026 17:11:32 +0200 Subject: [PATCH 37/53] update: fixup --- flake.nix | 2 +- lib/ttp2/include/networking.h | 6 +++++- lib/ttp2/src/networking.cpp | 24 ++++++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 63f35a8..2ea4dbb 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.7"; + version = "2.0.8"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 7464201..c58b59d 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -34,7 +34,11 @@ namespace ttp2 { int yEnd = 0; }; - struct Viewport: public ViewportRequest { + struct Viewport { + int xStart = 0; + int xEnd = 0; + int yStart = 0; + int yEnd = 0; std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 3e542ff..9524d12 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -160,12 +160,16 @@ namespace ttp2 { // Write content // X - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xStart, packet, "payload.viewportRequest.xStart"); - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xEnd, packet, "payload.viewportRequest.xEnd"); + int xStart = std::get(payload).xStart; + packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewportRequest.xStart"); + int xEnd = std::get(payload).xEnd; + packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewportRequest.xEnd"); // Y - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yStart, packet, "payload.viewportRequest.yStart"); - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yEnd, packet, "payload.viewportRequest.yEnd"); + int yStart = std::get(payload).yStart; + packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewportRequest.yStart"); + int yEnd = std::get(payload).yEnd; + packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewportRequest.yEnd"); } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "viewport", 0); @@ -176,12 +180,16 @@ namespace ttp2 { // Write content // X - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xStart, packet, "payload.viewport.xStart"); - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).xEnd, packet, "payload.viewport.xEnd"); + int xStart = std::get(payload).xStart; + packet = Asn1Helpers::asn1EncodePayload(xStart, packet, "payload.viewport.xStart"); + int xEnd = std::get(payload).xEnd; + packet = Asn1Helpers::asn1EncodePayload(xEnd, packet, "payload.viewport.xEnd"); // Y - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yStart, packet, "payload.viewport.yStart"); - packet = Asn1Helpers::asn1EncodePayload(std::get(payload).yEnd, packet, "payload.viewport.yEnd"); + int yStart = std::get(payload).yStart; + packet = Asn1Helpers::asn1EncodePayload(yStart, packet, "payload.viewport.yStart"); + int yEnd = std::get(payload).yEnd; + packet = Asn1Helpers::asn1EncodePayload(yEnd, packet, "payload.viewport.yEnd"); std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); From 85d6a9ad2d008c34ef23064073a895c27eeeeafd Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 14 Jul 2026 17:41:39 +0200 Subject: [PATCH 38/53] update: add viewport to client --- flake.nix | 2 +- test/client/main.cpp | 97 ++++++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/flake.nix b/flake.nix index 2ea4dbb..e51fad5 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.8"; + version = "2.0.9"; commonDeps = with pkgs; [ cmake diff --git a/test/client/main.cpp b/test/client/main.cpp index 1977489..0a18d4d 100644 --- a/test/client/main.cpp +++ b/test/client/main.cpp @@ -1,7 +1,9 @@ #include "client_session_controller.h" #include +#include #include +#include #include #include #include @@ -42,6 +44,43 @@ int requestInt(const std::string& message) { } } +std::shared_ptr openCsvFile() { + std::string filePath { "" }; + do { + if (filePath.length() > 0 && !std::filesystem::exists(filePath)) { + std::wcout << "Incorrect filepath!" << std::endl; + } + filePath = requestString("(string) Filepath: "); + } while (!std::filesystem::exists(filePath)); + + arrow::io::IOContext ioContext = arrow::io::default_io_context(); + + arrow::Result> maybeFile = arrow::io::ReadableFile::Open(filePath); + std::shared_ptr fileInput = *maybeFile; + + arrow::csv::ReadOptions readOptions = arrow::csv::ReadOptions::Defaults(); + arrow::csv::ParseOptions parseOptions = arrow::csv::ParseOptions::Defaults(); + arrow::csv::ConvertOptions convertOptions = arrow::csv::ConvertOptions::Defaults(); + + arrow::Result> maybeReader = arrow::csv::TableReader::Make(ioContext, + fileInput, + readOptions, + parseOptions, + convertOptions); + if (!maybeReader.ok()) { + std::wcout << "Error while instantiating TableReader!" << std::endl; + } + std::shared_ptr reader = *maybeReader; + + arrow::Result> maybeTable = reader->Read(); + if (!maybeTable.ok()) { + std::wcout << "Error while read table from CSV file!" << std::endl; + } + std::shared_ptr table = *maybeTable; + return table; +} + + int main() { std::string ipAddress = requestString("Server ipv4 (string): "); int port = requestInt("Server port (int): "); @@ -67,7 +106,7 @@ int main() { }); while (clientSessionController->isConnected()) { - int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) peek index\n(6) Exit\nnumber: "); + int option = requestInt("Choose option\n(1) Send message\n(2) Read messages\n(3) Benchmark\n(4) Open file\n(5) peek index\n(6) Viewport\n(7) Exit\nnumber: "); if (option == 1) { std::string payload = requestString("(string) Payload: "); @@ -96,7 +135,14 @@ int main() { std::wcout << "ID: " << packet.id << std::endl; std::wcout << file.payload->ToString().c_str() << std::endl; std::wcout << "---------------------" << std::endl; + } else if (std::holds_alternative(packet.payload)) { + Networking::Viewport viewport = std::get(packet.payload); + std::wcout << "------ Message Viewport------" << std::endl; + std::wcout << "ID: " << packet.id << std::endl; + std::wcout << viewport.payload->ToString().c_str() << std::endl; + std::wcout << "---------------------" << std::endl; } + } } else if (option == 3) { std::wcout << "~~~~~~ ~~~~~~ Benchmark ~~~~~~ ~~~~~~" << std::endl; @@ -146,41 +192,7 @@ int main() { std::wcout << "Invalid!" << std::endl; } } else if (option == 4) { - std::string filePath { "" }; - do { - if (filePath.length() > 0 && !std::filesystem::exists(filePath)) { - std::wcout << "Incorrect filepath!" << std::endl; - } - filePath = requestString("(string) Filepath: "); - } while (!std::filesystem::exists(filePath)); - - arrow::io::IOContext ioContext = arrow::io::default_io_context(); - - arrow::Result> maybeFile = arrow::io::ReadableFile::Open(filePath); - std::shared_ptr fileInput = *maybeFile; - - arrow::csv::ReadOptions readOptions = arrow::csv::ReadOptions::Defaults(); - arrow::csv::ParseOptions parseOptions = arrow::csv::ParseOptions::Defaults(); - arrow::csv::ConvertOptions convertOptions = arrow::csv::ConvertOptions::Defaults(); - - arrow::Result> maybeReader = arrow::csv::TableReader::Make(ioContext, - fileInput, - readOptions, - parseOptions, - convertOptions); - if (!maybeReader.ok()) { - std::wcout << "Error while instantiating TableReader!" << std::endl; - continue; - } - std::shared_ptr reader = *maybeReader; - - arrow::Result> maybeTable = reader->Read(); - if (!maybeTable.ok()) { - std::wcout << "Error while read table from CSV file!" << std::endl; - continue; - } - std::shared_ptr table = *maybeTable; - + std::shared_ptr table = openCsvFile(); ClientSessionController::Packet packet; ClientSessionController::File file; file.start = 0; @@ -217,6 +229,19 @@ int main() { std::wcout << "id: " << packetInfo.id << "\npacketType: " << payloadType.c_str() << std::endl; std::wcout << "--- --- ---" << std::endl; } else if (option == 6) { + std::shared_ptr table = openCsvFile(); + ClientSessionController::Packet packet; + ClientSessionController::Viewport viewport; + viewport.xStart = 0; + viewport.xEnd = table->num_rows(); + viewport.yStart = 0; + viewport.yEnd = table->num_columns(); + viewport.payload = table; + packet.payload = viewport; + clientSessionController->pushRequest(packet); + + std::wcout << "Done!" << std::endl; + } else if (option == 7) { clientSessionController->disconnect(); } else { std::wcout << "Invalid!" << std::endl; From e7dbda47aa3fddd40a3bf19704b155c449aa107f Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 14 Jul 2026 20:33:04 +0200 Subject: [PATCH 39/53] update: potential bug with predetermend size in _asn1_tab.c --- lib/ttp2/src/packets.asn1 | 4 ++-- lib/ttp2/src/packets_asn1_tab.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ttp2/src/packets.asn1 b/lib/ttp2/src/packets.asn1 index ad12bfb..3c3057a 100644 --- a/lib/ttp2/src/packets.asn1 +++ b/lib/ttp2/src/packets.asn1 @@ -31,8 +31,8 @@ Packet ::= SEQUENCE { payload CHOICE { standard [0] Standard, file [1] File, - viewport [2] Viewport, - viewportRequest [3] ViewportRequest + viewportRequest [2] ViewportRequest, + viewport [3] Viewport } } diff --git a/lib/ttp2/src/packets_asn1_tab.c b/lib/ttp2/src/packets_asn1_tab.c index 3919d69..3a048ae 100644 --- a/lib/ttp2/src/packets_asn1_tab.c +++ b/lib/ttp2/src/packets_asn1_tab.c @@ -32,9 +32,9 @@ const asn1_static_node packets_asn1_tab[] = { { NULL, 2056, "0"}, { "file", 1610620930, "File"}, { NULL, 2056, "1"}, - { "viewport", 1610620930, "Viewport"}, + { "viewportRequest", 1610620930, "ViewportRequest"}, { NULL, 2056, "2"}, - { "viewportRequest", 536879106, "ViewportRequest"}, + { "viewport", 536879106, "Viewport"}, { NULL, 2056, "3"}, { NULL, 0, NULL } }; From a744472fdd167e364547bb2fbacf28c7b720946f Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Tue, 14 Jul 2026 20:52:42 +0200 Subject: [PATCH 40/53] update: version 2.1.0 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e51fad5..2c62970 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.0.9"; + version = "2.1.0"; commonDeps = with pkgs; [ cmake From aa0791fd87c4ace1d9fd5554736f72b51401040d Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Wed, 15 Jul 2026 19:46:44 +0200 Subject: [PATCH 41/53] update: lock mutex when sending and receiving, #24 --- flake.nix | 2 +- lib/ttp2/src/networking.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 2c62970..ad493a7 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.0"; + version = "2.1.1"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 9524d12..b4e0017 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -97,6 +97,7 @@ namespace ttp2 { int Networking::sendMessage(int socket, int id, payloadVariants payload) { + std::lock_guard lock(mtx); asn1_node definitions = nullptr; asn1_node packet = nullptr; char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; @@ -218,6 +219,7 @@ namespace ttp2 { } Networking::Packet Networking::receiveMessage(int socket) { + std::lock_guard lock(mtx); Networking::Packet data; unsigned char temp[4096]; From 2f60dc7a292500104f58e6f1662daab3ee5d2e77 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 16 Jul 2026 15:37:54 +0200 Subject: [PATCH 42/53] update: remove while true from receive loops, #24 --- flake.nix | 2 +- lib/ttp2/src/client_session_controller.cpp | 14 ++++++-------- lib/ttp2/src/networking.cpp | 2 -- lib/ttp2/src/server_session_controller.cpp | 13 +++++-------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/flake.nix b/flake.nix index ad493a7..9bc9d88 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.1"; + version = "2.1.2"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/src/client_session_controller.cpp b/lib/ttp2/src/client_session_controller.cpp index c7d706b..a067798 100644 --- a/lib/ttp2/src/client_session_controller.cpp +++ b/lib/ttp2/src/client_session_controller.cpp @@ -49,10 +49,10 @@ namespace ttp2 { } void ClientSessionController::receiveResponseSession() { + const int MAX_EVENTS = 10; + while (isConnected()) { - const int MAX_EVENTS = 10; struct epoll_event incomingEvents[MAX_EVENTS]; - int eventCount = epoll_wait(epollFd, incomingEvents, MAX_EVENTS, -1); for (int index = 0; index < eventCount; ++index) { @@ -63,13 +63,11 @@ namespace ttp2 { continue; } if (incomingEvents[index].events & EPOLLIN) { - while (true) { - Packet packet = receiveMessage(fd); - if (packet.id == -1) { - break; - } - pushResponse(packet); + Packet packet = receiveMessage(fd); + if (packet.id == -1) { + continue; } + pushResponse(packet); } } } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index b4e0017..9524d12 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -97,7 +97,6 @@ namespace ttp2 { int Networking::sendMessage(int socket, int id, payloadVariants payload) { - std::lock_guard lock(mtx); asn1_node definitions = nullptr; asn1_node packet = nullptr; char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; @@ -219,7 +218,6 @@ namespace ttp2 { } Networking::Packet Networking::receiveMessage(int socket) { - std::lock_guard lock(mtx); Networking::Packet data; unsigned char temp[4096]; diff --git a/lib/ttp2/src/server_session_controller.cpp b/lib/ttp2/src/server_session_controller.cpp index 96389aa..556ce62 100644 --- a/lib/ttp2/src/server_session_controller.cpp +++ b/lib/ttp2/src/server_session_controller.cpp @@ -61,10 +61,9 @@ namespace ttp2 { } void ServerSessionController::receiveRequestSession() { + const int MAX_EVENTS = 10; while (isConnected()) { - const int MAX_EVENTS = 10; struct epoll_event incomingEvents[MAX_EVENTS]; - int eventCount = epoll_wait(epollFd, incomingEvents, MAX_EVENTS, -1); for (int index = 0; index < eventCount; ++index) { @@ -76,13 +75,11 @@ namespace ttp2 { continue; } if (incomingEvents[index].events & EPOLLIN) { - while (true) { - Packet packet = receiveMessage(fd); - if (packet.id == -1) { - break; - } - pushRequest(packet); + Packet packet = receiveMessage(fd); + if (packet.id == -1) { + continue; } + pushRequest(packet); } } } From 89298ee602eaa17e55dc0af35778149be8fbbf1c Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 16 Jul 2026 15:48:35 +0200 Subject: [PATCH 43/53] update: fix bufferToTable, #24 --- flake.nix | 2 +- lib/ttp2/src/networking.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 9bc9d88..756fc49 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.2"; + version = "2.1.3"; commonDeps = with pkgs; [ cmake diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 9524d12..8c21461 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -522,8 +522,10 @@ namespace ttp2 { std::shared_ptr Networking::bufferToTable(const uint8_t* rawData, int64_t dataSize) { std::shared_ptr buffer = arrow::Buffer::Wrap(rawData, dataSize); std::shared_ptr inputStream = std::make_shared(buffer); - std::shared_ptr stream_reader = *arrow::ipc::RecordBatchStreamReader::Open(inputStream); - std::shared_ptr table = *stream_reader->ToTable(); + + std::shared_ptr stream_reader = arrow::ipc::RecordBatchStreamReader::Open(inputStream).ValueOrDie(); + + std::shared_ptr table = stream_reader->ToTable().ValueOrDie(); return table; } From d601868deeac22ec49c7a1e3213f38308ecdd1cb Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 16 Jul 2026 19:14:25 +0200 Subject: [PATCH 44/53] update: check for corruption before returning buffer, #24 --- lib/ttp2/src/asn1_helpers.cpp | 6 +++--- lib/ttp2/src/networking.cpp | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index f88ae69..9f31638 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -90,11 +90,11 @@ namespace ttp2 { std::vector Asn1Helpers::asn1DecodePayloadBuffer(asn1_node packet, const char* asn1Key) { int payloadLen = 0; - int status2 = asn1_read_value(packet, asn1Key, nullptr, &payloadLen); + int status = asn1_read_value(packet, asn1Key, nullptr, &payloadLen); std::vector buffer(payloadLen); - if (status2 == ASN1_MEM_ERROR && payloadLen > 0) { - status2 = asn1_read_value(packet, asn1Key, buffer.data(), &payloadLen); + if (status == ASN1_MEM_ERROR && payloadLen > 0) { + status = asn1_read_value(packet, asn1Key, buffer.data(), &payloadLen); return buffer; } return buffer; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 8c21461..dc7771f 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -149,7 +149,9 @@ namespace ttp2 { std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); - packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.file.payload"); + if (buffer->size() > 0) { + packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.file.payload"); + } } else if (std::holds_alternative(payload)) { // Write structure int status = asn1_write_value(packet, "payload", "viewportRequest", 0); @@ -507,6 +509,7 @@ namespace ttp2 { if (!status.ok()) { std::wcout << "Something went wrong while writing the structure!" << std::endl; + return nullptr; } streamWriter->Close(); @@ -514,19 +517,30 @@ namespace ttp2 { if (!buffer.ok()) { std::wcout << "Something went wrong while converting table to buffer!" << std::endl; + return nullptr; } - return *buffer; + return std::move(buffer).ValueUnsafe(); } std::shared_ptr Networking::bufferToTable(const uint8_t* rawData, int64_t dataSize) { std::shared_ptr buffer = arrow::Buffer::Wrap(rawData, dataSize); std::shared_ptr inputStream = std::make_shared(buffer); - std::shared_ptr stream_reader = arrow::ipc::RecordBatchStreamReader::Open(inputStream).ValueOrDie(); + arrow::Result> streamReaderResult = arrow::ipc::RecordBatchStreamReader::Open(inputStream); + if (!streamReaderResult.ok()) { + std::wcout << "Open input stream failed in bufferToTable" << std::endl; + return arrow::Table::Make(arrow::schema({}), std::vector>{}); + } + std::shared_ptr streamReader = std::move(streamReaderResult).ValueUnsafe(); + + arrow::Result> tableResult = streamReader->ToTable(); + if (!tableResult.ok()) { + std::wcout << "Create table failed in bufferToTable" << std::endl; + return arrow::Table::Make(arrow::schema({}), std::vector>{}); + } - std::shared_ptr table = stream_reader->ToTable().ValueOrDie(); - return table; + return std::move(tableResult).ValueUnsafe(); } void Networking::disconnect() {} From 5cc9162ecbf20d27f3ea9151133784bd1f3f2b20 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 16 Jul 2026 19:15:13 +0200 Subject: [PATCH 45/53] update: flake version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 756fc49..60479f9 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.3"; + version = "2.1.4"; commonDeps = with pkgs; [ cmake From 5573a3f8957347eb497e53bf94756a01e21a6b10 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 17 Jul 2026 23:24:18 +0200 Subject: [PATCH 46/53] update: fix address boundary error, #24 --- lib/ttp2/src/networking.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index dc7771f..64615ec 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -524,7 +524,27 @@ namespace ttp2 { } std::shared_ptr Networking::bufferToTable(const uint8_t* rawData, int64_t dataSize) { - std::shared_ptr buffer = arrow::Buffer::Wrap(rawData, dataSize); + arrow::BufferBuilder bufferBuilder; + arrow::Status allocStatus = bufferBuilder.Resize(dataSize); + if (!allocStatus.ok()) { + std::wcout << "Buffer allocation failed in bufferToTable" << std::endl; + return arrow::Table::Make(arrow::schema({}), std::vector>{}); + } + + // Make a physical copy so that the data isn't deleted. (That would lead to a shared_ptr with a table that points to no real data) + arrow::Status appendStatus = bufferBuilder.Append(reinterpret_cast(rawData), dataSize); + if (!appendStatus.ok()) { + std::wcout << "Failed to append raw data to buffer" << std::endl; + return arrow::Table::Make(arrow::schema({}), std::vector>{}); + } + + std::shared_ptr buffer; + arrow::Status finishStatus = bufferBuilder.Finish(&buffer); + if (!finishStatus.ok()) { + std::wcout << "Failed to finish buffer building" << std::endl; + return arrow::Table::Make(arrow::schema({}), std::vector>{}); + } + std::shared_ptr inputStream = std::make_shared(buffer); arrow::Result> streamReaderResult = arrow::ipc::RecordBatchStreamReader::Open(inputStream); @@ -533,14 +553,14 @@ namespace ttp2 { return arrow::Table::Make(arrow::schema({}), std::vector>{}); } std::shared_ptr streamReader = std::move(streamReaderResult).ValueUnsafe(); - + arrow::Result> tableResult = streamReader->ToTable(); if (!tableResult.ok()) { std::wcout << "Create table failed in bufferToTable" << std::endl; return arrow::Table::Make(arrow::schema({}), std::vector>{}); } - return std::move(tableResult).ValueUnsafe(); + return *tableResult; } void Networking::disconnect() {} From 56f863f2dc5b878f7d6227fd2b4d6cae03561f4f Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 17 Jul 2026 23:24:52 +0200 Subject: [PATCH 47/53] update: new flake version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 60479f9..650e46e 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.4"; + version = "2.1.5"; commonDeps = with pkgs; [ cmake From e4e75617e1db5186e304569448397dab680b8f30 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sat, 18 Jul 2026 18:49:02 +0200 Subject: [PATCH 48/53] update: add tablog to ttp2 --- flake.lock | 37 ++++++++++++++++++++++++++++++++++++- flake.nix | 15 +++++++++++++-- lib/ttp2/CMakeLists.txt | 1 + test/client/CMakeLists.txt | 1 + test/server/CMakeLists.txt | 1 + 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 246cfd4..b08124f 100644 --- a/flake.lock +++ b/flake.lock @@ -16,9 +16,44 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1784356753, + "narHash": "sha256-12KrbMiWLcf8m7pCvAtZh1ZrgF85ZXDXvfR/fWTKy84=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "61b7c44c4073f0b827768aff0049561b5110ea5a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "tablog": "tablog" + } + }, + "tablog": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1784384014, + "narHash": "sha256-7m2OFL08r7MAeJvwUVXpCoBRq2iVHVcCDwxW+GoUNbk=", + "owner": "Sobottasgithub", + "repo": "tablog", + "rev": "dea2163cd34d978a97ee09b90d832f75d1890950", + "type": "github" + }, + "original": { + "owner": "Sobottasgithub", + "repo": "tablog", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 650e46e..b763c12 100644 --- a/flake.nix +++ b/flake.nix @@ -3,22 +3,33 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + + tablog = { + url = "github:Sobottasgithub/tablog"; + }; }; outputs = - { self, nixpkgs }: + { + self, + nixpkgs, + tablog, + }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; version = "2.1.5"; + libtablog = tablog.packages.${system}.lib; + commonDeps = with pkgs; [ cmake gcc gnumake libtasn1 arrow-cpp + libtablog ]; mkTTP2Package = @@ -67,7 +78,7 @@ }; in { - inherit lib; + inherit lib libtablog; client = mkTTP2Package { pname = "ttp2-client"; diff --git a/lib/ttp2/CMakeLists.txt b/lib/ttp2/CMakeLists.txt index e2449f7..d83c6cf 100644 --- a/lib/ttp2/CMakeLists.txt +++ b/lib/ttp2/CMakeLists.txt @@ -24,6 +24,7 @@ target_include_directories(ttp2 PUBLIC # Link against the libtasn1 library target_link_libraries(ttp2 PRIVATE tasn1) +target_link_libraries(ttp2 PRIVATE tablog) install(TARGETS ttp2 DESTINATION lib) install(DIRECTORY include/ DESTINATION include) diff --git a/test/client/CMakeLists.txt b/test/client/CMakeLists.txt index cd28d80..4be7657 100644 --- a/test/client/CMakeLists.txt +++ b/test/client/CMakeLists.txt @@ -11,5 +11,6 @@ add_executable(ttp2-client ${SOURCES}) target_link_libraries(ttp2-client PRIVATE ttp2) find_package(Arrow REQUIRED) target_link_libraries(ttp2-client PRIVATE Arrow::arrow_shared) +target_link_libraries(ttp2-client PRIVATE tablog) install(TARGETS ttp2-client DESTINATION bin) diff --git a/test/server/CMakeLists.txt b/test/server/CMakeLists.txt index 41bf1a7..637563a 100644 --- a/test/server/CMakeLists.txt +++ b/test/server/CMakeLists.txt @@ -11,5 +11,6 @@ add_executable(ttp2-server ${SOURCES}) target_link_libraries(ttp2-server PRIVATE ttp2) find_package(Arrow REQUIRED) target_link_libraries(ttp2-server PRIVATE Arrow::arrow_shared) +target_link_libraries(ttp2-server PRIVATE tablog) install(TARGETS ttp2-server DESTINATION bin) From 7fc07b6f142fd9f6f73649ba4f9aa9f87111ce43 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 20 Jul 2026 14:40:09 +0200 Subject: [PATCH 49/53] update: add tablog to ttp2 lib, #25 --- lib/ttp2/include/asn1_helpers.h | 2 + lib/ttp2/include/networking.h | 10 ++-- lib/ttp2/src/asn1_helpers.cpp | 11 ++-- lib/ttp2/src/client_session_controller.cpp | 6 ++- lib/ttp2/src/networking.cpp | 59 ++++++++++++---------- lib/ttp2/src/server_session_controller.cpp | 6 ++- 6 files changed, 56 insertions(+), 38 deletions(-) diff --git a/lib/ttp2/include/asn1_helpers.h b/lib/ttp2/include/asn1_helpers.h index 7f4a3c8..d378e1f 100644 --- a/lib/ttp2/include/asn1_helpers.h +++ b/lib/ttp2/include/asn1_helpers.h @@ -1,6 +1,8 @@ #ifndef ASN1_HELPERS_H #define ASN1_HELPERS_H +#include + #include #include #include diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index c58b59d..104ff72 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -1,6 +1,8 @@ #ifndef NETWORKING_H #define NETWORKING_H +#include + #include #include #include @@ -80,14 +82,16 @@ namespace ttp2 { virtual void disconnect(); - protected: + protected: + tablog::Tablog* logger = &tablog::Tablog::getInstance(); + bool connected = true; bool isNumeric(const std::string& string); int bytesToInt(std::vector bytes, int size); - static std::shared_ptr tableToBuffer(const std::shared_ptr& table); - static std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); + std::shared_ptr tableToBuffer(const std::shared_ptr& table); + std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); std::vector requestQueue; std::vector responseQueue; diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 9f31638..27d1998 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -1,5 +1,7 @@ #include "../include/asn1_helpers.h" +#include + #include #include #include @@ -21,7 +23,8 @@ namespace ttp2 { standardPayload, std::strlen(standardPayload)); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + std::string asn1KeyString = asn1Key; + tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; @@ -33,7 +36,8 @@ namespace ttp2 { payloadString.c_str(), 0); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + std::string asn1KeyString = asn1Key; + tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; @@ -45,7 +49,8 @@ namespace ttp2 { int status = asn1_write_value(packet, asn1Key, targetBuffer, size); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set " << asn1Key << " failed!" << std::endl; + std::string asn1KeyString = asn1Key; + tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; diff --git a/lib/ttp2/src/client_session_controller.cpp b/lib/ttp2/src/client_session_controller.cpp index a067798..b12bcfd 100644 --- a/lib/ttp2/src/client_session_controller.cpp +++ b/lib/ttp2/src/client_session_controller.cpp @@ -1,5 +1,7 @@ #include "../include/client_session_controller.h" +#include + #include #include #include @@ -17,13 +19,13 @@ namespace ttp2 { void ClientSessionController::networkingSession() { epollFd = epoll_create1(0); if (epollFd == -1) { - std::wcout << "Failed to create epoll!" << std::endl; + logger->log(tablog::ERROR, "Failed to create epoll!"); } serverEvent.events = EPOLLIN; serverEvent.data.fd = socket; if (epoll_ctl(epollFd, EPOLL_CTL_ADD, socket, &serverEvent) == -1) { - std::wcout << "Failed to set epoll_ctl for client!" << std::endl; + logger->log(tablog::ERROR, "Failed to set epoll_ctl for client!"); return; } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 64615ec..e5ea058 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -1,14 +1,9 @@ #include "../include/networking.h" #include "../include/asn1_helpers.h" +#include + #include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -27,6 +22,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include + extern "C" { #include @@ -103,8 +106,8 @@ namespace ttp2 { if (asn1_array2tree(packets_asn1_tab, &definitions, errorDescription) != ASN1_SUCCESS) { - std::wcout << "Error in sendMessage when loading asn1: " - << errorDescription << std::endl; + std::string errorDescriptionString = errorDescription; + logger->log(tablog::ERROR, "Error in sendMessage when loading asn1: " + errorDescriptionString); return -1; } @@ -122,7 +125,7 @@ namespace ttp2 { int status = asn1_write_value(packet, "payload", "standard", 0); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set payload as standard failed!" << std::endl; + logger->log(tablog::ERROR, "ASN1 set payload as standard failed!"); } // Write contents @@ -134,7 +137,7 @@ namespace ttp2 { int status = asn1_write_value(packet, "payload", "file", 0); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set payload as file failed!" << std::endl; + logger->log(tablog::ERROR, "ASN1 set payload as file failed!"); } // Write contents @@ -157,7 +160,7 @@ namespace ttp2 { int status = asn1_write_value(packet, "payload", "viewportRequest", 0); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set payload as viewport request failed!" << std::endl; + logger->log(tablog::ERROR, "ASN1 set payload as viewport request failed!"); } // Write content @@ -177,7 +180,7 @@ namespace ttp2 { int status = asn1_write_value(packet, "payload", "viewport", 0); if (status != ASN1_SUCCESS) { - std::wcout << "ASN1 set payload as viewport failed!" << std::endl; + logger->log(tablog::ERROR, "ASN1 set payload as viewport failed!"); } // Write content @@ -203,8 +206,8 @@ namespace ttp2 { std::vector buffer(derLen); if (asn1_der_coding(packet, "", buffer.data(), &derLen, errorDescription) != ASN1_SUCCESS) { - std::wcout << "Error while encoding packet: " << errorDescription - << std::endl; + std::string errorDescriptionString = errorDescription; + logger->log(tablog::ERROR, "Error while encoding packet: " + errorDescriptionString); abort(); return -1; } @@ -232,10 +235,10 @@ namespace ttp2 { if (errno == EAGAIN || errno == EWOULDBLOCK) { break; } - std::wcout << "Error while receiving bytes!" << std::endl; + logger->log(tablog::ERROR, "Error while receiving bytes!"); return data; } else { - // std::wcout << "Socket closed!" << std::endl; + // logger->log(tablog::CRITICAL, "Socket closed!"); disconnect(); return data; } @@ -315,10 +318,10 @@ namespace ttp2 { data.payload = viewport; } else { - std::wcout << "Error decoding payload: Unknown type!" << std::endl; + logger->log(tablog::ERROR, "Error decoding payload: Unknown type!"); } } else { - std::wcout << "Error decoding ASN1" << std::endl; + logger->log(tablog::ERROR, "Error decoding ASN1"); } asn1_delete_structure(&packet); @@ -379,7 +382,7 @@ namespace ttp2 { Networking::PacketInfo Networking::peekResponse(int index) { Networking::PacketInfo packetInfo; if (index > getResponseQueueSize() - 1 || index < 0) { - std::wcout << "Invalid peek request: " << index << std::endl; + logger->log(tablog::ERROR, "Invalid peek request: " + std::to_string(index)); return packetInfo; } @@ -396,7 +399,7 @@ namespace ttp2 { Networking::PacketInfo Networking::peekRequest(int index) { Networking::PacketInfo packetInfo; if (index > getRequestQueueSize() - 1 || index < 0) { - std::wcout << "Invalid peek request: " << index << std::endl; + logger->log(tablog::ERROR, "Invalid peek request: " + std::to_string(index)); return packetInfo; } @@ -508,7 +511,7 @@ namespace ttp2 { arrow::Status status = streamWriter->WriteTable(*table); if (!status.ok()) { - std::wcout << "Something went wrong while writing the structure!" << std::endl; + logger->log(tablog::ERROR, "Something went wrong while writing the structure!"); return nullptr; } @@ -516,7 +519,7 @@ namespace ttp2 { arrow::Result> buffer = outputStream->Finish(); if (!buffer.ok()) { - std::wcout << "Something went wrong while converting table to buffer!" << std::endl; + logger->log(tablog::ERROR, "Something went wrong while converting table to buffer!"); return nullptr; } @@ -527,21 +530,21 @@ namespace ttp2 { arrow::BufferBuilder bufferBuilder; arrow::Status allocStatus = bufferBuilder.Resize(dataSize); if (!allocStatus.ok()) { - std::wcout << "Buffer allocation failed in bufferToTable" << std::endl; + logger->log(tablog::ERROR, "Buffer allocation failed in bufferToTable"); return arrow::Table::Make(arrow::schema({}), std::vector>{}); } // Make a physical copy so that the data isn't deleted. (That would lead to a shared_ptr with a table that points to no real data) arrow::Status appendStatus = bufferBuilder.Append(reinterpret_cast(rawData), dataSize); if (!appendStatus.ok()) { - std::wcout << "Failed to append raw data to buffer" << std::endl; + logger->log(tablog::ERROR, "Failed to append raw data to buffer"); return arrow::Table::Make(arrow::schema({}), std::vector>{}); } std::shared_ptr buffer; arrow::Status finishStatus = bufferBuilder.Finish(&buffer); if (!finishStatus.ok()) { - std::wcout << "Failed to finish buffer building" << std::endl; + logger->log(tablog::ERROR, "Failed to finish buffer building"); return arrow::Table::Make(arrow::schema({}), std::vector>{}); } @@ -549,14 +552,14 @@ namespace ttp2 { arrow::Result> streamReaderResult = arrow::ipc::RecordBatchStreamReader::Open(inputStream); if (!streamReaderResult.ok()) { - std::wcout << "Open input stream failed in bufferToTable" << std::endl; + logger->log(tablog::ERROR, "Open input stream failed in bufferToTable"); return arrow::Table::Make(arrow::schema({}), std::vector>{}); } std::shared_ptr streamReader = std::move(streamReaderResult).ValueUnsafe(); arrow::Result> tableResult = streamReader->ToTable(); if (!tableResult.ok()) { - std::wcout << "Create table failed in bufferToTable" << std::endl; + logger->log(tablog::ERROR, "Create table failed in bufferToTable"); return arrow::Table::Make(arrow::schema({}), std::vector>{}); } diff --git a/lib/ttp2/src/server_session_controller.cpp b/lib/ttp2/src/server_session_controller.cpp index 556ce62..21afe47 100644 --- a/lib/ttp2/src/server_session_controller.cpp +++ b/lib/ttp2/src/server_session_controller.cpp @@ -1,5 +1,7 @@ #include "../include/server_session_controller.h" +#include + #include #include #include @@ -20,13 +22,13 @@ namespace ttp2 { void ServerSessionController::networkingSession() { epollFd = epoll_create1(0); if (epollFd == -1) { - std::wcout << "Failed to create epoll!" << std::endl; + logger->log(tablog::ERROR, "Failed to create epoll!"); } clientEvent.events = EPOLLIN; clientEvent.data.fd = clientSocket; if (epoll_ctl(epollFd, EPOLL_CTL_ADD, clientSocket, &clientEvent) == -1) { - std::wcout << "Failed to set epoll_ctl for client!" << std::endl; + logger->log(tablog::ERROR, "Failed to set epoll_ctl for client!"); return; } From 21cde68f167fcdcc5eb72d3fa92925b48b6cc6a6 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 20 Jul 2026 17:35:45 +0200 Subject: [PATCH 50/53] update: implement logger registry, #25 --- flake.lock | 6 +++--- lib/ttp2/include/networking.h | 4 +++- lib/ttp2/src/asn1_helpers.cpp | 7 ++++--- lib/ttp2/src/client_session_controller.cpp | 5 ++++- lib/ttp2/src/networking.cpp | 9 +++++++++ lib/ttp2/src/server_session_controller.cpp | 5 ++++- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index b08124f..caf9d13 100644 --- a/flake.lock +++ b/flake.lock @@ -43,11 +43,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1784384014, - "narHash": "sha256-7m2OFL08r7MAeJvwUVXpCoBRq2iVHVcCDwxW+GoUNbk=", + "lastModified": 1784558310, + "narHash": "sha256-4d0QJZu5j5vDgJ/bp2kkMiBcivD9CDZSOrkCFcNKZXQ=", "owner": "Sobottasgithub", "repo": "tablog", - "rev": "dea2163cd34d978a97ee09b90d832f75d1890950", + "rev": "ded1d9094b5a76c323be795b674ee3fa7514c950", "type": "github" }, "original": { diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index 104ff72..c37deb0 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -83,7 +83,7 @@ namespace ttp2 { virtual void disconnect(); protected: - tablog::Tablog* logger = &tablog::Tablog::getInstance(); + std::shared_ptr logger; bool connected = true; @@ -93,6 +93,8 @@ namespace ttp2 { std::shared_ptr tableToBuffer(const std::shared_ptr& table); std::shared_ptr bufferToTable(const uint8_t* rawData, int64_t dataSize); + void configureLogger(std::string name); + std::vector requestQueue; std::vector responseQueue; std::mutex mtx; diff --git a/lib/ttp2/src/asn1_helpers.cpp b/lib/ttp2/src/asn1_helpers.cpp index 27d1998..6d8d59b 100644 --- a/lib/ttp2/src/asn1_helpers.cpp +++ b/lib/ttp2/src/asn1_helpers.cpp @@ -1,5 +1,6 @@ #include "../include/asn1_helpers.h" +#include #include #include @@ -24,7 +25,7 @@ namespace ttp2 { if (status != ASN1_SUCCESS) { std::string asn1KeyString = asn1Key; - tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); + tablog::TablogRegistry::getInstance().get("TTP2")->log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; @@ -37,7 +38,7 @@ namespace ttp2 { if (status != ASN1_SUCCESS) { std::string asn1KeyString = asn1Key; - tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); + tablog::TablogRegistry::getInstance().get("TTP2")->log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; @@ -50,7 +51,7 @@ namespace ttp2 { if (status != ASN1_SUCCESS) { std::string asn1KeyString = asn1Key; - tablog::Tablog::getInstance().log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); + tablog::TablogRegistry::getInstance().get("TTP2")->log(tablog::ERROR, "ASN1 set " + asn1KeyString + " failed!"); } return packet; diff --git a/lib/ttp2/src/client_session_controller.cpp b/lib/ttp2/src/client_session_controller.cpp index b12bcfd..854db9e 100644 --- a/lib/ttp2/src/client_session_controller.cpp +++ b/lib/ttp2/src/client_session_controller.cpp @@ -10,9 +10,12 @@ #include namespace ttp2 { - ClientSessionController::ClientSessionController() {} + ClientSessionController::ClientSessionController() { + configureLogger("TTP2"); + } ClientSessionController::ClientSessionController(int &socket) { + configureLogger("TTP2"); this->socket = socket; } diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index e5ea058..9fcb916 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -1,6 +1,7 @@ #include "../include/networking.h" #include "../include/asn1_helpers.h" +#include #include #include @@ -567,4 +568,12 @@ namespace ttp2 { } void Networking::disconnect() {} + + void Networking::configureLogger(std::string name) { + tablog::TablogRegistry* registry = &tablog::TablogRegistry::getInstance(); + std::shared_ptr logger = std::make_shared(); + logger->configure(name, true); + registry->registerLogger(name, logger); + this->logger = logger; + } } diff --git a/lib/ttp2/src/server_session_controller.cpp b/lib/ttp2/src/server_session_controller.cpp index 21afe47..716ff1c 100644 --- a/lib/ttp2/src/server_session_controller.cpp +++ b/lib/ttp2/src/server_session_controller.cpp @@ -12,9 +12,12 @@ #include namespace ttp2 { - ServerSessionController::ServerSessionController() {} + ServerSessionController::ServerSessionController() { + configureLogger("TTP2"); + } ServerSessionController::ServerSessionController(int serverSocket, int clientSocket) { + configureLogger("TTP2"); this->serverSocket = serverSocket; this->clientSocket = clientSocket; } From b46c8ebe97268e07fce0e47a37c79046bf505eb5 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Mon, 20 Jul 2026 17:36:08 +0200 Subject: [PATCH 51/53] update: flake version --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b763c12..761fa71 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.5"; + version = "2.1.6"; libtablog = tablog.packages.${system}.lib; From 87e214c4b664e7a20232016ab86d31fc29759529 Mon Sep 17 00:00:00 2001 From: Patrick Schulze Date: Thu, 23 Jul 2026 15:30:01 +0200 Subject: [PATCH 52/53] update: update tablog --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index caf9d13..8abbdfa 100644 --- a/flake.lock +++ b/flake.lock @@ -43,11 +43,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1784558310, - "narHash": "sha256-4d0QJZu5j5vDgJ/bp2kkMiBcivD9CDZSOrkCFcNKZXQ=", + "lastModified": 1784813121, + "narHash": "sha256-ixwsmElsnlQE0MHPjS6m5+XmS47bFPHBYtZIxCTwLB8=", "owner": "Sobottasgithub", "repo": "tablog", - "rev": "ded1d9094b5a76c323be795b674ee3fa7514c950", + "rev": "e47b0796e6a0820315a846fb02a9c9c89b5bda33", "type": "github" }, "original": { From 015211810584b05cd88607d10d683e29967a42d4 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 24 Jul 2026 16:31:12 +0200 Subject: [PATCH 53/53] update: implement filter --- flake.nix | 2 +- lib/ttp2/include/networking.h | 7 ++++- lib/ttp2/src/networking.cpp | 52 ++++++++++++++++++++++----------- lib/ttp2/src/packets.asn1 | 8 ++++- lib/ttp2/src/packets_asn1_tab.c | 7 ++++- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/flake.nix b/flake.nix index 761fa71..ca39332 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - version = "2.1.6"; + version = "2.1.7"; libtablog = tablog.packages.${system}.lib; diff --git a/lib/ttp2/include/networking.h b/lib/ttp2/include/networking.h index c37deb0..94c2756 100644 --- a/lib/ttp2/include/networking.h +++ b/lib/ttp2/include/networking.h @@ -43,8 +43,13 @@ namespace ttp2 { int yEnd = 0; std::shared_ptr payload = arrow::Table::Make(arrow::schema({}), std::vector>{}, 0); }; + + struct Filter { + std::string columnName; + std::string regex; + }; - typedef std::variant payloadVariants; + typedef std::variant payloadVariants; struct Packet { int id = -1; diff --git a/lib/ttp2/src/networking.cpp b/lib/ttp2/src/networking.cpp index 9fcb916..74a9504 100644 --- a/lib/ttp2/src/networking.cpp +++ b/lib/ttp2/src/networking.cpp @@ -200,6 +200,18 @@ namespace ttp2 { std::shared_ptr table = std::get(payload).payload; std::shared_ptr buffer = tableToBuffer(table); packet = Asn1Helpers::asn1EncodePayload(buffer->data(), buffer->size(), packet, "payload.viewport.payload"); + } else if (std::holds_alternative(payload)) { + // Write structure + int status = asn1_write_value(packet, "payload", "filter", 0); + if (status != ASN1_SUCCESS) { + logger->log(tablog::ERROR, "ASN1 set payload as filter failed!"); + } + + // Write content + std::string columnName = std::get(payload).columnName; + packet = Asn1Helpers::asn1EncodePayload(columnName, packet, "payload.filter.columnName"); + std::string regex = std::get(payload).regex; + packet = Asn1Helpers::asn1EncodePayload(regex, packet, "payload.filter.regex"); } int derLen = 0; @@ -289,16 +301,16 @@ namespace ttp2 { data.payload = standard; } else if (typeNameString == "file") { - Networking::File file; - file.filePath = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.filePath"); - file.start = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.start"); - file.end = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.end"); + Networking::File file; + file.filePath = Asn1Helpers::asn1DecodePayloadString(packet, "payload.file.filePath"); + file.start = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.start"); + file.end = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.file.end"); - std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.file.payload"); - // const uint8_t* bufferConst = buffer.data(); - file.payload = bufferToTable(buffer.data(), buffer.size()); + std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.file.payload"); + // const uint8_t* bufferConst = buffer.data(); + file.payload = bufferToTable(buffer.data(), buffer.size()); - data.payload = file; + data.payload = file; } else if (typeNameString == "viewportRequest") { Networking::ViewportRequest viewportRequest; @@ -309,15 +321,21 @@ namespace ttp2 { data.payload = viewportRequest; } else if (typeNameString == "viewport") { - Networking::Viewport viewport; - viewport.xStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xStart"); - viewport.xEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); - viewport.yStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yStart"); - viewport.yEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); - std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.viewport.payload"); - viewport.payload = bufferToTable(buffer.data(), buffer.size()); - - data.payload = viewport; + Networking::Viewport viewport; + viewport.xStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xStart"); + viewport.xEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.xEnd"); + viewport.yStart = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yStart"); + viewport.yEnd = Asn1Helpers::asn1DecodePayloadInt(packet, "payload.viewport.yEnd"); + std::vector buffer = Asn1Helpers::asn1DecodePayloadBuffer(packet, "payload.viewport.payload"); + viewport.payload = bufferToTable(buffer.data(), buffer.size()); + + data.payload = viewport; + } else if (typeNameString == "filter") { + Networking::Filter filter; + filter.columnName = Asn1Helpers::asn1DecodePayloadString(packet, "payload.filter.columnName"); + filter.regex = Asn1Helpers::asn1DecodePayloadString(packet, "payload.filter.regex"); + + data.payload = filter; } else { logger->log(tablog::ERROR, "Error decoding payload: Unknown type!"); } diff --git a/lib/ttp2/src/packets.asn1 b/lib/ttp2/src/packets.asn1 index 3c3057a..636e461 100644 --- a/lib/ttp2/src/packets.asn1 +++ b/lib/ttp2/src/packets.asn1 @@ -26,13 +26,19 @@ Viewport ::= SEQUENCE { payload OCTET STRING } +Filter ::= SEQUENCE { + columnName OCTET STRING, + regex OCTET STRING +} + Packet ::= SEQUENCE { id INTEGER, payload CHOICE { standard [0] Standard, file [1] File, viewportRequest [2] ViewportRequest, - viewport [3] Viewport + viewport [3] Viewport, + filter [4] Filter } } diff --git a/lib/ttp2/src/packets_asn1_tab.c b/lib/ttp2/src/packets_asn1_tab.c index 3a048ae..a160d30 100644 --- a/lib/ttp2/src/packets_asn1_tab.c +++ b/lib/ttp2/src/packets_asn1_tab.c @@ -25,6 +25,9 @@ const asn1_static_node packets_asn1_tab[] = { { "yStart", 1073741827, NULL }, { "yEnd", 1073741827, NULL }, { "payload", 7, NULL }, + { "Filter", 1610612741, NULL }, + { "columnName", 1073741831, NULL }, + { "regex", 7, NULL }, { "Packet", 536870917, NULL }, { "id", 1073741827, NULL }, { "payload", 536870930, NULL }, @@ -34,7 +37,9 @@ const asn1_static_node packets_asn1_tab[] = { { NULL, 2056, "1"}, { "viewportRequest", 1610620930, "ViewportRequest"}, { NULL, 2056, "2"}, - { "viewport", 536879106, "Viewport"}, + { "viewport", 1610620930, "Viewport"}, { NULL, 2056, "3"}, + { "filter", 536879106, "Filter"}, + { NULL, 2056, "4"}, { NULL, 0, NULL } };