Put verbose messages on a command-line argument, finally, and format the messages a bit better.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4625 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-11-09 00:28:34 +00:00
parent 5fff3b8161
commit a6c8dd846c
3 changed files with 42 additions and 3 deletions

View File

@ -276,6 +276,7 @@ typedef struct tf_run_args_t {
const char* args; const char* args;
const char* zip; const char* zip;
bool one_proc; bool one_proc;
bool verbose;
bool help; bool help;
} tf_run_args_t; } tf_run_args_t;
@ -307,6 +308,7 @@ static int _tf_run_task(const tf_run_args_t* args, int index)
} }
tf_task_set_db_path(task, db_path); tf_task_set_db_path(task, db_path);
tf_task_activate(task); tf_task_activate(task);
tf_ssb_set_verbose(tf_task_get_ssb(task), args->verbose);
tf_ssb_start_periodic(tf_task_get_ssb(task)); tf_ssb_start_periodic(tf_task_get_ssb(task));
if (args->zip) if (args->zip)
{ {
@ -393,6 +395,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
{ "args", 'a', offsetof(tf_run_args_t, args), NULL, XOPT_TYPE_STRING, NULL, "Arguments of the form key=value,foo=bar,verbose=true." }, { "args", 'a', offsetof(tf_run_args_t, args), NULL, XOPT_TYPE_STRING, NULL, "Arguments of the form key=value,foo=bar,verbose=true." },
{ "one-proc", 'o', offsetof(tf_run_args_t, one_proc), NULL, XOPT_TYPE_BOOL, NULL, "Run everything in one process (unsafely!)." }, { "one-proc", 'o', offsetof(tf_run_args_t, one_proc), NULL, XOPT_TYPE_BOOL, NULL, "Run everything in one process (unsafely!)." },
{ "zip", 'z', offsetof(tf_run_args_t, zip), NULL, XOPT_TYPE_STRING, NULL, "Zip archive from which to load files." }, { "zip", 'z', offsetof(tf_run_args_t, zip), NULL, XOPT_TYPE_STRING, NULL, "Zip archive from which to load files." },
{ "verbose", 'v', offsetof(tf_run_args_t, verbose), NULL, XOPT_TYPE_BOOL, NULL, "Log raw messages." },
{ "help", 'h', offsetof(tf_run_args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." }, { "help", 'h', offsetof(tf_run_args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." },
XOPT_NULLOPTION, XOPT_NULLOPTION,
}; };

View File

@ -49,6 +49,14 @@ const uint8_t k_ssb_network[] = {
0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
}; };
const char* k_ssb_type_names[] =
{
"binary",
"utf8",
"json",
"unknown",
};
typedef enum { typedef enum {
k_tf_ssb_state_invalid, k_tf_ssb_state_invalid,
k_tf_ssb_state_connected, k_tf_ssb_state_connected,
@ -751,7 +759,15 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
memcpy(combined + 1 + 2 * sizeof(uint32_t), message, size); memcpy(combined + 1 + 2 * sizeof(uint32_t), message, size);
if (connection->ssb->verbose) if (connection->ssb->verbose)
{ {
tf_printf(MAGENTA "%s RPC SEND" RESET " flags=%x RN=%d: [%zd B] %.*s\n", connection->name, flags & k_ssb_rpc_mask_send, request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message); tf_printf(MAGENTA "%s RPC SEND" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n",
connection->name,
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
(flags & k_ssb_rpc_flag_stream) ? "true" : "false",
k_ssb_type_names[flags & k_ssb_rpc_mask_type],
request_number,
size,
(flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size,
message);
} }
_tf_ssb_connection_add_debug_message(connection, true, flags & k_ssb_rpc_mask_send, request_number, message, size); _tf_ssb_connection_add_debug_message(connection, true, flags & k_ssb_rpc_mask_send, request_number, message, size);
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size); _tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
@ -1519,7 +1535,15 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub); tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub);
if (connection->ssb->verbose) if (connection->ssb->verbose)
{ {
tf_printf(CYAN "%s RPC RECV" RESET " from %s flags=%x RN=%d: [%zd B] %.*s\n", connection->name, id, flags, request_number, size, (int)size, message); tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B] %.*s\n",
connection->name,
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
(flags & k_ssb_rpc_flag_stream) ? "true" : "false",
k_ssb_type_names[flags & k_ssb_rpc_mask_type],
request_number,
size,
(int)size,
message);
} }
JSContext* context = connection->ssb->context; JSContext* context = connection->ssb->context;
JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL); JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL);
@ -1579,7 +1603,13 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
{ {
if (connection->ssb->verbose) if (connection->ssb->verbose)
{ {
tf_printf(CYAN "%s RPC RECV" RESET " flags=%x RN=%d: %zd bytes\n", connection->name, flags, request_number, size); tf_printf(CYAN "%s RPC RECV" RESET " end/error=%s stream=%s type=%s RN=%d: [%zd B]\n",
connection->name,
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false",
(flags & k_ssb_rpc_flag_stream) ? "true" : "false",
k_ssb_type_names[flags & k_ssb_rpc_mask_type],
request_number,
size);
} }
tf_ssb_rpc_callback_t* callback = NULL; tf_ssb_rpc_callback_t* callback = NULL;
void* user_data = NULL; void* user_data = NULL;
@ -3869,3 +3899,8 @@ static void _tf_ssb_start_update_settings(tf_ssb_t* ssb, int delay_ms)
uv_timer_start(&ssb->settings_timer, _tf_ssb_start_update_settings_timer, delay_ms, delay_ms); uv_timer_start(&ssb->settings_timer, _tf_ssb_start_update_settings_timer, delay_ms, delay_ms);
uv_unref((uv_handle_t*)&ssb->settings_timer); uv_unref((uv_handle_t*)&ssb->settings_timer);
} }
void tf_ssb_set_verbose(tf_ssb_t* ssb, bool verbose)
{
ssb->verbose = verbose;
}

View File

@ -82,6 +82,7 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path
void tf_ssb_destroy(tf_ssb_t* ssb); void tf_ssb_destroy(tf_ssb_t* ssb);
void tf_ssb_start_periodic(tf_ssb_t* ssb); void tf_ssb_start_periodic(tf_ssb_t* ssb);
void tf_ssb_set_verbose(tf_ssb_t* ssb, bool verbose);
sqlite3* tf_ssb_acquire_db_reader(tf_ssb_t* ssb); sqlite3* tf_ssb_acquire_db_reader(tf_ssb_t* ssb);
sqlite3* tf_ssb_acquire_db_reader_restricted(tf_ssb_t* ssb); sqlite3* tf_ssb_acquire_db_reader_restricted(tf_ssb_t* ssb);