From 1845f2c39ea336626081fae435fb7fe28c18dbc4 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 26 Jun 2026 12:55:32 +0200 Subject: [PATCH 01/27] 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 02/27] 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 03/27] 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 04/27] 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 05/27] 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 06/27] 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 07/27] 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 08/27] 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 09/27] 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 10/27] 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 11/27] 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 12/27] 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 13/27] 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 14/27] 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 15/27] 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 16/27] 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 17/27] 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 18/27] 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 19/27] 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 20/27] 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 21/27] 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 22/27] 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 23/27] 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 24/27] 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 25/27] 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 26/27] 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 27/27] 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 } };