diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 45 | ||||
-rw-r--r-- | archived.md | 27 | ||||
-rw-r--r-- | send.c | 16 | ||||
-rw-r--r-- | server.c | 4 |
5 files changed, 44 insertions, 50 deletions
@@ -1,7 +1,7 @@ all: chatty server send clean: - rm -f server chatty send _id _clients + rm -f server chatty send tags *.log _* chatty: gcc -ggdb -Wall -pedantic -std=c99 -o chatty chatty.c @@ -9,22 +9,12 @@ The idea is the following: - authentication ## client -- [x] prompt -- [x] sending message -- [x] bug: do not allow sending empty message -- [x] wrapping messages -- [x] bug: when sending message after diconnect (serverfd?) -- [x] Handle disconnection thiin a thread, the best way would be -- [x] Add limit_y to printf_wrap -- [x] id2string on clients -- [x] ctrl+z to suspend -- [ ] bug(tb_printf_wrap): text after pfx is wrapped one too soon -- [ ] bug: when reconnecting nrecv != -1 -- [ ] bug: when disconnecting -- [ ] use error type success to say that authentication succeeded +- [ ] bug: when connecting two clients of the same account +- [ ] bug: wrapping does not work and displays nothing if there is no screen space +- [ ] bug: reconnect does not work when server does not know id +- [ ] markup for messages ## server -- [x] import clients - [ ] check that fds arena does not overflow - [ ] check if when sending and the client is offline (due to connection loss) what happens - [ ] timeout on recv? @@ -37,42 +27,17 @@ The idea is the following: negotiated. ## common -- [x] handle messages that are too large -- [x] refactor i&self into conn -- [x] logging -- [x] Req|Inf connection per client -- [x] connect/disconnect messages -- [ ] bug: blocking after `Added pollfd`, after importing a client and then connecting with the - id/or without? After reconnection fails chatty blocks (remove sleep) -- [ ] connect/disconnections messages - [ ] use IP address / domain - [ ] chat history -- [ ] asserting, logging if fail / halt execution +- [ ] rooms - [ ] compression ## Protocol - see `protocol.h` for more info -- [ ] make sections per message -- request chat logs from a certain point up to now (history) -- connect to a specific room - The null terminator must be sent with the string. - The text can be arbitrary length -## Arena's -1. There is an arena for the messages' texts (`msgTextArena`) and an arena for the messages - (`msgsArena`). -2. The `Message.text` pointer will point to a text buffer entry in `msgTextArena` -3. Good way to do this, if you have message `M`. -```c -M.text = ArenaPush(msgTextArena, M.text_len); -``` -Notice, that this depends on knowing the text's length before allocating the memory. - -## Strings -- the length of a string (eg. `Message.text_len`) always **excludes** the null terminator unless stated explicitly -- the `#define *_LEN` are the max length **including** the null terminator - ## Keybinds - `Ctrl+C` | `Ctrl+D`: quits - `Ctrl+U`: Erase input line diff --git a/archived.md b/archived.md new file mode 100644 index 0000000..7895224 --- /dev/null +++ b/archived.md @@ -0,0 +1,27 @@ +## Client +- [x] prompt +- [x] sending message +- [x] bug: do not allow sending empty message +- [x] wrapping messages +- [x] bug: when sending message after diconnect (serverfd?) +- [x] Handle disconnection thiin a thread, the best way would be +- [x] Add limit_y to printf_wrap +- [x] id2string on clients +- [x] ctrl+z to suspend +- [x] bug: when reconnecting nrecv != -1 +- [x] bug: when disconnecting +- [x] use error type success to say that authentication succeeded + +## Server +- [x] import clients + +## Common +- [x] handle messages that are too large +- [x] refactor i&self into conn +- [x] logging +- [x] Req|Inf connection per client +- [x] connect/disconnect messages +- [x] bug: blocking after `Added pollfd`, after importing a client and then connecting with the + id/or without? After reconnection fails chatty blocks (remove sleep) +- [x] connect/disconnections messages +- [x] asserting, logging if fail / halt execution @@ -18,7 +18,7 @@ main(int argc, char** argv) return 1; } - s32 err, serverfd, nsend, nrecv; + s32 err, serverfd; serverfd = socket(AF_INET, SOCK_STREAM, 0); assert(serverfd != -1); @@ -38,17 +38,15 @@ main(int argc, char** argv) HeaderMessage header = HEADER_INIT(HEADER_TYPE_INTRODUCTION); IntroductionMessage message; memcpy(message.author, argv[1], author_len); - nsend = send(serverfd, &header, sizeof(header), 0); - assert(nsend != -1); - nsend = send(serverfd, &message, sizeof(message), 0); + s32 nsend = sendAnyMessage(serverfd, header, &message); assert(nsend != -1); // Get id - nrecv = recv(serverfd, &header, sizeof(header), 0); + IDMessage id_message; + s32 nrecv = recvAnyMessageType(serverfd, &header, &id_message, HEADER_TYPE_ID); assert(nrecv != -1); - assert(header.type == HEADER_TYPE_ID); - id = header.id; - fprintf(stderr, "Got id: %lu\n", header.id); + fprintf(stderr, "Got id: %lu\n", id_message.id); + id = id_message.id; } // convert text to wide string @@ -64,7 +62,7 @@ main(int argc, char** argv) bzero(&message, TEXTMESSAGE_SIZE); message = (TextMessage){.timestamp = time(NULL), .len = text_len}; - nsend = send(serverfd, &header, sizeof(header), 0); + s32 nsend = send(serverfd, &header, sizeof(header), 0); assert(nsend != -1); fprintf(stderr, "header bytes sent: %d\n", nsend); @@ -471,7 +471,11 @@ main(int argc, char** argv) client = authenticate(&clientsArena, clients_file, fds + conn, header); if (!client) + { loggingf("Could not initialize client (%d)\n", fds[conn].fd); + close(fds[conn].fd); + fds[conn].fd = -1; + } /* This is the first time a message is sent, because unifd is not yet set. */ else if (!client->unifd) { |