From 2e32bdc5463e1f1c48c4d7440b0c40e3ce4cd5a6 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 27 Feb 2025 10:22:41 -0800 Subject: [PATCH 01/14] recording branch --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 075a26b..18f82d7 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 075a26b8f9ec93110cd3dd22a6e319e970b40519 +Subproject commit 18f82d77e53273ff0ef69e1235162dac35f53597 From a10f27c2f3aa20b12085be75f72f9717811f4577 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 27 Feb 2025 13:26:20 -0800 Subject: [PATCH 02/14] updating envelope --- external/libs | 2 +- src/agent.cpp | 4 ++-- src/agent.hpp | 4 ++-- src/office.cpp | 6 +++--- src/office.hpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/external/libs b/external/libs index 18f82d7..5f49e17 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 18f82d77e53273ff0ef69e1235162dac35f53597 +Subproject commit 5f49e17c318d9f028f697ce8e4a8db2327a0351b diff --git a/src/agent.cpp b/src/agent.cpp index 1f41a76..ce1365d 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -333,13 +333,13 @@ int Agent::sendPacket(const Packet * pkt) { return this->_sc->queueData(c.data(), c.size()); } -void Agent::packetReceive(SocketEnvelope * envelope) { +void Agent::packetReceive(Envelope * envelope) { if (!envelope) return; BFRetain(envelope); - SealedPacket c(envelope->buf()->data(), envelope->buf()->size()); + SealedPacket c(envelope->data()->buffer(), envelope->data()->size()); Connection * sc = envelope->connection(); const Packet * p = (const Packet *) c.data(); diff --git a/src/agent.hpp b/src/agent.hpp index 89581eb..aa6f6ba 100644 --- a/src/agent.hpp +++ b/src/agent.hpp @@ -15,7 +15,7 @@ class User; namespace BF { namespace Net { - class SocketEnvelope; + class Envelope; class Connection; } } @@ -35,7 +35,7 @@ class Agent : public BF::Object { * sc : each agent should have this * bub : copy data if you need to use after function returns */ - static void packetReceive(BF::Net::SocketEnvelope * envelope); + static void packetReceive(BF::Net::Envelope * envelope); /** * this is a callback described by the Socket family diff --git a/src/office.cpp b/src/office.cpp index 96dd3e1..fe14d4a 100644 --- a/src/office.cpp +++ b/src/office.cpp @@ -18,7 +18,7 @@ using namespace BF; using namespace BF::Net; -Atomic> inbox; +Atomic> inbox; BFLock inboxlock; BFThreadAsyncID _tid = NULL; @@ -34,7 +34,7 @@ int Office::quitApplication(const User * user) { return Agent::broadcast(&p); } -void Office::packetReceive(SocketEnvelope * envelope) { +void Office::packetReceive(Envelope * envelope) { // push into queue BFRetain(envelope); inbox.get().push(envelope); @@ -49,7 +49,7 @@ void _OfficeInDataWorkerThread(void * in) { inbox.lock(); // get first item from the queue - SocketEnvelope * envelope = inbox.unsafeget().front(); + Envelope * envelope = inbox.unsafeget().front(); // send it over to the agents Agent::packetReceive(envelope); diff --git a/src/office.hpp b/src/office.hpp index 90d06a1..35093ce 100644 --- a/src/office.hpp +++ b/src/office.hpp @@ -13,7 +13,7 @@ class User; namespace BF { namespace Net { - class SocketEnvelope; + class Envelope; } } @@ -22,7 +22,7 @@ namespace BF { */ namespace Office { -void packetReceive(BF::Net::SocketEnvelope * envelope); +void packetReceive(BF::Net::Envelope * envelope); int start(); int stop(); From 4e5f1c2b0fd55087d29f1b5afdcac12e28dc1df8 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 27 Feb 2025 13:28:48 -0800 Subject: [PATCH 03/14] update libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 5f49e17..dbc11f1 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 5f49e17c318d9f028f697ce8e4a8db2327a0351b +Subproject commit dbc11f1564eb4ee00a47a060c2539b9119d6bfc7 From 571de25113bb85c558eea6017252ba0454739842 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 25 Mar 2025 14:09:16 -0700 Subject: [PATCH 04/14] accepting libs changes --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index dbc11f1..81635d0 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit dbc11f1564eb4ee00a47a060c2539b9119d6bfc7 +Subproject commit 81635d08903c47cbf5d8dc08826139749bb152c5 From 652ea798a14dfdbe865d63dfda170732f33e5961 Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 16 Apr 2025 22:10:58 -0700 Subject: [PATCH 05/14] update date --- src/log.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log.hpp b/src/log.hpp index 3bc4a67..7b59ff4 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -1,6 +1,6 @@ /** * author: brando - * date: + * date: 2/12/24 */ #ifndef LOG_HPP From 3da5f5fdc3daf8d5f180487cc1b6e62bbc9809f2 Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 16 Apr 2025 22:12:10 -0700 Subject: [PATCH 06/14] updating libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 81635d0..30f136b 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 81635d08903c47cbf5d8dc08826139749bb152c5 +Subproject commit 30f136b6cab33eeddf6d5c149ad0533949841bb2 From 99a3933ca22fafcb532bc63574c9978e8ee7d537 Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 30 Apr 2025 18:35:44 -0700 Subject: [PATCH 07/14] update code --- external/libs | 2 +- makefile | 4 ++-- src/agent.cpp | 4 ++-- src/chatroom.cpp | 3 +-- src/interface.cpp | 4 ++-- src/operand.cpp | 7 +++---- src/operand.hpp | 2 +- src/sealedpacket.cpp | 15 +++++++++++++-- src/sealedpacket.hpp | 7 +++++++ 9 files changed, 32 insertions(+), 16 deletions(-) diff --git a/external/libs b/external/libs index 30f136b..68b5ad9 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 30f136b6cab33eeddf6d5c149ad0533949841bb2 +Subproject commit 68b5ad9380ff5db08dc9a224f4f82edd9525e213 diff --git a/makefile b/makefile index d0ff4f4..e5f3e8e 100644 --- a/makefile +++ b/makefile @@ -63,13 +63,13 @@ endif ifeq ($(CONFIG),release) # release LIBRARIES += \ - external/bin/libs/release/bflibc/libbfc.a \ external/bin/libs/release/bflibcpp/libbfcpp.a \ + external/bin/libs/release/bflibc/libbfc.a \ external/bin/libs/release/bfnet/libbfnet.a else LIBRARIES += \ - external/bin/libs/debug/bflibc/libbfc-debug.a \ external/bin/libs/debug/bflibcpp/libbfcpp-debug.a \ + external/bin/libs/debug/bflibc/libbfc-debug.a \ external/bin/libs/debug/bfnet/libbfnet-debug.a endif diff --git a/src/agent.cpp b/src/agent.cpp index ce1365d..ad4713f 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -330,7 +330,7 @@ void Agent::receivedPayloadTypeChatroomResignation(const Packet * pkt) { int Agent::sendPacket(const Packet * pkt) { SealedPacket c(pkt, sizeof(Packet)); - return this->_sc->queueData(c.data(), c.size()); + return this->_sc->queueData(c.data()); } void Agent::packetReceive(Envelope * envelope) { @@ -343,7 +343,7 @@ void Agent::packetReceive(Envelope * envelope) { Connection * sc = envelope->connection(); const Packet * p = (const Packet *) c.data(); - size_t size = c.size(); + size_t size = c.data()->size(); if (!sc || !p) { BFRelease(envelope); diff --git a/src/chatroom.cpp b/src/chatroom.cpp index d3d8bdd..cdff2a1 100644 --- a/src/chatroom.cpp +++ b/src/chatroom.cpp @@ -30,8 +30,7 @@ void _ChatroomReleaseAgent(Agent * a) { BFRelease(a); } Chatroom::Chatroom() : Object() { #ifndef TESTING if (Chat::SocketGetMode() != SOCKET_MODE_SERVER) { - String msg("Can only create a raw chatroom from server mode (current mode '%c')", Chat::SocketGetMode()); - throw Exception(msg); + throw Exception("Can only create a raw chatroom from server mode (current mode '%c')", Chat::SocketGetMode()); } #endif diff --git a/src/interface.cpp b/src/interface.cpp index 4684b27..623bc26 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -551,7 +551,7 @@ int _InterfaceDrawUserInputDraft( werase(inputwin); box(inputwin, 0, 0); - _InterfaceFixTextInBoxedWindow(inputwin, userInput, 1); + _InterfaceFixTextInBoxedWindow(inputwin, userInput.cString(), 1); wrefresh(inputwin); @@ -673,7 +673,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } else { char chatroomname[CHAT_ROOM_NAME_SIZE]; if (cmd.count() > 1) { - strncpy(chatroomname, cmd[1], CHAT_ROOM_NAME_SIZE); + strncpy(chatroomname, cmd[1].cString(), CHAT_ROOM_NAME_SIZE); } else { // set up chat room name // diff --git a/src/operand.cpp b/src/operand.cpp index 851b000..4031a1a 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -27,11 +27,10 @@ int _OperandAcceptArgsCompare(char * a, char * b) { return strcmp(a, b); } -Operand::Operand(std::initializer_list list) : Object() { +Operand::Operand(std::initializer_list list) : Object() { this->_acceptedArgs.setReleaseCallback(_OperandAcceptArgsRelease); - for (const char * arg : list) { - char * buf = BFStringCopyString(arg); - this->_acceptedArgs.add(buf); + for (const String & arg : list) { + this->_acceptedArgs.add(arg.cStringCopy()); } this->_acceptedArgs.setComparator(_OperandAcceptArgsCompare); } diff --git a/src/operand.hpp b/src/operand.hpp index b601759..dcc4a62 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -22,7 +22,7 @@ */ class Operand : public BF::Object { public: - Operand(std::initializer_list list); + Operand(std::initializer_list list); virtual ~Operand(); bool compare(const Operand & op); diff --git a/src/sealedpacket.cpp b/src/sealedpacket.cpp index 0bfb993..6c1eee4 100644 --- a/src/sealedpacket.cpp +++ b/src/sealedpacket.cpp @@ -12,7 +12,10 @@ extern "C" { #include } +using namespace BF; + SealedPacket::SealedPacket(const void * data, size_t size) { + /* this->_dataPlainSize = size; this->_dataPlain = malloc(sizeof(char) * size); @@ -20,16 +23,24 @@ SealedPacket::SealedPacket(const void * data, size_t size) { return; memcpy(this->_dataPlain, data, size); + */ + this->_data = new Data(size, (const unsigned char *) data); } SealedPacket::~SealedPacket() { - BFFree(this->_dataPlain); + //BFFree(this->_dataPlain); + BFRelease(this->_data); } bool SealedPacket::isEncrypted() { return false; } +const Data * SealedPacket::data() const { + return this->_data; +} + +/* const void * SealedPacket::data() { return this->_dataPlain; } @@ -37,4 +48,4 @@ const void * SealedPacket::data() { size_t SealedPacket::size() { return this->_dataPlainSize; } - +*/ diff --git a/src/sealedpacket.hpp b/src/sealedpacket.hpp index a7a4049..a083d60 100644 --- a/src/sealedpacket.hpp +++ b/src/sealedpacket.hpp @@ -7,6 +7,7 @@ #define SEALED_PACKET_HPP #include +#include /** * handles encryption and serialization of the @@ -22,12 +23,18 @@ class SealedPacket : public BF::Object { ~SealedPacket(); bool isEncrypted(); + /* const void * data(); size_t size(); + */ + const BF::Data * data() const; private: + /* void * _dataPlain; size_t _dataPlainSize; + */ + BF::Data * _data; }; #endif // SEALED_PACKET_HPP From 16eccb4d10f02354c7d963f991750c68ede8211a Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 30 Apr 2025 18:38:20 -0700 Subject: [PATCH 08/14] updating tests --- testbench/ciphersymmetric_tests.hpp | 2 +- testbench/command_tests.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testbench/ciphersymmetric_tests.hpp b/testbench/ciphersymmetric_tests.hpp index ea1de0d..3f5af7a 100644 --- a/testbench/ciphersymmetric_tests.hpp +++ b/testbench/ciphersymmetric_tests.hpp @@ -141,7 +141,7 @@ BFTEST_UNIT_FUNC(test_LongString, 2<<10, { if (!result) { String res = dec; - if (strcmp(res.cString(), str)) { + if (res != str) { printf("%s != %s\n", res.cString(), str.cString()); result = 3; } diff --git a/testbench/command_tests.hpp b/testbench/command_tests.hpp index aded932..a2a7d0a 100644 --- a/testbench/command_tests.hpp +++ b/testbench/command_tests.hpp @@ -37,9 +37,9 @@ BFTEST_UNIT_FUNC(test_commandargs, 2<<10, { Command c(buf); BF_ASSERT(c.op() == Operand({"command"})); - BF_ASSERT(!strcmp(c[1], "subcommand")); - BF_ASSERT(!strcmp(c[2], "arg0")); - BF_ASSERT(!strcmp(c[3], "arg1")); + BF_ASSERT(!strcmp(c[1].c_str(), "subcommand")); + BF_ASSERT(!strcmp(c[2].c_str(), "arg0")); + BF_ASSERT(!strcmp(c[3].c_str(), "arg1")); }) BFTEST_UNIT_FUNC(test_commandargscount, 2<<10, { From 3b0e0883210adc7d2bb34c6646bf2ba21a4f3b43 Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 2 May 2025 11:41:34 -0700 Subject: [PATCH 09/14] adding logging --- src/agent.cpp | 2 ++ src/chat.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/agent.cpp b/src/agent.cpp index ad4713f..3172459 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -370,6 +370,7 @@ void Agent::packetReceive(Envelope * envelope) { BFRetain(agent); + LOG_DEBUG("agent received packet header: %d", p->header.type); switch (p->header.type) { case kPayloadTypeMessage: agent->receivedPayloadTypeMessage(p); @@ -402,6 +403,7 @@ void Agent::packetReceive(Envelope * envelope) { agent->receivedPayloadTypeChatroomEnrollmentForm(p); break; default: + LOG_DEBUG("unknown header type: %d", p->header.type); break; } diff --git a/src/chat.cpp b/src/chat.cpp index 5c9efc8..1cf0ff5 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -188,6 +188,7 @@ int Chat::Main(int argc, char * argv[]) { LOG_OPEN; LOG_DEBUG("============ App started ============"); + LOG_DEBUG("packet size: %d", CHAT_SOCKET_BUFFER_SIZE); if (showversion) { _ChatShowVersion(argv[0]); From a56631bcff4c89b3196b2b1f76aa19d4c63efd34 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 6 May 2025 11:21:36 -0700 Subject: [PATCH 10/14] update libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 68b5ad9..8929a0c 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 68b5ad9380ff5db08dc9a224f4f82edd9525e213 +Subproject commit 8929a0cebccda978dbb611808c8e66298b56fba0 From 83b0eba88dbf7c7086f198ed8115fe4c3ded1552 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 6 May 2025 15:39:24 -0700 Subject: [PATCH 11/14] Works still --- src/agent.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/agent.cpp b/src/agent.cpp index 3172459..76613e2 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -328,6 +328,9 @@ void Agent::receivedPayloadTypeChatroomResignation(const Packet * pkt) { } int Agent::sendPacket(const Packet * pkt) { + if (!pkt) return 1; + + LOG_DEBUG("sending package header type=%d", pkt->header.type); SealedPacket c(pkt, sizeof(Packet)); return this->_sc->queueData(c.data()); @@ -342,7 +345,7 @@ void Agent::packetReceive(Envelope * envelope) { SealedPacket c(envelope->data()->buffer(), envelope->data()->size()); Connection * sc = envelope->connection(); - const Packet * p = (const Packet *) c.data(); + const Packet * p = (const Packet *) c.data()->buffer(); size_t size = c.data()->size(); if (!sc || !p) { From 1fb786c2c51ee68705a25260d6941169416592fe Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 6 May 2025 16:36:52 -0700 Subject: [PATCH 12/14] clean up --- src/interface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/interface.cpp b/src/interface.cpp index 623bc26..c082eda 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -820,7 +820,6 @@ int Interface::windowLoop() { this->_prevstate = kInterfaceStateUnknown; this->_state = kInterfaceStatePromptUsername; - //this->_state = kInterfaceStateLobby; while (this->_state.get() != kInterfaceStateQuit) { // draw ui based on current state From 13ce09e03d60ec468bb5126d9f10a01ee3ebb5ad Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 6 May 2025 21:17:36 -0700 Subject: [PATCH 13/14] cleaning up --- src/sealedpacket.hpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/sealedpacket.hpp b/src/sealedpacket.hpp index a083d60..aa6f475 100644 --- a/src/sealedpacket.hpp +++ b/src/sealedpacket.hpp @@ -23,17 +23,11 @@ class SealedPacket : public BF::Object { ~SealedPacket(); bool isEncrypted(); - /* - const void * data(); - size_t size(); - */ + const BF::Data * data() const; private: - /* - void * _dataPlain; - size_t _dataPlainSize; - */ + BF::Data * _data; }; From 9f7117a738035e7035575ec4d65b51c1d3f0c3b8 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 6 May 2025 21:38:55 -0700 Subject: [PATCH 14/14] update todo --- todo.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/todo.md b/todo.md index 2d3e1f8..5e389e1 100644 --- a/todo.md +++ b/todo.md @@ -1,17 +1,17 @@ -x.x +**x.x** - [ ] window dynamic resizing - [ ] add to homebrew package manager - [ ] docker? - [ ] ai bot chatroom - [ ] clean interface.cpp. split some code into categorical source files -0.4 +**0.4** - [ ] wrap entire communication in encryption - [ ] user data window editor - [ ] ability to change user name - [ ] get list of users in chatroom -0.3 +**0.3** - [x] improved controls (easier commands or guidance) - [x] use of ":" for long commands - [x] single key commands @@ -25,14 +25,15 @@ x.x - [x] move package logic to libs - [ ] host vs server (allow user to run this application as a service) - [x] detect if users are active. Protect the case when remote users are disconnected unintentionally +- [ ] fix ncurses borders -0.2.1 +**0.2.1** - [x] issue with sending messages between two machines that are on macos and linux - [x] test on two macs - [x] build a macos universal binary - [x] properly quit to make sure the receiver isn't overworking -0.2 +**0.2** - [x] cross platform - [x] configure a local openssl usage in this repo - [x] chatroom encryption @@ -47,7 +48,7 @@ x.x - https://github.com/openssl/openssl/discussions/24924 - [x] separate sources for libs -0.1 +**0.1** - [x] make linux build - [x] make macos build - [x] test release builds