diff --git a/faith-client/.gitignore b/faith-client/.gitignore new file mode 100644 index 0000000..ad668dc --- /dev/null +++ b/faith-client/.gitignore @@ -0,0 +1,4 @@ +build/ +nob +.cache/ +compile_commands.json diff --git a/faithd/src/client/client.h b/faith-client/include/faith-client/client.h similarity index 97% rename from faithd/src/client/client.h rename to faith-client/include/faith-client/client.h index 5a1028e..2190142 100644 --- a/faithd/src/client/client.h +++ b/faith-client/include/faith-client/client.h @@ -2,8 +2,8 @@ #include -#include "../auth/structs.h" -#include "../core/core.h" +#include +#include #define FAITH_CLIENT_COMMAND_TIMEOUT 10000 // 10 seconds diff --git a/faith-client/nob.c b/faith-client/nob.c new file mode 100644 index 0000000..3b66a16 --- /dev/null +++ b/faith-client/nob.c @@ -0,0 +1,255 @@ +#include + +#define NOBDEF static inline +#define NOB_IMPLEMENTATION +#define NOB_EXPERIMENTAL_DELETE_OLD +#define NOB_WARN_DEPRECATED +#define NOB_STRIP_PREFIX +#include "../third_party/third_party/nob.h" + +#define command(arg, commands, name, signature, description) \ + command_loc(__FILE__, __LINE__, (arg), (commands), (name), (signature), \ + (description)) + +#define BUILD_FOLDER "./build/" +#define OBJECT_FOLDER BUILD_FOLDER "obj/" +#define OUTPUT_LIBRARY BUILD_FOLDER "libfaith_client.a" + +#define FAITH_PROTO_ROOT "../faith-proto/" +#define FAITH_PROTO_INCLUDE FAITH_PROTO_ROOT "include" +#define FAITH_PROTO_LIBRARY FAITH_PROTO_ROOT "build/libfaith_proto.a" +#define FAITH_PROTO_HEADER FAITH_PROTO_INCLUDE "/faith-proto/codec/codec.h" + +typedef struct { + const char *name; + const char *signature; + const char *description; +} Command; + +typedef struct { + Command *items; + size_t count; + size_t capacity; + + bool picked; + const char *picked_name; + const char *picked_at_file; + int picked_at_line; +} Commands; + +void commands_reset(Commands *commands) { + commands->count = 0; + commands->picked = false; +} + +void print_available_commands(Commands commands) { + size_t max_name_width = 0; + size_t max_sign_width = 0; + + da_foreach(Command, command, &commands) { + size_t name_width = strlen(command->name); + size_t sign_width = strlen(command->signature); + + if (name_width > max_name_width) + max_name_width = name_width; + + if (sign_width > max_sign_width) + max_sign_width = sign_width; + } + + nob_log(INFO, "Available commands:"); + + da_foreach(Command, command, &commands) { + nob_log(INFO, " %-*s %-*s - %s", (int)max_name_width, command->name, + (int)max_sign_width, command->signature, command->description); + } +} + +bool command_loc(const char *file, int line, const char *arg, + Commands *commands, const char *name, const char *signature, + const char *description) { + if (commands->picked) { + fprintf( + stderr, + "%s:%d: ASSERTION FAILED: the branch for command `%s` fell through.\n", + commands->picked_at_file, commands->picked_at_line, + commands->picked_name); + + fprintf(stderr, + "%s:%d: NOTE: the execution proceeded to here, but the command was " + "already picked.\n", + file, line); + + abort(); + } + + Command command = { + .name = name, + .signature = signature, + .description = description, + }; + + da_append(commands, command); + + commands->picked_name = name; + commands->picked_at_line = line; + commands->picked_at_file = file; + commands->picked = strcmp(arg, name) == 0; + + return commands->picked; +} + +static const char *faith_client_sources[] = { + "src/client.c", +}; + +static const char *faith_client_objects[] = { + OBJECT_FOLDER "client.o", +}; + +static bool compile_source_async(Procs *procs, const char *source, + const char *object) { + Cmd cmd = {0}; + + nob_cc(&cmd); + nob_cc_flags(&cmd); + +#ifndef _WIN32 + nob_cmd_append(&cmd, "-fPIC"); +#endif + + nob_cmd_append(&cmd, "-Iinclude", "-I../third_party/", "-I"FAITH_PROTO_INCLUDE, "-c", source, + "-o", object); + + if (!nob_cmd_run(&cmd, .async = procs, .max_procs = 0)) { + nob_cmd_free(cmd); + return false; + } + + nob_cmd_free(cmd); + return true; +} + +static bool archive_static_library(void) { + Cmd cmd = {0}; + bool result = false; + + if (nob_file_exists(OUTPUT_LIBRARY)) { + if (!nob_delete_file(OUTPUT_LIBRARY)) { + nob_log(ERROR, "Could not remove old library: %s", OUTPUT_LIBRARY); + goto cleanup; + } + } + + nob_cmd_append(&cmd, "ar", "rcs", OUTPUT_LIBRARY); + + for (size_t i = 0; i < NOB_ARRAY_LEN(faith_client_objects); ++i) + nob_cmd_append(&cmd, faith_client_objects[i]); + + if (!nob_cmd_run(&cmd)) + goto cleanup; + + nob_log(INFO, "Built %s", OUTPUT_LIBRARY); + result = true; + +cleanup: + nob_cmd_free(cmd); + return result; +} + +bool build(void) { + Procs procs = {0}; + bool result = false; + + _Static_assert( + NOB_ARRAY_LEN(faith_client_sources) == + NOB_ARRAY_LEN(faith_client_objects), + "faith-client source/object count mismatch"); + + if (!nob_file_exists(FAITH_PROTO_LIBRARY)) { + nob_log(ERROR, "Required library is missing: %s", FAITH_PROTO_LIBRARY); + goto cleanup; + } + + if (!nob_file_exists(FAITH_PROTO_HEADER)) { + nob_log(ERROR, "Required protocol header is missing: %s", + FAITH_PROTO_HEADER); + goto cleanup; + } + + if (!nob_file_exists("include/faith-client/client.h")) { + nob_log(ERROR, "Required client header is missing: %s", + "include/faith-client/client.h"); + goto cleanup; + } + + if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) + goto cleanup; + + if (!nob_mkdir_if_not_exists(OBJECT_FOLDER)) + goto cleanup; + + for (size_t i = 0; i < NOB_ARRAY_LEN(faith_client_sources); ++i) { + if (!compile_source_async(&procs, faith_client_sources[i], + faith_client_objects[i])) + goto cleanup; + } + + if (!nob_procs_flush(&procs)) + goto cleanup; + + if (!archive_static_library()) + goto cleanup; + + result = true; + +cleanup: + if (procs.count > 0 && !nob_procs_flush(&procs)) + result = false; + + nob_da_free(procs); + + return result; +} + + +int main(int argc, char **argv) { +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif + + GO_REBUILD_URSELF_PLUS(argc, argv, "../third_party/third_party/nob.h"); + + set_log_handler(cancer_log_handler); + + const char *program_name = shift(argv, argc); + const char *command_name = "build"; + + (void)program_name; + + if (argc > 0) + command_name = shift(argv, argc); + + Commands commands = {0}; + + commands_reset(&commands); + + if (command(command_name, &commands, "build", "", + "Build the native Faith client library")) { + bool result = build(); + nob_da_free(commands); + return result ? 0 : 1; + } + if (command(command_name, &commands, "help", "", "Print this help message")) { + print_available_commands(commands); + nob_da_free(commands); + return 0; + } + + print_available_commands(commands); + nob_log(ERROR, "Unknown command %s", command_name); + + nob_da_free(commands); + + return 1; +} diff --git a/faithd/src/client/client.c b/faith-client/src/client.c similarity index 99% rename from faithd/src/client/client.c rename to faith-client/src/client.c index 2ae1eaf..c7c12dc 100644 --- a/faithd/src/client/client.c +++ b/faith-client/src/client.c @@ -1,4 +1,4 @@ -#include "client.h" +#include #include #include #include @@ -22,20 +22,20 @@ #include #define STB_DS_IMPLEMENTATION -#include "../../third_party/stb_ds.h" +#include #define NOB_IMPLEMENTATION -#include "../../third_party/nob.h" +#include -#include "../auth/envelopes.h" -#include "../codec/msg.h" -#include "../codec/protocol.h" -#include "../codec/signatures.h" -#include "../server/envelopes.h" +#include +#include +#include +#include +#include #define MAX_QUEUED_EVENTS 512 -static int g_log_enable_tracing = true; +static bool g_log_enable_tracing = true; typedef atomic_uint_fast64_t client_request_id_t; @@ -1957,7 +1957,7 @@ static int read_identity(const char *path, client_side_identity_t *ident) { return 1; } -#define READ_IDENT "ident/e5dbc4ceaab6baee77881c9eb5307a68.bin" +//#define READ_IDENT "ident/c6923af794ef6aa62012539a4ec45d26.bin" static faith_status_code_t client_new_identity(client_side_identity_t *o_ident) { if (!o_ident) diff --git a/faith-client/test/nob.c b/faith-client/test/nob.c new file mode 100644 index 0000000..cbf66ca --- /dev/null +++ b/faith-client/test/nob.c @@ -0,0 +1,229 @@ +#include + +#define NOBDEF static inline +#define NOB_IMPLEMENTATION +#define NOB_EXPERIMENTAL_DELETE_OLD +#define NOB_WARN_DEPRECATED +#define NOB_STRIP_PREFIX +#include "../../third_party/third_party/nob.h" + +#define command(arg, commands, name, signature, description) \ + command_loc(__FILE__, __LINE__, (arg), (commands), (name), (signature), \ + (description)) + +#define BUILD_FOLDER "./build/" +#define OBJECT_FOLDER BUILD_FOLDER "obj/" + +#define TEST_SOURCE "tui.c" +#define TEST_OBJECT OBJECT_FOLDER "tui.o" +#define TEST_EXECUTABLE BUILD_FOLDER "faith-tui" + +#define FAITH_CLIENT_INCLUDE "../include" +#define FAITH_CLIENT_HEADER \ + FAITH_CLIENT_INCLUDE "/faith-client/client.h" +#define FAITH_CLIENT_LIBRARY "../build/libfaith_client.a" + +#define FAITH_PROTO_INCLUDE "../../faith-proto/include" +#define FAITH_PROTO_HEADER \ + FAITH_PROTO_INCLUDE "/faith-proto/codec/codec.h" +#define FAITH_PROTO_LIBRARY "../../faith-proto/build/libfaith_proto.a" + +typedef struct { + const char *name; + const char *signature; + const char *description; +} Command; + +typedef struct { + Command *items; + size_t count; + size_t capacity; + + bool picked; + const char *picked_name; + const char *picked_at_file; + int picked_at_line; +} Commands; + +void commands_reset(Commands *commands) { + commands->count = 0; + commands->picked = false; +} + +void print_available_commands(Commands commands) { + size_t max_name_width = 0; + size_t max_sign_width = 0; + + da_foreach(Command, command, &commands) { + size_t name_width = strlen(command->name); + size_t sign_width = strlen(command->signature); + + if (name_width > max_name_width) + max_name_width = name_width; + + if (sign_width > max_sign_width) + max_sign_width = sign_width; + } + + nob_log(INFO, "Available commands:"); + + da_foreach(Command, command, &commands) { + nob_log(INFO, " %-*s %-*s - %s", (int)max_name_width, command->name, + (int)max_sign_width, command->signature, command->description); + } +} + +bool command_loc(const char *file, int line, const char *arg, + Commands *commands, const char *name, const char *signature, + const char *description) { + if (commands->picked) { + fprintf( + stderr, + "%s:%d: ASSERTION FAILED: the branch for command `%s` fell through.\n", + commands->picked_at_file, commands->picked_at_line, + commands->picked_name); + + fprintf(stderr, + "%s:%d: NOTE: the execution proceeded to here, but the command was " + "already picked.\n", + file, line); + + abort(); + } + + Command command = { + .name = name, + .signature = signature, + .description = description, + }; + + da_append(commands, command); + + commands->picked_name = name; + commands->picked_at_line = line; + commands->picked_at_file = file; + commands->picked = strcmp(arg, name) == 0; + + return commands->picked; +} + +static bool required_files_exist(void) { + if (!nob_file_exists(TEST_SOURCE)) { + nob_log(ERROR, "Test source is missing: %s", TEST_SOURCE); + return false; + } + + if (!nob_file_exists(FAITH_CLIENT_HEADER)) { + nob_log(ERROR, "Client header is missing: %s", FAITH_CLIENT_HEADER); + return false; + } + + if (!nob_file_exists(FAITH_CLIENT_LIBRARY)) { + nob_log(ERROR, "Client library is missing: %s", FAITH_CLIENT_LIBRARY); + return false; + } + + if (!nob_file_exists(FAITH_PROTO_HEADER)) { + nob_log(ERROR, "Protocol header is missing: %s", FAITH_PROTO_HEADER); + return false; + } + + if (!nob_file_exists(FAITH_PROTO_LIBRARY)) { + nob_log(ERROR, "Protocol library is missing: %s", FAITH_PROTO_LIBRARY); + return false; + } + + return true; +} + +static bool compile_test(void) { + Cmd cmd = {0}; + + nob_cc(&cmd); + nob_cc_flags(&cmd); + + nob_cmd_append(&cmd, "-I../../third_party/", "-I" FAITH_CLIENT_INCLUDE, + "-I" FAITH_PROTO_INCLUDE, "-c", TEST_SOURCE, "-o", + TEST_OBJECT); + + bool result = nob_cmd_run(&cmd); + nob_cmd_free(cmd); + + return result; +} + +static bool link_test(void) { + Cmd cmd = {0}; + + nob_cc(&cmd); + nob_cc_output(&cmd, TEST_EXECUTABLE); + + nob_cmd_append(&cmd, TEST_OBJECT, FAITH_CLIENT_LIBRARY, FAITH_PROTO_LIBRARY, + "-lssl", "-lcrypto", "-lpthread"); + + bool result = nob_cmd_run(&cmd); + nob_cmd_free(cmd); + + return result; +} + +static bool build(void) { + if (!required_files_exist()) + return false; + + if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) + return false; + + if (!nob_mkdir_if_not_exists(OBJECT_FOLDER)) + return false; + + if (!compile_test()) + return false; + + if (!link_test()) + return false; + + nob_log(INFO, "Built %s", TEST_EXECUTABLE); + + return true; +} + +int main(int argc, char **argv) { +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif + + GO_REBUILD_URSELF_PLUS(argc, argv, "../../third_party/third_party/nob.h"); + + const char *program_name = shift(argv, argc); + const char *command_name = "build"; + + (void)program_name; + + if (argc > 0) + command_name = shift(argv, argc); + + Commands commands = {0}; + + commands_reset(&commands); + + if (command(command_name, &commands, "build", "", + "Build the native client test executable")) { + bool result = build(); + nob_da_free(commands); + return result ? 0 : 1; + } + + if (command(command_name, &commands, "help", "", "Print this help message")) { + print_available_commands(commands); + nob_da_free(commands); + return 0; + } + + print_available_commands(commands); + nob_log(ERROR, "Unknown command %s", command_name); + + nob_da_free(commands); + + return 1; +} diff --git a/faithd/src/test/client_test_suite.c b/faith-client/test/tui.c similarity index 99% rename from faithd/src/test/client_test_suite.c rename to faith-client/test/tui.c index 7fd1915..caa6a52 100644 --- a/faithd/src/test/client_test_suite.c +++ b/faith-client/test/tui.c @@ -1,4 +1,4 @@ -#include "../client/client.h" +#include #include #include diff --git a/faith-proto/.gitignore b/faith-proto/.gitignore new file mode 100644 index 0000000..ad668dc --- /dev/null +++ b/faith-proto/.gitignore @@ -0,0 +1,4 @@ +build/ +nob +.cache/ +compile_commands.json diff --git a/faithd/src/application/conversation.h b/faith-proto/include/faith-proto/codec/application.h similarity index 100% rename from faithd/src/application/conversation.h rename to faith-proto/include/faith-proto/codec/application.h diff --git a/faithd/src/auth/envelopes.h b/faith-proto/include/faith-proto/codec/auth.h similarity index 81% rename from faithd/src/auth/envelopes.h rename to faith-proto/include/faith-proto/codec/auth.h index c35ffa7..5ac53b3 100644 --- a/faithd/src/auth/envelopes.h +++ b/faith-proto/include/faith-proto/codec/auth.h @@ -1,6 +1,24 @@ #pragma once -#include "../codec/envelopes.h" +#include + +#include "../core/crypto.h" + +#define FAITH_AUTH_ID_SIZE 16 +#define FAITH_DEVICE_ID_SIZE 16 + +typedef struct { + uint8_t bytes[FAITH_AUTH_ID_SIZE]; +} faith_auth_id_t; + +typedef struct { + uint8_t bytes[FAITH_DEVICE_ID_SIZE]; +} faith_device_id_t; + +typedef enum { + FAITH_DEVICE_LINK_DENY = 0, + FAITH_DEVICE_LINK_APPROVE = 1, +} faith_device_link_response_type_t; #define FAITH_DEVICE_LINK_CODE_SIZE 16 @@ -58,3 +76,7 @@ typedef struct { // Random nonce generated by the server uint64_t server_nonce; } faith_envl_stc_hello_challenge_t; + + +bool faith_client_id_equal(faith_auth_id_t a, faith_auth_id_t b); +bool faith_device_id_equal(faith_device_id_t a, faith_device_id_t b); diff --git a/faithd/src/codec/protocol.h b/faith-proto/include/faith-proto/codec/codec.h similarity index 98% rename from faithd/src/codec/protocol.h rename to faith-proto/include/faith-proto/codec/codec.h index 90e4aa3..ead31ac 100644 --- a/faithd/src/codec/protocol.h +++ b/faith-proto/include/faith-proto/codec/codec.h @@ -1,14 +1,14 @@ #pragma once -#include "../codec/envelopes.h" -#include "../codec/msg.h" +#include "envelopes.h" +#include "msg.h" #include "../core/core.h" -#include "../auth/envelopes.h" -#include "../server/envelopes.h" +#include "auth.h" +#include "server.h" #include "commands.h" -#include "core.h" +#include "core_types.h" #include "events.h" #include "helpers.h" diff --git a/faithd/src/codec/commands.h b/faith-proto/include/faith-proto/codec/commands.h similarity index 98% rename from faithd/src/codec/commands.h rename to faith-proto/include/faith-proto/codec/commands.h index 08b25cd..1b03fb7 100644 --- a/faithd/src/codec/commands.h +++ b/faith-proto/include/faith-proto/codec/commands.h @@ -2,8 +2,9 @@ #include -#include "../auth/structs.h" -#include "core.h" +#include "auth.h" +#include "core_types.h" +#include "../core/core.h" #define FAITH_COMMAND_ID_SIZE 16 #define FAITH_COMMAND_TYPES(X) X(FAITH_COMMAND_CREATE_CONVERSATION, 0) diff --git a/faithd/src/codec/core.h b/faith-proto/include/faith-proto/codec/core_types.h similarity index 100% rename from faithd/src/codec/core.h rename to faith-proto/include/faith-proto/codec/core_types.h diff --git a/faithd/src/codec/envelopes.h b/faith-proto/include/faith-proto/codec/envelopes.h similarity index 97% rename from faithd/src/codec/envelopes.h rename to faith-proto/include/faith-proto/codec/envelopes.h index c9b1b62..288217d 100644 --- a/faithd/src/codec/envelopes.h +++ b/faith-proto/include/faith-proto/codec/envelopes.h @@ -1,7 +1,7 @@ #pragma once -#include "../auth/structs.h" -#include "core.h" +#include "auth.h" +#include "core_types.h" #include diff --git a/faithd/src/codec/events.h b/faith-proto/include/faith-proto/codec/events.h similarity index 96% rename from faithd/src/codec/events.h rename to faith-proto/include/faith-proto/codec/events.h index 38b2893..d4bea2b 100644 --- a/faithd/src/codec/events.h +++ b/faith-proto/include/faith-proto/codec/events.h @@ -1,8 +1,8 @@ #pragma once -#include "../application/conversation.h" -#include "../auth/structs.h" -#include "core.h" +#include "application.h" +#include "auth.h" +#include "core_types.h" #include "helpers.h" #define FAITH_ENVL_STC_EVENT_BODY_SIZE_FIXED \ diff --git a/faithd/src/codec/helpers.h b/faith-proto/include/faith-proto/codec/helpers.h similarity index 99% rename from faithd/src/codec/helpers.h rename to faith-proto/include/faith-proto/codec/helpers.h index caebd49..633f9b1 100644 --- a/faithd/src/codec/helpers.h +++ b/faith-proto/include/faith-proto/codec/helpers.h @@ -1,6 +1,7 @@ #pragma once #include "../core/core.h" +#include "core_types.h" #include #define _FAITH_BODY_SIZE(X) ((faith_body_size_t)((X))) diff --git a/faithd/src/codec/msg.h b/faith-proto/include/faith-proto/codec/msg.h similarity index 100% rename from faithd/src/codec/msg.h rename to faith-proto/include/faith-proto/codec/msg.h diff --git a/faithd/src/server/envelopes.h b/faith-proto/include/faith-proto/codec/server.h similarity index 100% rename from faithd/src/server/envelopes.h rename to faith-proto/include/faith-proto/codec/server.h diff --git a/faithd/src/codec/signatures.h b/faith-proto/include/faith-proto/codec/signatures.h similarity index 97% rename from faithd/src/codec/signatures.h rename to faith-proto/include/faith-proto/codec/signatures.h index 776d5dd..c01ad9f 100644 --- a/faithd/src/codec/signatures.h +++ b/faith-proto/include/faith-proto/codec/signatures.h @@ -2,8 +2,7 @@ #include "../core/crypto.h" -#include "../auth/device_link.h" -#include "../auth/structs.h" +#include "auth.h" #define FAITH_SIGNATURE_DEVICE_LINK_RESPONSE_SIZE \ (FAITH_AUTH_ID_SIZE /* auth ID */ + \ diff --git a/faithd/src/core/core.h b/faith-proto/include/faith-proto/core/core.h similarity index 99% rename from faithd/src/core/core.h rename to faith-proto/include/faith-proto/core/core.h index 8425a19..c949189 100644 --- a/faithd/src/core/core.h +++ b/faith-proto/include/faith-proto/core/core.h @@ -3,7 +3,7 @@ #include #define NOB_STRIP_PREFIX -#include "../../third_party/nob.h" +#include #define _FH_CHECK_GOTO(expr, result, label) \ do { \ diff --git a/faithd/src/core/crypto.h b/faith-proto/include/faith-proto/core/crypto.h similarity index 100% rename from faithd/src/core/crypto.h rename to faith-proto/include/faith-proto/core/crypto.h diff --git a/faith-proto/nob.c b/faith-proto/nob.c new file mode 100644 index 0000000..f11ccb5 --- /dev/null +++ b/faith-proto/nob.c @@ -0,0 +1,276 @@ +#include + +#define NOBDEF static inline +#define NOB_IMPLEMENTATION +#define NOB_EXPERIMENTAL_DELETE_OLD +#define NOB_WARN_DEPRECATED +#define NOB_STRIP_PREFIX +#include "../third_party/third_party/nob.h" + +#define command(arg, commands, name, signature, description) \ + command_loc(__FILE__, __LINE__, (arg), (commands), (name), (signature), \ + (description)) + +#define BUILD_FOLDER "./build/" +#define OBJECT_FOLDER BUILD_FOLDER "obj/" +#define OUTPUT_LIBRARY BUILD_FOLDER "libfaith_proto.a" + +typedef struct { + const char *name; + const char *signature; + const char *description; +} Command; + +typedef struct { + Command *items; + size_t count; + size_t capacity; + + bool picked; + const char *picked_name; + const char *picked_at_file; + int picked_at_line; +} Commands; + +static const char *faith_proto_sources[] = { + "src/codec/auth.c", + "src/codec/codec.c", + "src/codec/commands.c", + "src/codec/envelopes.c", + "src/codec/events.c", + "src/codec/helpers.c", + "src/codec/msg.c", + "src/codec/signatures.c", + + "src/core/core.c", + "src/core/crypto.c", +}; + +static const char *faith_proto_objects[] = { + OBJECT_FOLDER "codec_auth.o", + OBJECT_FOLDER "codec_codec.o", + OBJECT_FOLDER "codec_commands.o", + OBJECT_FOLDER "codec_envelopes.o", + OBJECT_FOLDER "codec_events.o", + OBJECT_FOLDER "codec_helpers.o", + OBJECT_FOLDER "codec_msg.o", + OBJECT_FOLDER "codec_signatures.o", + + OBJECT_FOLDER "core_core.o", + OBJECT_FOLDER "core_crypto.o", +}; + +static void commands_reset(Commands *commands) { + commands->count = 0; + commands->picked = false; +} + +static void print_available_commands(Commands commands) { + size_t max_name_width = 0; + size_t max_sign_width = 0; + + da_foreach(Command, command, &commands) { + const size_t name_width = strlen(command->name); + const size_t sign_width = strlen(command->signature); + + if (name_width > max_name_width) + max_name_width = name_width; + + if (sign_width > max_sign_width) + max_sign_width = sign_width; + } + + nob_log(INFO, "Available commands:"); + + da_foreach(Command, command, &commands) { + nob_log(INFO, + " %-*s %-*s - %s", + (int)max_name_width, + command->name, + (int)max_sign_width, + command->signature, + command->description); + } +} + +static bool command_loc(const char *file, + int line, + const char *arg, + Commands *commands, + const char *name, + const char *signature, + const char *description) { + if (commands->picked) { + fprintf(stderr, + "%s:%d: ASSERTION FAILED: the branch for command `%s` fell " + "through.\n", + commands->picked_at_file, + commands->picked_at_line, + commands->picked_name); + + fprintf(stderr, + "%s:%d: NOTE: execution proceeded here after a command had " + "already been picked.\n", + file, + line); + + abort(); + } + + const Command cmd = { + .name = name, + .signature = signature, + .description = description, + }; + + da_append(commands, cmd); + + commands->picked_name = name; + commands->picked_at_line = line; + commands->picked_at_file = file; + commands->picked = strcmp(arg, name) == 0; + + return commands->picked; +} + +static bool compile_source_async(Procs *procs, + const char *source, + const char *object) { + Cmd cmd = {0}; + + nob_cc(&cmd); + nob_cc_flags(&cmd); + +#ifndef _WIN32 + nob_cmd_append(&cmd, "-fPIC"); +#endif + + nob_cmd_append(&cmd, + "-I.", + "-Iinclude/faith-proto/", + "-I../third_party/", + "-c", + source, + "-o", + object); + + if (!nob_cmd_run(&cmd, .async = procs, .max_procs = 0)) { + nob_cmd_free(cmd); + return false; + } + + nob_cmd_free(cmd); + return true; +} + +static bool archive_static_library(void) { + Cmd cmd = {0}; + bool result = false; + + if (nob_file_exists(OUTPUT_LIBRARY)) { + if (!nob_delete_file(OUTPUT_LIBRARY)) { + nob_log(ERROR, "Could not remove old library %s", OUTPUT_LIBRARY); + goto cleanup; + } + } + + nob_cmd_append(&cmd, "ar", "rcs", OUTPUT_LIBRARY); + + for (size_t i = 0; i < NOB_ARRAY_LEN(faith_proto_objects); ++i) + nob_cmd_append(&cmd, faith_proto_objects[i]); + + if (!nob_cmd_run(&cmd)) + goto cleanup; + + nob_log(INFO, "Built %s", OUTPUT_LIBRARY); + result = true; + +cleanup: + nob_cmd_free(cmd); + return result; +} + +static bool build(void) { + Procs procs = {0}; + bool result = false; + + _Static_assert( + NOB_ARRAY_LEN(faith_proto_sources) == + NOB_ARRAY_LEN(faith_proto_objects), + "faith-proto source/object count mismatch"); + + if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) + goto cleanup; + + if (!nob_mkdir_if_not_exists(OBJECT_FOLDER)) + goto cleanup; + + for (size_t i = 0; i < NOB_ARRAY_LEN(faith_proto_sources); ++i) { + if (!compile_source_async( + &procs, + faith_proto_sources[i], + faith_proto_objects[i])) { + goto cleanup; + } + } + + if (!nob_procs_flush(&procs)) + goto cleanup; + + if (!archive_static_library()) + goto cleanup; + + result = true; + +cleanup: + if (procs.count > 0 && !nob_procs_flush(&procs)) + result = false; + + nob_da_free(procs); + return result; +} + +int main(int argc, char **argv) { +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif + + GO_REBUILD_URSELF_PLUS(argc, argv, "../third_party/third_party/nob.h"); + + const char *program_name = shift(argv, argc); + (void)program_name; + + const char *command_name = "build"; + + if (argc > 0) + command_name = shift(argv, argc); + + Commands commands = {0}; + commands_reset(&commands); + + if (command(command_name, + &commands, + "build", + "", + "Build the static faith protocol library")) { + const bool ok = build(); + nob_da_free(commands); + return ok ? 0 : 1; + } + + if (command(command_name, + &commands, + "help", + "", + "Print this help message")) { + print_available_commands(commands); + nob_da_free(commands); + return 0; + } + + print_available_commands(commands); + nob_log(ERROR, "Unknown command %s", command_name); + + nob_da_free(commands); + return 1; +} diff --git a/faithd/src/auth/structs.c b/faith-proto/src/codec/auth.c similarity index 90% rename from faithd/src/auth/structs.c rename to faith-proto/src/codec/auth.c index 818a184..96bc0c1 100644 --- a/faithd/src/auth/structs.c +++ b/faith-proto/src/codec/auth.c @@ -1,4 +1,4 @@ -#include "structs.h" +#include "codec/auth.h" bool faith_client_id_equal(faith_auth_id_t a, faith_auth_id_t b) { return memcmp(a.bytes, b.bytes, 16) == 0; @@ -7,3 +7,4 @@ bool faith_client_id_equal(faith_auth_id_t a, faith_auth_id_t b) { bool faith_device_id_equal(faith_device_id_t a, faith_device_id_t b) { return memcmp(a.bytes, b.bytes, 16) == 0; } + diff --git a/faithd/src/codec/protocol.c b/faith-proto/src/codec/codec.c similarity index 99% rename from faithd/src/codec/protocol.c rename to faith-proto/src/codec/codec.c index 2439eac..dcb7a5c 100644 --- a/faithd/src/codec/protocol.c +++ b/faith-proto/src/codec/codec.c @@ -1,11 +1,10 @@ -#include "protocol.h" +#include "codec/codec.h" -#include "../../third_party/nob.h" -#include "../../third_party/stb_ds.h" +#include -#include "core.h" -#include "events.h" -#include "helpers.h" +#include "codec/core_types.h" +#include "codec/events.h" +#include "codec/helpers.h" #define _MODULE_NAME "codec/protocol" diff --git a/faithd/src/codec/commands.c b/faith-proto/src/codec/commands.c similarity index 97% rename from faithd/src/codec/commands.c rename to faith-proto/src/codec/commands.c index b36f74a..328b9e3 100644 --- a/faithd/src/codec/commands.c +++ b/faith-proto/src/codec/commands.c @@ -1,6 +1,6 @@ -#include "commands.h" +#include "codec/commands.h" -#include "helpers.h" +#include "codec/helpers.h" faith_status_code_t faith_encode_cmd_create_conversation( uint8_t *out_buf, faith_body_size_t *out_size, size_t buf_cap_in_bytes, diff --git a/faithd/src/codec/envelopes.c b/faith-proto/src/codec/envelopes.c similarity index 92% rename from faithd/src/codec/envelopes.c rename to faith-proto/src/codec/envelopes.c index e28ce11..9297406 100644 --- a/faithd/src/codec/envelopes.c +++ b/faith-proto/src/codec/envelopes.c @@ -1,4 +1,4 @@ -#include "envelopes.h" +#include "codec/envelopes.h" const char *faith_envelope_name(faith_envelope_type_t env) { switch (env) { diff --git a/faithd/src/codec/events.c b/faith-proto/src/codec/events.c similarity index 98% rename from faithd/src/codec/events.c rename to faith-proto/src/codec/events.c index 97298b0..7fd2acc 100644 --- a/faithd/src/codec/events.c +++ b/faith-proto/src/codec/events.c @@ -1,4 +1,4 @@ -#include "events.h" +#include "codec/events.h" faith_status_code_t faith_encode_event_conversation_created( uint8_t *out_buf, faith_body_size_t *out_size, size_t buf_cap_in_bytes, diff --git a/faithd/src/codec/helpers.c b/faith-proto/src/codec/helpers.c similarity index 98% rename from faithd/src/codec/helpers.c rename to faith-proto/src/codec/helpers.c index ae872f9..5396b6c 100644 --- a/faithd/src/codec/helpers.c +++ b/faith-proto/src/codec/helpers.c @@ -1,4 +1,4 @@ -#include "helpers.h" +#include "codec/helpers.h" #include diff --git a/faithd/src/codec/msg.c b/faith-proto/src/codec/msg.c similarity index 93% rename from faithd/src/codec/msg.c rename to faith-proto/src/codec/msg.c index da9af2a..6cbad07 100644 --- a/faithd/src/codec/msg.c +++ b/faith-proto/src/codec/msg.c @@ -1,4 +1,4 @@ -#include "msg.h" +#include "codec/msg.h" const char *faith_frame_msg_name(faith_frame_msg_type_t msg) { switch (msg) { diff --git a/faithd/src/codec/signatures.c b/faith-proto/src/codec/signatures.c similarity index 97% rename from faithd/src/codec/signatures.c rename to faith-proto/src/codec/signatures.c index 325c0c3..589f2b1 100644 --- a/faithd/src/codec/signatures.c +++ b/faith-proto/src/codec/signatures.c @@ -1,6 +1,6 @@ -#include "signatures.h" +#include "codec/signatures.h" -#include "helpers.h" +#include "codec/helpers.h" faith_status_code_t faith_gen_sign_buf_hello_handshake( uint8_t *out_buf, size_t *out_size, size_t buf_cap_in_bytes, diff --git a/faithd/src/core/core.c b/faith-proto/src/core/core.c similarity index 99% rename from faithd/src/core/core.c rename to faith-proto/src/core/core.c index 2211579..dabbfae 100644 --- a/faithd/src/core/core.c +++ b/faith-proto/src/core/core.c @@ -1,4 +1,4 @@ -#include "core.h" +#include "core/core.h" #include #include diff --git a/faithd/src/core/crypto.c b/faith-proto/src/core/crypto.c similarity index 99% rename from faithd/src/core/crypto.c rename to faith-proto/src/core/crypto.c index a3fee71..e30f020 100644 --- a/faithd/src/core/crypto.c +++ b/faith-proto/src/core/crypto.c @@ -1,4 +1,4 @@ -#include "crypto.h" +#include "core/crypto.h" #include #include diff --git a/faith-server/.cache/clangd/index/client_io.c.8C2D040904B1271A.idx b/faith-server/.cache/clangd/index/client_io.c.8C2D040904B1271A.idx new file mode 100644 index 0000000..5eacaf8 Binary files /dev/null and b/faith-server/.cache/clangd/index/client_io.c.8C2D040904B1271A.idx differ diff --git a/faith-server/.cache/clangd/index/client_io.h.02B6A8499A7E62C3.idx b/faith-server/.cache/clangd/index/client_io.h.02B6A8499A7E62C3.idx new file mode 100644 index 0000000..47ef1b6 Binary files /dev/null and b/faith-server/.cache/clangd/index/client_io.h.02B6A8499A7E62C3.idx differ diff --git a/faith-server/.cache/clangd/index/client_lifecycle.c.AB824C4EC105D87F.idx b/faith-server/.cache/clangd/index/client_lifecycle.c.AB824C4EC105D87F.idx new file mode 100644 index 0000000..93c2a16 Binary files /dev/null and b/faith-server/.cache/clangd/index/client_lifecycle.c.AB824C4EC105D87F.idx differ diff --git a/faith-server/.cache/clangd/index/client_lifecycle.h.280ED39EEEE6D916.idx b/faith-server/.cache/clangd/index/client_lifecycle.h.280ED39EEEE6D916.idx new file mode 100644 index 0000000..209a1a0 Binary files /dev/null and b/faith-server/.cache/clangd/index/client_lifecycle.h.280ED39EEEE6D916.idx differ diff --git a/faith-server/.cache/clangd/index/conn.c.286E7B4DB3D17795.idx b/faith-server/.cache/clangd/index/conn.c.286E7B4DB3D17795.idx new file mode 100644 index 0000000..287b507 Binary files /dev/null and b/faith-server/.cache/clangd/index/conn.c.286E7B4DB3D17795.idx differ diff --git a/faith-server/.cache/clangd/index/conn.h.5B957B46D88BFFFE.idx b/faith-server/.cache/clangd/index/conn.h.5B957B46D88BFFFE.idx new file mode 100644 index 0000000..ba15d5f Binary files /dev/null and b/faith-server/.cache/clangd/index/conn.h.5B957B46D88BFFFE.idx differ diff --git a/faith-server/.cache/clangd/index/conversation.c.9D5FE9B9ECB56104.idx b/faith-server/.cache/clangd/index/conversation.c.9D5FE9B9ECB56104.idx new file mode 100644 index 0000000..5873b6c Binary files /dev/null and b/faith-server/.cache/clangd/index/conversation.c.9D5FE9B9ECB56104.idx differ diff --git a/faith-server/.cache/clangd/index/conversation.h.CA8AEBC729A90768.idx b/faith-server/.cache/clangd/index/conversation.h.CA8AEBC729A90768.idx new file mode 100644 index 0000000..749b146 Binary files /dev/null and b/faith-server/.cache/clangd/index/conversation.h.CA8AEBC729A90768.idx differ diff --git a/faith-server/.cache/clangd/index/device_link.c.D1E762ACED786DDA.idx b/faith-server/.cache/clangd/index/device_link.c.D1E762ACED786DDA.idx new file mode 100644 index 0000000..bdb578a Binary files /dev/null and b/faith-server/.cache/clangd/index/device_link.c.D1E762ACED786DDA.idx differ diff --git a/faith-server/.cache/clangd/index/device_link.h.22C5EBE709AB0D7E.idx b/faith-server/.cache/clangd/index/device_link.h.22C5EBE709AB0D7E.idx new file mode 100644 index 0000000..06926d0 Binary files /dev/null and b/faith-server/.cache/clangd/index/device_link.h.22C5EBE709AB0D7E.idx differ diff --git a/faith-server/.cache/clangd/index/dispatch.c.3F46910E43D46093.idx b/faith-server/.cache/clangd/index/dispatch.c.3F46910E43D46093.idx new file mode 100644 index 0000000..5ff90c3 Binary files /dev/null and b/faith-server/.cache/clangd/index/dispatch.c.3F46910E43D46093.idx differ diff --git a/faith-server/.cache/clangd/index/dispatch.c.62F9B44B4E07CE38.idx b/faith-server/.cache/clangd/index/dispatch.c.62F9B44B4E07CE38.idx new file mode 100644 index 0000000..a440897 Binary files /dev/null and b/faith-server/.cache/clangd/index/dispatch.c.62F9B44B4E07CE38.idx differ diff --git a/faith-server/.cache/clangd/index/dispatch.h.2F9F87B70FC609EE.idx b/faith-server/.cache/clangd/index/dispatch.h.2F9F87B70FC609EE.idx new file mode 100644 index 0000000..151cd86 Binary files /dev/null and b/faith-server/.cache/clangd/index/dispatch.h.2F9F87B70FC609EE.idx differ diff --git a/faith-server/.cache/clangd/index/dispatch.h.FD8C25C3BCFF72D4.idx b/faith-server/.cache/clangd/index/dispatch.h.FD8C25C3BCFF72D4.idx new file mode 100644 index 0000000..7f2f5e7 Binary files /dev/null and b/faith-server/.cache/clangd/index/dispatch.h.FD8C25C3BCFF72D4.idx differ diff --git a/faith-server/.cache/clangd/index/envelopes.h.436F9D61FC5EFB78.idx b/faith-server/.cache/clangd/index/envelopes.h.436F9D61FC5EFB78.idx new file mode 100644 index 0000000..87a4c4e Binary files /dev/null and b/faith-server/.cache/clangd/index/envelopes.h.436F9D61FC5EFB78.idx differ diff --git a/faith-server/.cache/clangd/index/event_inbox.c.14FF782EECCF5E8E.idx b/faith-server/.cache/clangd/index/event_inbox.c.14FF782EECCF5E8E.idx new file mode 100644 index 0000000..5b3ba89 Binary files /dev/null and b/faith-server/.cache/clangd/index/event_inbox.c.14FF782EECCF5E8E.idx differ diff --git a/faith-server/.cache/clangd/index/event_inbox.h.D41BD20F8085C3D1.idx b/faith-server/.cache/clangd/index/event_inbox.h.D41BD20F8085C3D1.idx new file mode 100644 index 0000000..e8cb797 Binary files /dev/null and b/faith-server/.cache/clangd/index/event_inbox.h.D41BD20F8085C3D1.idx differ diff --git a/faith-server/.cache/clangd/index/events.c.14865C6D9A01D9DB.idx b/faith-server/.cache/clangd/index/events.c.14865C6D9A01D9DB.idx new file mode 100644 index 0000000..ecee3c7 Binary files /dev/null and b/faith-server/.cache/clangd/index/events.c.14865C6D9A01D9DB.idx differ diff --git a/faith-server/.cache/clangd/index/events.h.CFA4CC35D07DB522.idx b/faith-server/.cache/clangd/index/events.h.CFA4CC35D07DB522.idx new file mode 100644 index 0000000..661de2f Binary files /dev/null and b/faith-server/.cache/clangd/index/events.h.CFA4CC35D07DB522.idx differ diff --git a/faith-server/.cache/clangd/index/faithd.c.6F79CE9E9CA84501.idx b/faith-server/.cache/clangd/index/faithd.c.6F79CE9E9CA84501.idx new file mode 100644 index 0000000..3b938ce Binary files /dev/null and b/faith-server/.cache/clangd/index/faithd.c.6F79CE9E9CA84501.idx differ diff --git a/faith-server/.cache/clangd/index/frame.c.C80373E52C9BB8D2.idx b/faith-server/.cache/clangd/index/frame.c.C80373E52C9BB8D2.idx new file mode 100644 index 0000000..5cebed7 Binary files /dev/null and b/faith-server/.cache/clangd/index/frame.c.C80373E52C9BB8D2.idx differ diff --git a/faith-server/.cache/clangd/index/frame.h.65765AAFBD5799C5.idx b/faith-server/.cache/clangd/index/frame.h.65765AAFBD5799C5.idx new file mode 100644 index 0000000..af48197 Binary files /dev/null and b/faith-server/.cache/clangd/index/frame.h.65765AAFBD5799C5.idx differ diff --git a/faith-server/.cache/clangd/index/handshake.c.D817BD515F58D030.idx b/faith-server/.cache/clangd/index/handshake.c.D817BD515F58D030.idx new file mode 100644 index 0000000..09e9cab Binary files /dev/null and b/faith-server/.cache/clangd/index/handshake.c.D817BD515F58D030.idx differ diff --git a/faith-server/.cache/clangd/index/handshake.h.A3CA9501DDF10B53.idx b/faith-server/.cache/clangd/index/handshake.h.A3CA9501DDF10B53.idx new file mode 100644 index 0000000..861c15d Binary files /dev/null and b/faith-server/.cache/clangd/index/handshake.h.A3CA9501DDF10B53.idx differ diff --git a/faith-server/.cache/clangd/index/helpers.h.0A0CA671275D72A7.idx b/faith-server/.cache/clangd/index/helpers.h.0A0CA671275D72A7.idx new file mode 100644 index 0000000..f4a32eb Binary files /dev/null and b/faith-server/.cache/clangd/index/helpers.h.0A0CA671275D72A7.idx differ diff --git a/faith-server/.cache/clangd/index/logging.c.CC1D02F5F22FC37C.idx b/faith-server/.cache/clangd/index/logging.c.CC1D02F5F22FC37C.idx new file mode 100644 index 0000000..acaa70d Binary files /dev/null and b/faith-server/.cache/clangd/index/logging.c.CC1D02F5F22FC37C.idx differ diff --git a/faith-server/.cache/clangd/index/logging.h.8637C57BCD33C9F5.idx b/faith-server/.cache/clangd/index/logging.h.8637C57BCD33C9F5.idx new file mode 100644 index 0000000..df1f8f7 Binary files /dev/null and b/faith-server/.cache/clangd/index/logging.h.8637C57BCD33C9F5.idx differ diff --git a/faith-server/.cache/clangd/index/nob.h.6412967F74601D00.idx b/faith-server/.cache/clangd/index/nob.h.6412967F74601D00.idx new file mode 100644 index 0000000..2852eef Binary files /dev/null and b/faith-server/.cache/clangd/index/nob.h.6412967F74601D00.idx differ diff --git a/faith-server/.cache/clangd/index/reactor.c.3515F166852BDD2E.idx b/faith-server/.cache/clangd/index/reactor.c.3515F166852BDD2E.idx new file mode 100644 index 0000000..5674dbf Binary files /dev/null and b/faith-server/.cache/clangd/index/reactor.c.3515F166852BDD2E.idx differ diff --git a/faith-server/.cache/clangd/index/reactor.h.87443FCCBE09285A.idx b/faith-server/.cache/clangd/index/reactor.h.87443FCCBE09285A.idx new file mode 100644 index 0000000..2cdd0fa Binary files /dev/null and b/faith-server/.cache/clangd/index/reactor.h.87443FCCBE09285A.idx differ diff --git a/faith-server/.cache/clangd/index/routing.c.E27785336B8F53E8.idx b/faith-server/.cache/clangd/index/routing.c.E27785336B8F53E8.idx new file mode 100644 index 0000000..f88d828 Binary files /dev/null and b/faith-server/.cache/clangd/index/routing.c.E27785336B8F53E8.idx differ diff --git a/faith-server/.cache/clangd/index/routing.h.60EB94C2BAE0BA8C.idx b/faith-server/.cache/clangd/index/routing.h.60EB94C2BAE0BA8C.idx new file mode 100644 index 0000000..d472810 Binary files /dev/null and b/faith-server/.cache/clangd/index/routing.h.60EB94C2BAE0BA8C.idx differ diff --git a/faith-server/.cache/clangd/index/server.c.65834361912DC0E7.idx b/faith-server/.cache/clangd/index/server.c.65834361912DC0E7.idx new file mode 100644 index 0000000..6dde3b5 Binary files /dev/null and b/faith-server/.cache/clangd/index/server.c.65834361912DC0E7.idx differ diff --git a/faith-server/.cache/clangd/index/server.h.9B962C063EC7D2A2.idx b/faith-server/.cache/clangd/index/server.h.9B962C063EC7D2A2.idx new file mode 100644 index 0000000..8892c19 Binary files /dev/null and b/faith-server/.cache/clangd/index/server.h.9B962C063EC7D2A2.idx differ diff --git a/faith-server/.cache/clangd/index/sess_registry.c.9D0B46F1EA937F9A.idx b/faith-server/.cache/clangd/index/sess_registry.c.9D0B46F1EA937F9A.idx new file mode 100644 index 0000000..e6c8d78 Binary files /dev/null and b/faith-server/.cache/clangd/index/sess_registry.c.9D0B46F1EA937F9A.idx differ diff --git a/faith-server/.cache/clangd/index/sess_registry.h.F5B121E6DD5BAABC.idx b/faith-server/.cache/clangd/index/sess_registry.h.F5B121E6DD5BAABC.idx new file mode 100644 index 0000000..a79d669 Binary files /dev/null and b/faith-server/.cache/clangd/index/sess_registry.h.F5B121E6DD5BAABC.idx differ diff --git a/faith-server/.cache/clangd/index/stb_ds.h.D3BDF2CD136698C1.idx b/faith-server/.cache/clangd/index/stb_ds.h.D3BDF2CD136698C1.idx new file mode 100644 index 0000000..ce5bc4a Binary files /dev/null and b/faith-server/.cache/clangd/index/stb_ds.h.D3BDF2CD136698C1.idx differ diff --git a/faith-server/.cache/clangd/index/tls.c.DD6BA93D6A5579FE.idx b/faith-server/.cache/clangd/index/tls.c.DD6BA93D6A5579FE.idx new file mode 100644 index 0000000..190837d Binary files /dev/null and b/faith-server/.cache/clangd/index/tls.c.DD6BA93D6A5579FE.idx differ diff --git a/faith-server/.cache/clangd/index/tls.h.6C3692A6EC4A764A.idx b/faith-server/.cache/clangd/index/tls.h.6C3692A6EC4A764A.idx new file mode 100644 index 0000000..cc1cdb0 Binary files /dev/null and b/faith-server/.cache/clangd/index/tls.h.6C3692A6EC4A764A.idx differ diff --git a/faith-server/.cache/clangd/index/user.h.0278CD7771A19AE0.idx b/faith-server/.cache/clangd/index/user.h.0278CD7771A19AE0.idx new file mode 100644 index 0000000..9e2055e Binary files /dev/null and b/faith-server/.cache/clangd/index/user.h.0278CD7771A19AE0.idx differ diff --git a/faithd/.clang-format b/faith-server/.clang-format similarity index 100% rename from faithd/.clang-format rename to faith-server/.clang-format diff --git a/faithd/.gitignore b/faith-server/.gitignore similarity index 100% rename from faithd/.gitignore rename to faith-server/.gitignore diff --git a/faith-server/compile_commands.json b/faith-server/compile_commands.json new file mode 100644 index 0000000..1514ff7 --- /dev/null +++ b/faith-server/compile_commands.json @@ -0,0 +1,272 @@ +[ + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/reactor_reactor.o", + "src/reactor/reactor.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/reactor/reactor.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/reactor_reactor.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/logging_logging.o", + "src/logging/logging.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/logging/logging.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/logging_logging.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/delivery_routing.o", + "src/delivery/routing.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/delivery/routing.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/delivery_routing.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/delivery_events.o", + "src/delivery/events.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/delivery/events.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/delivery_events.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/transport_conn.o", + "src/transport/conn.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/transport/conn.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/transport_conn.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/server_dispatch.o", + "src/server/dispatch.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/server/dispatch.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/server_dispatch.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/auth_handshake.o", + "src/auth/handshake.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/auth/handshake.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/auth_handshake.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/server_client_lifecycle.o", + "src/server/client_lifecycle.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/server/client_lifecycle.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/server_client_lifecycle.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/server_sess_registry.o", + "src/server/sess_registry.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/server/sess_registry.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/server_sess_registry.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/server_client_io.o", + "src/server/client_io.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/server/client_io.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/server_client_io.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/transport_frame.o", + "src/transport/frame.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/transport/frame.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/transport_frame.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/delivery_event_inbox.o", + "src/delivery/event_inbox.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/delivery/event_inbox.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/delivery_event_inbox.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/transport_tls.o", + "src/transport/tls.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/transport/tls.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/transport_tls.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/server_server.o", + "src/server/server.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/server/server.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/server_server.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/auth_device_link.o", + "src/auth/device_link.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/auth/device_link.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/auth_device_link.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/commands_conversation.o", + "src/commands/conversation.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/commands/conversation.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/commands_conversation.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/commands_dispatch.o", + "src/commands/dispatch.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/commands/dispatch.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/commands_dispatch.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-Wall", + "-Wextra", + "-I../faith-proto/include", + "-c", + "-o", + "./build/obj/faithd.o", + "src/faithd.c" + ], + "directory": "/home/luca/Dev/faith/faith-server", + "file": "/home/luca/Dev/faith/faith-server/src/faithd.c", + "output": "/home/luca/Dev/faith/faith-server/build/obj/faithd.o" + } +] diff --git a/faith-server/ident/25822ebfee4228d6142b665edd314b0a.bin b/faith-server/ident/25822ebfee4228d6142b665edd314b0a.bin new file mode 100644 index 0000000..0eb4568 --- /dev/null +++ b/faith-server/ident/25822ebfee4228d6142b665edd314b0a.bin @@ -0,0 +1,2 @@ +%‚.¿îB(Ö+f^Ý1K +™s-‚ÇÖÛ׫. í°*C,¬I @û¯·\$” lmÓZ[7Y¦…Ð0qôU&ÉøaZÉÃ+ÜwòA½‰ÖÈP‘ätöȽê í7“cà´Ê‹ \ No newline at end of file diff --git a/faith-server/ident/c6923af794ef6aa62012539a4ec45d26.bin b/faith-server/ident/c6923af794ef6aa62012539a4ec45d26.bin new file mode 100644 index 0000000..4b76aad Binary files /dev/null and b/faith-server/ident/c6923af794ef6aa62012539a4ec45d26.bin differ diff --git a/faithd/nob.c b/faith-server/nob.c similarity index 70% rename from faithd/nob.c rename to faith-server/nob.c index d765cc1..8b49cdc 100644 --- a/faithd/nob.c +++ b/faith-server/nob.c @@ -1,16 +1,20 @@ #include + #define NOBDEF static inline #define NOB_IMPLEMENTATION #define NOB_EXPERIMENTAL_DELETE_OLD #define NOB_WARN_DEPRECATED #define NOB_STRIP_PREFIX -#include "third_party/nob.h" +#include "../third_party/third_party/nob.h" #define command(arg, commands, name, signature, description) \ command_loc(__FILE__, __LINE__, (arg), (commands), (name), (signature), \ (description)) #define BUILD_FOLDER "./build/" +#define FAITH_PROTO_ROOT "../faith-proto/" +#define FAITH_PROTO_INCLUDE FAITH_PROTO_ROOT "include" +#define FAITH_PROTO_LIBRARY FAITH_PROTO_ROOT "build/libfaith_proto.a" typedef struct { const char *name; @@ -37,15 +41,20 @@ void commands_reset(Commands *commands) { void print_available_commands(Commands commands) { size_t max_name_width = 0; size_t max_sign_width = 0; + da_foreach(Command, command, &commands) { size_t name_width = strlen(command->name); size_t sign_width = strlen(command->signature); + if (name_width > max_name_width) max_name_width = name_width; + if (sign_width > max_sign_width) max_sign_width = sign_width; } + nob_log(INFO, "Available commands:"); + da_foreach(Command, command, &commands) { nob_log(INFO, " %-*s %-*s - %s", (int)max_name_width, command->name, (int)max_sign_width, command->signature, command->description); @@ -61,38 +70,34 @@ bool command_loc(const char *file, int line, const char *arg, "%s:%d: ASSERTION FAILED: the branch for command `%s` fell through.\n", commands->picked_at_file, commands->picked_at_line, commands->picked_name); + fprintf(stderr, "%s:%d: NOTE: the execution proceeded to here, but the command was " "already picked.\n", file, line); + abort(); } + Command command = { .name = name, .signature = signature, .description = description, }; + da_append(commands, command); + commands->picked_name = name; commands->picked_at_line = line; commands->picked_at_file = file; - commands->picked = (strcmp(arg, name) == 0); + commands->picked = strcmp(arg, name) == 0; + return commands->picked; } static const char *faithd_sources[] = { "src/auth/device_link.c", "src/auth/handshake.c", - "src/auth/structs.c", - "src/codec/events.c", - "src/codec/helpers.c", - "src/codec/msg.c", - "src/codec/protocol.c", - "src/codec/commands.c", - "src/codec/signatures.c", - "src/core/core.c", - "src/core/crypto.c", - "src/codec/envelopes.c", "src/delivery/event_inbox.c", "src/delivery/events.c", "src/delivery/routing.c", @@ -114,16 +119,6 @@ static const char *faithd_sources[] = { static const char *faithd_objects[] = { BUILD_FOLDER "obj/auth_device_link.o", BUILD_FOLDER "obj/auth_handshake.o", - BUILD_FOLDER "obj/auth_structs.o", - BUILD_FOLDER "obj/codec_events.o", - BUILD_FOLDER "obj/codec_helpers.o", - BUILD_FOLDER "obj/codec_msg.o", - BUILD_FOLDER "obj/codec_protocol.o", - BUILD_FOLDER "obj/codec_commands.o", - BUILD_FOLDER "obj/codec_signatures.o", - BUILD_FOLDER "obj/core_core.o", - BUILD_FOLDER "obj/core_crypto.o", - BUILD_FOLDER "obj/codec_envelopes.o", BUILD_FOLDER "obj/delivery_event_inbox.o", BUILD_FOLDER "obj/delivery_events.o", BUILD_FOLDER "obj/delivery_routing.o", @@ -142,31 +137,13 @@ static const char *faithd_objects[] = { BUILD_FOLDER "obj/faithd.o", }; -static const char *test_sources[] = { - "src/test/client_test_suite.c", - "src/client/client.c", -}; - -static const char *test_objects[] = { - BUILD_FOLDER "obj/client_test_suite.o", - BUILD_FOLDER "obj/client_client.o", -}; - -static const char *test_shared_objects[] = { - BUILD_FOLDER "obj/codec_protocol.o", BUILD_FOLDER "obj/core_crypto.o", - BUILD_FOLDER "obj/core_core.o", BUILD_FOLDER "obj/codec_helpers.o", - BUILD_FOLDER "obj/codec_envelopes.o", BUILD_FOLDER "obj/auth_structs.o", - BUILD_FOLDER "obj/codec_signatures.o", BUILD_FOLDER "obj/codec_msg.o", - BUILD_FOLDER "obj/codec_commands.o", BUILD_FOLDER "obj/codec_events.o", -}; - static bool compile_source_async(Procs *procs, const char *source, const char *object) { Cmd cmd = {0}; nob_cc(&cmd); nob_cc_flags(&cmd); - nob_cmd_append(&cmd, "-c", source, "-o", object); + nob_cmd_append(&cmd, "-I" FAITH_PROTO_INCLUDE, "-I../third_party/", "-c", source, "-o", object); if (!nob_cmd_run(&cmd, .async = procs, .max_procs = 0)) { nob_cmd_free(cmd); @@ -185,8 +162,16 @@ bool build(void) { _Static_assert(NOB_ARRAY_LEN(faithd_sources) == NOB_ARRAY_LEN(faithd_objects), "faithd source/object count mismatch"); - _Static_assert(NOB_ARRAY_LEN(test_sources) == NOB_ARRAY_LEN(test_objects), - "test source/object count mismatch"); + if (!nob_file_exists(FAITH_PROTO_LIBRARY)) { + nob_log(ERROR, "Required library is missing: %s", FAITH_PROTO_LIBRARY); + goto cleanup; + } + + if (!nob_file_exists(FAITH_PROTO_INCLUDE)) { + nob_log(ERROR, "Required include directory is missing: %s", + FAITH_PROTO_INCLUDE); + goto cleanup; + } if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) goto cleanup; @@ -199,37 +184,16 @@ bool build(void) { goto cleanup; } - for (size_t i = 0; i < NOB_ARRAY_LEN(test_sources); ++i) { - if (!compile_source_async(&procs, test_sources[i], test_objects[i])) - goto cleanup; - } - if (!nob_procs_flush(&procs)) goto cleanup; - /* Link faithd */ nob_cc(&cmd); - nob_cc_output(&cmd, BUILD_FOLDER "faithd"); + nob_cc_output(&cmd, BUILD_FOLDER "faith-server"); for (size_t i = 0; i < NOB_ARRAY_LEN(faithd_objects); ++i) nob_cmd_append(&cmd, faithd_objects[i]); - nob_cmd_append(&cmd, "-lssl", "-lcrypto"); - - if (!nob_cmd_run(&cmd)) - goto cleanup; - - /* Link test_suite */ - nob_cc(&cmd); - nob_cc_output(&cmd, BUILD_FOLDER "test_suite"); - - for (size_t i = 0; i < NOB_ARRAY_LEN(test_objects); ++i) - nob_cmd_append(&cmd, test_objects[i]); - - for (size_t i = 0; i < NOB_ARRAY_LEN(test_shared_objects); ++i) - nob_cmd_append(&cmd, test_shared_objects[i]); - - nob_cmd_append(&cmd, "-lssl", "-lcrypto"); + nob_cmd_append(&cmd, FAITH_PROTO_LIBRARY, "-lssl", "-lcrypto"); if (!nob_cmd_run(&cmd)) goto cleanup; @@ -249,14 +213,17 @@ bool build(void) { int main(int argc, char **argv) { #ifdef _WIN32 SetConsoleOutputCP(CP_UTF8); -#endif // _WIN32 +#endif - GO_REBUILD_URSELF_PLUS(argc, argv, "third_party/nob.h"); + GO_REBUILD_URSELF_PLUS(argc, argv, "../third_party/third_party/nob.h"); set_log_handler(cancer_log_handler); const char *program_name = shift(argv, argc); const char *command_name = "build"; + + (void)program_name; + if (argc > 0) command_name = shift(argv, argc); @@ -264,36 +231,38 @@ int main(int argc, char **argv) { commands_reset(&commands); - if (command(command_name, &commands, "build", "[test_names...]", - "Run the tests checking their expected output")) { - if (!mkdir_if_not_exists(BUILD_FOLDER)) - return 1; - + if (command(command_name, &commands, "build", "", + "Build the Faith API server")) { if (!build()) return 1; return 0; } + if (command(command_name, &commands, "chain", "", "Generate certificate files \"chain.pem\" and \"pkey.pem\"")) { - // generate pkey.pem { Nob_Cmd cmd = {0}; + cmd_append(&cmd, "openssl", "genpkey", "-algorithm", "rsa", "-out", "pkey.pem", "-pkeyopt", "rsa_keygen_bits:2048"); + cmd_run(&cmd); } - // generate chain.pem + { Nob_Cmd cmd = {0}; + cmd_append(&cmd, "openssl", "req", "-x509", "-new", "-key", "pkey.pem", "-days", "36500", "-subj", "/CN=localhost", "-out", "chain.pem"); + cmd_run(&cmd); } return 0; } + if (command(command_name, &commands, "help", "", "Print this help message")) { print_available_commands(commands); return 0; @@ -301,5 +270,6 @@ int main(int argc, char **argv) { print_available_commands(commands); nob_log(ERROR, "Unknown command %s", command_name); + return 1; } diff --git a/faithd/scripts/format.sh b/faith-server/scripts/format.sh similarity index 100% rename from faithd/scripts/format.sh rename to faith-server/scripts/format.sh diff --git a/faithd/src/application/user.h b/faith-server/src/application/user.h similarity index 83% rename from faithd/src/application/user.h rename to faith-server/src/application/user.h index a6e7a8a..c7b7136 100644 --- a/faithd/src/application/user.h +++ b/faith-server/src/application/user.h @@ -1,6 +1,6 @@ #pragma once -#include "../auth/structs.h" +#include typedef struct { faith_auth_id_t auth_id; diff --git a/faithd/src/auth/device_link.c b/faith-server/src/auth/device_link.c similarity index 99% rename from faithd/src/auth/device_link.c rename to faith-server/src/auth/device_link.c index 6ef78f0..7b16f7e 100644 --- a/faithd/src/auth/device_link.c +++ b/faith-server/src/auth/device_link.c @@ -1,15 +1,15 @@ #include "device_link.h" -#include "../../third_party/stb_ds.h" +#include #include "../server/client_io.h" #include "../server/client_lifecycle.h" -#include "../codec/signatures.h" +#include +#include #include "../delivery/routing.h" -#include "structs.h" #define NOB_IMPLEMENTATION -#include "../../third_party/nob.h" +#include #include "../logging/logging.h" #include "handshake.h" diff --git a/faithd/src/auth/device_link.h b/faith-server/src/auth/device_link.h similarity index 85% rename from faithd/src/auth/device_link.h rename to faith-server/src/auth/device_link.h index bd85ebb..2b40c3f 100644 --- a/faithd/src/auth/device_link.h +++ b/faith-server/src/auth/device_link.h @@ -1,17 +1,12 @@ #pragma once -#include "../core/core.h" +#include +#include #include "../server/server.h" -#include "structs.h" #define FAITH_DEVICE_LINK_REQ_EXPIRATION_TIME_MS 1000 * 60 /* 60 seconds */ -typedef enum { - FAITH_DEVICE_LINK_DENY = 0, - FAITH_DEVICE_LINK_APPROVE = 1, -} faith_device_link_response_type_t; - faith_status_code_t device_link_handle_device_response(server_state_t *s, client_conn_t *cl, const faith_envelope_t *response_envl); diff --git a/faithd/src/auth/handshake.c b/faith-server/src/auth/handshake.c similarity index 99% rename from faithd/src/auth/handshake.c rename to faith-server/src/auth/handshake.c index 41ef4fb..25ecf50 100644 --- a/faithd/src/auth/handshake.c +++ b/faith-server/src/auth/handshake.c @@ -2,10 +2,9 @@ #include "../server/client_io.h" #include "device_link.h" -#include "structs.h" - -#include "../codec/protocol.h" -#include "../codec/signatures.h" +#include +#include +#include #include "../delivery/events.h" diff --git a/faithd/src/auth/handshake.h b/faith-server/src/auth/handshake.h similarity index 93% rename from faithd/src/auth/handshake.h rename to faith-server/src/auth/handshake.h index 2c4b078..a62a5ea 100644 --- a/faithd/src/auth/handshake.h +++ b/faith-server/src/auth/handshake.h @@ -1,6 +1,7 @@ #pragma once -#include "../core/core.h" +#include +#include #include "../server/server.h" diff --git a/faithd/src/auth/structs.h b/faith-server/src/auth/helpers.h similarity index 92% rename from faithd/src/auth/structs.h rename to faith-server/src/auth/helpers.h index 149161e..c1bf30f 100644 --- a/faithd/src/auth/structs.h +++ b/faith-server/src/auth/helpers.h @@ -3,8 +3,18 @@ #include #include -#include "../core/core.h" -#include "../core/crypto.h" +#include +#include + +#include + +typedef struct { + uint64_t nonce; + uint64_t server_nonce; + uint8_t public_key[FAITH_ED25519_PUBLIC_KEY_SIZE]; + faith_auth_id_t sender_auth_id; + faith_device_id_t device_id; +} client_auth_handshake_params_t; #define _FH_FOR_EACH_AUTH_DEVICE_CONNECTION(SERVER, AUTH_ID, RECIPIENT, \ STATUS_OUT, BODY) \ @@ -72,24 +82,3 @@ } \ } while (0) -#define FAITH_AUTH_ID_SIZE 16 -#define FAITH_DEVICE_ID_SIZE 16 - -typedef struct { - uint8_t bytes[FAITH_AUTH_ID_SIZE]; -} faith_auth_id_t; - -typedef struct { - uint8_t bytes[FAITH_DEVICE_ID_SIZE]; -} faith_device_id_t; - -typedef struct { - uint64_t nonce; - uint64_t server_nonce; - uint8_t public_key[FAITH_ED25519_PUBLIC_KEY_SIZE]; - faith_auth_id_t sender_auth_id; - faith_device_id_t device_id; -} client_auth_handshake_params_t; - -bool faith_client_id_equal(faith_auth_id_t a, faith_auth_id_t b); -bool faith_device_id_equal(faith_device_id_t a, faith_device_id_t b); diff --git a/faithd/src/commands/conversation.c b/faith-server/src/commands/conversation.c similarity index 76% rename from faithd/src/commands/conversation.c rename to faith-server/src/commands/conversation.c index a509601..c5e565a 100644 --- a/faithd/src/commands/conversation.c +++ b/faith-server/src/commands/conversation.c @@ -2,12 +2,12 @@ #include "../delivery/events.h" -#include "../../third_party/stb_ds.h" +#include static faith_status_code_t send_conversation_created( server_state_t *s, client_conn_t *cl, const faith_event_conversation_created_t *conv_created, - const faith_auth_id_t* conservant_id) { + const faith_auth_id_t *conservant_id) { if (!s || !cl || !conv_created) return FAITH_ERR_INVALID; @@ -18,15 +18,17 @@ static faith_status_code_t send_conversation_created( _FH_CHECK_RETURN(faith_encode_event_conversation_created( data, &data_size, sizeof(data), conv_created)); - _FH_CHECK_RETURN(delivery_queue_event(s, &cl->ident.auth_id, &cl->ident.device_id, FAITH_EVENT_CONVERSATION_CREATED, - data, data_size)); + _FH_CHECK_RETURN( + delivery_queue_event(s, &cl->ident.auth_id, &cl->ident.device_id, + FAITH_EVENT_CONVERSATION_CREATED, data, data_size)); faith_status_code_t device_loop_rc = FAITH_OK; - _FH_FOR_EACH_AUTH_DEVICE_SESSION(s, conservant_id, recipient_sess, device_loop_rc, { - _FH_CHECK_RETURN(delivery_queue_event( - s, conservant_id, &recipient_sess->ident.device_id, - FAITH_EVENT_CONVERSATION_CREATED, data, data_size)); - }); + _FH_FOR_EACH_AUTH_DEVICE_SESSION( + s, conservant_id, recipient_sess, device_loop_rc, { + _FH_CHECK_RETURN(delivery_queue_event( + s, conservant_id, &recipient_sess->ident.device_id, + FAITH_EVENT_CONVERSATION_CREATED, data, data_size)); + }); return device_loop_rc; } @@ -63,9 +65,8 @@ faith_status_code_t conv_handle_create_conversation( faith_event_conversation_created_t conv_created = {.conversation_id = conv_id}; - for(size_t i = 0; i < 100; i++) { - _FH_CHECK_DEFER(send_conversation_created(s, cl, &conv_created, &create_conv_cmd.conversant_id)); - } + _FH_CHECK_DEFER(send_conversation_created(s, cl, &conv_created, + &create_conv_cmd.conversant_id)); *o_result = FAITH_COMMAND_RESULT_ACCEPTED; diff --git a/faithd/src/commands/conversation.h b/faith-server/src/commands/conversation.h similarity index 77% rename from faithd/src/commands/conversation.h rename to faith-server/src/commands/conversation.h index c8ccb87..c26f68f 100644 --- a/faithd/src/commands/conversation.h +++ b/faith-server/src/commands/conversation.h @@ -1,8 +1,7 @@ #pragma once -#include "../core/core.h" - -#include "../codec/commands.h" +#include +#include #include "../server/server.h" diff --git a/faithd/src/commands/dispatch.c b/faith-server/src/commands/dispatch.c similarity index 95% rename from faithd/src/commands/dispatch.c rename to faith-server/src/commands/dispatch.c index 23f1043..f7a85f0 100644 --- a/faithd/src/commands/dispatch.c +++ b/faith-server/src/commands/dispatch.c @@ -1,12 +1,11 @@ #include "dispatch.h" -#include "../codec/protocol.h" -#include "../core/core.h" +#include +#include +#include #include "../server/client_io.h" -#include "../auth/structs.h" - #include "conversation.h" #define _MODULE_NAME "commands/dispatch" diff --git a/faithd/src/commands/dispatch.h b/faith-server/src/commands/dispatch.h similarity index 62% rename from faithd/src/commands/dispatch.h rename to faith-server/src/commands/dispatch.h index 9d6aad9..1a3414f 100644 --- a/faithd/src/commands/dispatch.h +++ b/faith-server/src/commands/dispatch.h @@ -1,8 +1,9 @@ #pragma once -#include "../core/core.h" +#include -#include "../codec/commands.h" +#include +#include #include "../server/server.h" diff --git a/faithd/src/delivery/event_inbox.c b/faith-server/src/delivery/event_inbox.c similarity index 98% rename from faithd/src/delivery/event_inbox.c rename to faith-server/src/delivery/event_inbox.c index dad1a05..5e77fa8 100644 --- a/faithd/src/delivery/event_inbox.c +++ b/faith-server/src/delivery/event_inbox.c @@ -1,6 +1,6 @@ #include "event_inbox.h" -#include "../../third_party/stb_ds.h" +#include #include #define _MODULE_NAME "delivery/event_inbox" diff --git a/faithd/src/delivery/event_inbox.h b/faith-server/src/delivery/event_inbox.h similarity index 94% rename from faithd/src/delivery/event_inbox.h rename to faith-server/src/delivery/event_inbox.h index c32ea08..6bb3aa5 100644 --- a/faithd/src/delivery/event_inbox.h +++ b/faith-server/src/delivery/event_inbox.h @@ -1,6 +1,6 @@ #pragma once -#include "../codec/events.h" +#include #include diff --git a/faithd/src/delivery/events.c b/faith-server/src/delivery/events.c similarity index 98% rename from faithd/src/delivery/events.c rename to faith-server/src/delivery/events.c index 6e3f79e..89d4d57 100644 --- a/faithd/src/delivery/events.c +++ b/faith-server/src/delivery/events.c @@ -1,10 +1,10 @@ #include "events.h" -#include "../codec/protocol.h" +#include #include "../server/client_io.h" #include "event_inbox.h" -#include "../../third_party/stb_ds.h" +#include #define DIV_UP(x, y) (((x) + (y) - 1) / (y)) diff --git a/faithd/src/delivery/events.h b/faith-server/src/delivery/events.h similarity index 88% rename from faithd/src/delivery/events.h rename to faith-server/src/delivery/events.h index b59a09c..b811532 100644 --- a/faithd/src/delivery/events.h +++ b/faith-server/src/delivery/events.h @@ -1,7 +1,8 @@ #pragma once -#include "../codec/events.h" -#include "../core/core.h" +#include +#include +#include #include "../server/server.h" faith_status_code_t delivery_queue_event(server_state_t *s, diff --git a/faithd/src/delivery/routing.c b/faith-server/src/delivery/routing.c similarity index 98% rename from faithd/src/delivery/routing.c rename to faith-server/src/delivery/routing.c index e837298..26eb7eb 100644 --- a/faithd/src/delivery/routing.c +++ b/faith-server/src/delivery/routing.c @@ -1,7 +1,7 @@ #include "routing.h" #include "../server/client_io.h" -#include "../../third_party/stb_ds.h" +#include #define _MODULE_NAME "delivery/routing" diff --git a/faithd/src/delivery/routing.h b/faith-server/src/delivery/routing.h similarity index 85% rename from faithd/src/delivery/routing.h rename to faith-server/src/delivery/routing.h index d3aebee..41a9d86 100644 --- a/faithd/src/delivery/routing.h +++ b/faith-server/src/delivery/routing.h @@ -1,6 +1,7 @@ #pragma once -#include "../core/core.h" +#include +#include #include "../server/server.h" diff --git a/faithd/src/faithd.c b/faith-server/src/faithd.c similarity index 100% rename from faithd/src/faithd.c rename to faith-server/src/faithd.c diff --git a/faithd/src/logging/logging.c b/faith-server/src/logging/logging.c similarity index 100% rename from faithd/src/logging/logging.c rename to faith-server/src/logging/logging.c diff --git a/faithd/src/logging/logging.h b/faith-server/src/logging/logging.h similarity index 100% rename from faithd/src/logging/logging.h rename to faith-server/src/logging/logging.h diff --git a/faithd/src/reactor/reactor.c b/faith-server/src/reactor/reactor.c similarity index 100% rename from faithd/src/reactor/reactor.c rename to faith-server/src/reactor/reactor.c diff --git a/faithd/src/reactor/reactor.h b/faith-server/src/reactor/reactor.h similarity index 97% rename from faithd/src/reactor/reactor.h rename to faith-server/src/reactor/reactor.h index 4e315b2..43321af 100644 --- a/faithd/src/reactor/reactor.h +++ b/faith-server/src/reactor/reactor.h @@ -2,7 +2,7 @@ #include -#include "../core/core.h" +#include #define REACTOR_MAX_EVENTS 1024 diff --git a/faithd/src/server/client_io.c b/faith-server/src/server/client_io.c similarity index 99% rename from faithd/src/server/client_io.c rename to faith-server/src/server/client_io.c index 7c8b60a..37c62dc 100644 --- a/faithd/src/server/client_io.c +++ b/faith-server/src/server/client_io.c @@ -5,7 +5,7 @@ #include "../logging/logging.h" #include "../transport/frame.h" -#include "../codec/envelopes.h" +#include #include "dispatch.h" diff --git a/faithd/src/server/client_io.h b/faith-server/src/server/client_io.h similarity index 89% rename from faithd/src/server/client_io.h rename to faith-server/src/server/client_io.h index 252d7a3..745cd84 100644 --- a/faithd/src/server/client_io.h +++ b/faith-server/src/server/client_io.h @@ -1,8 +1,8 @@ #pragma once -#include "../codec/msg.h" -#include "../codec/protocol.h" -#include "../core/core.h" +#include +#include +#include #include "server.h" diff --git a/faithd/src/server/client_lifecycle.c b/faith-server/src/server/client_lifecycle.c similarity index 99% rename from faithd/src/server/client_lifecycle.c rename to faith-server/src/server/client_lifecycle.c index 9315ae1..245e0fc 100644 --- a/faithd/src/server/client_lifecycle.c +++ b/faith-server/src/server/client_lifecycle.c @@ -4,7 +4,7 @@ #include "client_io.h" -#include "../../third_party/stb_ds.h" +#include #define _MODULE_NAME "server/client_lifecycle" diff --git a/faithd/src/server/client_lifecycle.h b/faith-server/src/server/client_lifecycle.h similarity index 89% rename from faithd/src/server/client_lifecycle.h rename to faith-server/src/server/client_lifecycle.h index 0d33429..a1386fb 100644 --- a/faithd/src/server/client_lifecycle.h +++ b/faith-server/src/server/client_lifecycle.h @@ -1,7 +1,7 @@ #pragma once -#include "../core/core.h" -#include "envelopes.h" +#include +#include #include "server.h" diff --git a/faithd/src/server/dispatch.c b/faith-server/src/server/dispatch.c similarity index 99% rename from faithd/src/server/dispatch.c rename to faith-server/src/server/dispatch.c index 204d65c..797ce0e 100644 --- a/faithd/src/server/dispatch.c +++ b/faith-server/src/server/dispatch.c @@ -1,5 +1,5 @@ #include "dispatch.h" -#include "../core/core.h" +#include #include "client_io.h" #include "server.h" diff --git a/faithd/src/server/dispatch.h b/faith-server/src/server/dispatch.h similarity index 82% rename from faithd/src/server/dispatch.h rename to faith-server/src/server/dispatch.h index 4b1da13..a139390 100644 --- a/faithd/src/server/dispatch.h +++ b/faith-server/src/server/dispatch.h @@ -1,6 +1,6 @@ #pragma once -#include "../codec/protocol.h" +#include #include "server.h" faith_status_code_t server_dispatch_frame(server_state_t *s, client_conn_t *cl, diff --git a/faithd/src/server/server.c b/faith-server/src/server/server.c similarity index 99% rename from faithd/src/server/server.c rename to faith-server/src/server/server.c index b19000e..8ff9ee5 100644 --- a/faithd/src/server/server.c +++ b/faith-server/src/server/server.c @@ -10,8 +10,8 @@ #include #include -#include "../../third_party/nob.h" -#include "../../third_party/stb_ds.h" +#include +#include #define _MODULE_NAME "server/server" diff --git a/faithd/src/server/server.h b/faith-server/src/server/server.h similarity index 95% rename from faithd/src/server/server.h rename to faith-server/src/server/server.h index 6eab6c7..f23160c 100644 --- a/faithd/src/server/server.h +++ b/faith-server/src/server/server.h @@ -1,11 +1,12 @@ #pragma once -#include "../auth/envelopes.h" +#include "../auth/helpers.h" #include "../reactor/reactor.h" #include "../transport/conn.h" #include "sess_registry.h" -#include "../auth/structs.h" +#include +#include #include diff --git a/faithd/src/server/sess_registry.c b/faith-server/src/server/sess_registry.c similarity index 99% rename from faithd/src/server/sess_registry.c rename to faith-server/src/server/sess_registry.c index e7028d9..f76bf7b 100644 --- a/faithd/src/server/sess_registry.c +++ b/faith-server/src/server/sess_registry.c @@ -3,7 +3,7 @@ #include "server.h" #define STB_DS_IMPLEMENTATION -#include "../../third_party/stb_ds.h" +#include #define _MODULE_NAME "server/sess_registry" diff --git a/faithd/src/server/sess_registry.h b/faith-server/src/server/sess_registry.h similarity index 96% rename from faithd/src/server/sess_registry.h rename to faith-server/src/server/sess_registry.h index ae300b7..8d73b8a 100644 --- a/faithd/src/server/sess_registry.h +++ b/faith-server/src/server/sess_registry.h @@ -1,8 +1,9 @@ #pragma once #include "../application/user.h" -#include "../auth/structs.h" -#include "../core/core.h" + +#include +#include #include "../delivery/event_inbox.h" typedef struct { diff --git a/faithd/src/transport/conn.c b/faith-server/src/transport/conn.c similarity index 100% rename from faithd/src/transport/conn.c rename to faith-server/src/transport/conn.c diff --git a/faithd/src/transport/conn.h b/faith-server/src/transport/conn.h similarity index 97% rename from faithd/src/transport/conn.h rename to faith-server/src/transport/conn.h index 35439ce..36030c9 100644 --- a/faithd/src/transport/conn.h +++ b/faith-server/src/transport/conn.h @@ -1,6 +1,6 @@ #pragma once -#include "../core/core.h" +#include #include "tls.h" #include diff --git a/faithd/src/transport/frame.c b/faith-server/src/transport/frame.c similarity index 100% rename from faithd/src/transport/frame.c rename to faith-server/src/transport/frame.c diff --git a/faithd/src/transport/frame.h b/faith-server/src/transport/frame.h similarity index 92% rename from faithd/src/transport/frame.h rename to faith-server/src/transport/frame.h index 394bf94..ca41b3a 100644 --- a/faithd/src/transport/frame.h +++ b/faith-server/src/transport/frame.h @@ -1,6 +1,6 @@ #pragma once -#include "../codec/protocol.h" +#include #include "conn.h" transport_result_t frame_try_full_read(transport_conn_t *conn, diff --git a/faithd/src/transport/tls.c b/faith-server/src/transport/tls.c similarity index 100% rename from faithd/src/transport/tls.c rename to faith-server/src/transport/tls.c diff --git a/faithd/src/transport/tls.h b/faith-server/src/transport/tls.h similarity index 97% rename from faithd/src/transport/tls.h rename to faith-server/src/transport/tls.h index b8302a0..2b7e32f 100644 --- a/faithd/src/transport/tls.h +++ b/faith-server/src/transport/tls.h @@ -1,6 +1,6 @@ #pragma once -#include "../core/core.h" +#include #include diff --git a/Cargo.lock b/faith-ui/Cargo.lock similarity index 100% rename from Cargo.lock rename to faith-ui/Cargo.lock diff --git a/Cargo.toml b/faith-ui/Cargo.toml similarity index 100% rename from Cargo.toml rename to faith-ui/Cargo.toml diff --git a/assets/NotoColorEmoji.ttf b/faith-ui/assets/NotoColorEmoji.ttf similarity index 100% rename from assets/NotoColorEmoji.ttf rename to faith-ui/assets/NotoColorEmoji.ttf diff --git a/assets/NotoSans-Bold.ttf b/faith-ui/assets/NotoSans-Bold.ttf similarity index 100% rename from assets/NotoSans-Bold.ttf rename to faith-ui/assets/NotoSans-Bold.ttf diff --git a/assets/NotoSans-Regular.ttf b/faith-ui/assets/NotoSans-Regular.ttf similarity index 100% rename from assets/NotoSans-Regular.ttf rename to faith-ui/assets/NotoSans-Regular.ttf diff --git a/assets/NotoSansArabic-Regular.ttf b/faith-ui/assets/NotoSansArabic-Regular.ttf similarity index 100% rename from assets/NotoSansArabic-Regular.ttf rename to faith-ui/assets/NotoSansArabic-Regular.ttf diff --git a/assets/NotoSansHebrew-Regular.ttf b/faith-ui/assets/NotoSansHebrew-Regular.ttf similarity index 100% rename from assets/NotoSansHebrew-Regular.ttf rename to faith-ui/assets/NotoSansHebrew-Regular.ttf diff --git a/faith-ui/assets/logo.png b/faith-ui/assets/logo.png new file mode 100644 index 0000000..d389cd1 Binary files /dev/null and b/faith-ui/assets/logo.png differ diff --git a/build.rs b/faith-ui/build.rs similarity index 100% rename from build.rs rename to faith-ui/build.rs diff --git a/scripts/check.sh b/faith-ui/scripts/check.sh similarity index 100% rename from scripts/check.sh rename to faith-ui/scripts/check.sh diff --git a/shaders/frag.glsl b/faith-ui/shaders/frag.glsl similarity index 100% rename from shaders/frag.glsl rename to faith-ui/shaders/frag.glsl diff --git a/shaders/frag_dedicated.glsl b/faith-ui/shaders/frag_dedicated.glsl similarity index 100% rename from shaders/frag_dedicated.glsl rename to faith-ui/shaders/frag_dedicated.glsl diff --git a/shaders/vert.glsl b/faith-ui/shaders/vert.glsl similarity index 100% rename from shaders/vert.glsl rename to faith-ui/shaders/vert.glsl diff --git a/src/cli.rs b/faith-ui/src/cli.rs similarity index 100% rename from src/cli.rs rename to faith-ui/src/cli.rs diff --git a/src/graphics/color.rs b/faith-ui/src/graphics/color.rs similarity index 100% rename from src/graphics/color.rs rename to faith-ui/src/graphics/color.rs diff --git a/src/graphics/device.rs b/faith-ui/src/graphics/device.rs similarity index 100% rename from src/graphics/device.rs rename to faith-ui/src/graphics/device.rs diff --git a/src/graphics/font.rs b/faith-ui/src/graphics/font.rs similarity index 100% rename from src/graphics/font.rs rename to faith-ui/src/graphics/font.rs diff --git a/src/graphics/handles.rs b/faith-ui/src/graphics/handles.rs similarity index 100% rename from src/graphics/handles.rs rename to faith-ui/src/graphics/handles.rs diff --git a/src/graphics/image.rs b/faith-ui/src/graphics/image.rs similarity index 100% rename from src/graphics/image.rs rename to faith-ui/src/graphics/image.rs diff --git a/src/graphics/mod.rs b/faith-ui/src/graphics/mod.rs similarity index 100% rename from src/graphics/mod.rs rename to faith-ui/src/graphics/mod.rs diff --git a/src/graphics/opengl/backend.rs b/faith-ui/src/graphics/opengl/backend.rs similarity index 100% rename from src/graphics/opengl/backend.rs rename to faith-ui/src/graphics/opengl/backend.rs diff --git a/src/graphics/opengl/mod.rs b/faith-ui/src/graphics/opengl/mod.rs similarity index 100% rename from src/graphics/opengl/mod.rs rename to faith-ui/src/graphics/opengl/mod.rs diff --git a/src/graphics/renderer.rs b/faith-ui/src/graphics/renderer.rs similarity index 100% rename from src/graphics/renderer.rs rename to faith-ui/src/graphics/renderer.rs diff --git a/src/graphics/vulkan/backend.rs b/faith-ui/src/graphics/vulkan/backend.rs similarity index 100% rename from src/graphics/vulkan/backend.rs rename to faith-ui/src/graphics/vulkan/backend.rs diff --git a/src/graphics/vulkan/mod.rs b/faith-ui/src/graphics/vulkan/mod.rs similarity index 100% rename from src/graphics/vulkan/mod.rs rename to faith-ui/src/graphics/vulkan/mod.rs diff --git a/src/main.rs b/faith-ui/src/main.rs similarity index 100% rename from src/main.rs rename to faith-ui/src/main.rs diff --git a/src/platform/event.rs b/faith-ui/src/platform/event.rs similarity index 100% rename from src/platform/event.rs rename to faith-ui/src/platform/event.rs diff --git a/src/platform/mod.rs b/faith-ui/src/platform/mod.rs similarity index 100% rename from src/platform/mod.rs rename to faith-ui/src/platform/mod.rs diff --git a/src/platform/wayland.rs b/faith-ui/src/platform/wayland.rs similarity index 100% rename from src/platform/wayland.rs rename to faith-ui/src/platform/wayland.rs diff --git a/src/platform/window.rs b/faith-ui/src/platform/window.rs similarity index 100% rename from src/platform/window.rs rename to faith-ui/src/platform/window.rs diff --git a/src/platform/x11.rs b/faith-ui/src/platform/x11.rs similarity index 100% rename from src/platform/x11.rs rename to faith-ui/src/platform/x11.rs diff --git a/src/ui/mod.rs b/faith-ui/src/ui/mod.rs similarity index 100% rename from src/ui/mod.rs rename to faith-ui/src/ui/mod.rs diff --git a/src/ui/quad.rs b/faith-ui/src/ui/quad.rs similarity index 100% rename from src/ui/quad.rs rename to faith-ui/src/ui/quad.rs diff --git a/src/ui/renderer.rs b/faith-ui/src/ui/renderer.rs similarity index 100% rename from src/ui/renderer.rs rename to faith-ui/src/ui/renderer.rs diff --git a/src/ui/text.rs b/faith-ui/src/ui/text.rs similarity index 100% rename from src/ui/text.rs rename to faith-ui/src/ui/text.rs diff --git a/faithd/third_party/nob.h b/third_party/third_party/nob.h similarity index 100% rename from faithd/third_party/nob.h rename to third_party/third_party/nob.h diff --git a/faithd/third_party/stb_ds.h b/third_party/third_party/stb_ds.h similarity index 100% rename from faithd/third_party/stb_ds.h rename to third_party/third_party/stb_ds.h