Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/libs
Submodule libs updated 68 files
+1 −0 .gitignore
+1 −1 bflibc/makefile
+18 −0 bflibc/src/bfmath.c
+5 −0 bflibc/src/bfmath.h
+2 −0 bflibc/src/lock.c
+12 −0 bflibc/testbench/math_tests.h
+6 −3 bflibcpp/makefile
+4 −1 bflibcpp/readme.md
+82 −29 bflibcpp/src/array.hpp
+38 −0 bflibcpp/src/atomic.hpp
+32 −12 bflibcpp/src/basicmap.hpp
+5 −0 bflibcpp/src/bflibcpp.hpp
+4 −0 bflibcpp/src/bintree.hpp
+4 −0 bflibcpp/src/collection.hpp
+50 −2 bflibcpp/src/data.cpp
+17 −2 bflibcpp/src/data.hpp
+15 −0 bflibcpp/src/defer.cpp
+44 −0 bflibcpp/src/defer.hpp
+59 −0 bflibcpp/src/deque.hpp
+1 −1 bflibcpp/src/directory.hpp
+1 −1 bflibcpp/src/file.hpp
+33 −0 bflibcpp/src/hash.hpp
+16 −11 bflibcpp/src/hashmap.hpp
+35 −32 bflibcpp/src/list.hpp
+2 −2 bflibcpp/src/map.hpp
+11 −0 bflibcpp/src/object.cpp
+14 −5 bflibcpp/src/object.hpp
+1 −1 bflibcpp/src/path.hpp
+5 −10 bflibcpp/src/release.hpp
+453 −0 bflibcpp/src/sort.hpp
+68 −16 bflibcpp/src/string.cpp
+31 −8 bflibcpp/src/string.hpp
+21 −0 bflibcpp/src/swap.hpp
+4 −0 bflibcpp/src/time.cpp
+1 −0 bflibcpp/src/time.hpp
+18 −0 bflibcpp/src/typesortstrategy.hpp
+190 −0 bflibcpp/src/url.cpp
+87 −0 bflibcpp/src/url.hpp
+5 −225 bflibcpp/src/vector.hpp
+18 −6 bflibcpp/testbench/array_tests.hpp
+27 −2 bflibcpp/testbench/atomic_tests.hpp
+25 −37 bflibcpp/testbench/data_tests.hpp
+67 −0 bflibcpp/testbench/defer_tests.hpp
+11 −14 bflibcpp/testbench/hashmap_tests.hpp
+26 −67 bflibcpp/testbench/list_tests.hpp
+2 −2 bflibcpp/testbench/object_tests.hpp
+32 −36 bflibcpp/testbench/string_tests.hpp
+4 −2 bflibcpp/testbench/tests.cpp
+158 −0 bflibcpp/testbench/url_tests.hpp
+73 −12 bflibcpp/testbench/vector_tests.hpp
+20 −6 bflibcpp/todo.md
+6 −4 bfnet/makefile
+1 −0 bfnet/notes.md
+0 −3 bfnet/src/bfnet.hpp
+0 −33 bfnet/src/buffer.cpp
+0 −34 bfnet/src/buffer.hpp
+50 −50 bfnet/src/connection.cpp
+16 −9 bfnet/src/connection.hpp
+5 −6 bfnet/src/envelope.cpp
+6 −6 bfnet/src/envelope.hpp
+5 −0 bfnet/src/server.cpp
+25 −14 bfnet/src/socket.cpp
+31 −6 bfnet/src/socket.hpp
+135 −15 bfnet/testbench/socket_tests.hpp
+2 −0 bfnet/todo.md
+48 −0 bftest/src/bftest.c
+18 −6 bftest/src/bftest.h
+5 −7 bftest/todo.md
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions src/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,25 @@ 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(), c.size());
return this->_sc->queueData(c.data());
}

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();
size_t size = c.size();
const Packet * p = (const Packet *) c.data()->buffer();
size_t size = c.data()->size();

if (!sc || !p) {
BFRelease(envelope);
Expand All @@ -370,6 +373,7 @@ void Agent::packetReceive(SocketEnvelope * envelope) {

BFRetain(agent);

LOG_DEBUG("agent received packet header: %d", p->header.type);
switch (p->header.type) {
case kPayloadTypeMessage:
agent->receivedPayloadTypeMessage(p);
Expand Down Expand Up @@ -402,6 +406,7 @@ void Agent::packetReceive(SocketEnvelope * envelope) {
agent->receivedPayloadTypeChatroomEnrollmentForm(p);
break;
default:
LOG_DEBUG("unknown header type: %d", p->header.type);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User;

namespace BF {
namespace Net {
class SocketEnvelope;
class Envelope;
class Connection;
}
}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
3 changes: 1 addition & 2 deletions src/chatroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ int _InterfaceDrawUserInputDraft(
werase(inputwin);
box(inputwin, 0, 0);

_InterfaceFixTextInBoxedWindow(inputwin, userInput, 1);
_InterfaceFixTextInBoxedWindow(inputwin, userInput.cString(), 1);

wrefresh(inputwin);

Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/log.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* author: brando
* date:
* date: 2/12/24
*/

#ifndef LOG_HPP
Expand Down
6 changes: 3 additions & 3 deletions src/office.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using namespace BF;
using namespace BF::Net;

Atomic<Queue<SocketEnvelope *>> inbox;
Atomic<Queue<Envelope *>> inbox;
BFLock inboxlock;
BFThreadAsyncID _tid = NULL;

Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/office.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class User;

namespace BF {
namespace Net {
class SocketEnvelope;
class Envelope;
}
}

Expand All @@ -22,7 +22,7 @@ namespace BF {
*/
namespace Office {

void packetReceive(BF::Net::SocketEnvelope * envelope);
void packetReceive(BF::Net::Envelope * envelope);

int start();
int stop();
Expand Down
7 changes: 3 additions & 4 deletions src/operand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ int _OperandAcceptArgsCompare(char * a, char * b) {
return strcmp(a, b);
}

Operand::Operand(std::initializer_list<const char *> list) : Object() {
Operand::Operand(std::initializer_list<String> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/operand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class Operand : public BF::Object {
public:
Operand(std::initializer_list<const char *> list);
Operand(std::initializer_list<BF::String> list);
virtual ~Operand();

bool compare(const Operand & op);
Expand Down
15 changes: 13 additions & 2 deletions src/sealedpacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,40 @@ extern "C" {
#include <bflibc/bflibc.h>
}

using namespace BF;

SealedPacket::SealedPacket(const void * data, size_t size) {
/*
this->_dataPlainSize = size;

this->_dataPlain = malloc(sizeof(char) * size);
if (this->_dataPlain == NULL)
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;
}

size_t SealedPacket::size() {
return this->_dataPlainSize;
}

*/
9 changes: 5 additions & 4 deletions src/sealedpacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define SEALED_PACKET_HPP

#include <bflibcpp/object.hpp>
#include <bflibcpp/data.hpp>

/**
* handles encryption and serialization of the
Expand All @@ -22,12 +23,12 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion testbench/ciphersymmetric_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions testbench/command_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
13 changes: 7 additions & 6 deletions todo.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down