From bf7cc372230a99ac64032936553d3b3e694851c4 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 2 Jan 2024 10:03:21 -0600 Subject: [PATCH] Progress: Further work in TacocaT. The payload is now the only thing that gets written. The next things to do are to: - Process the headers and possibly the signatures. - Go through a lot of the error cases and make sure they are handled. - Address all of the todo and fixme comments. - Consider supporting encryption and including optional third-party libraries to perform such tasks. --- sources/c/tacocat/main/common/enumeration.h | 10 +- sources/c/tacocat/main/common/print.c | 1 + sources/c/tacocat/main/common/print.h | 1 + sources/c/tacocat/main/print/error.c | 64 +++++++++- sources/c/tacocat/main/print/error.h | 68 +++++++++-- sources/c/tacocat/main/receive.c | 176 ++++++++++++++++++++++------ sources/c/tacocat/main/receive.h | 9 ++ sources/c/tacocat/main/send.c | 11 +- sources/c/tacocat/main/tacocat.c | 4 +- 9 files changed, 284 insertions(+), 60 deletions(-) diff --git a/sources/c/tacocat/main/common/enumeration.h b/sources/c/tacocat/main/common/enumeration.h index ce24f5c..6f042ad 100644 --- a/sources/c/tacocat/main/common/enumeration.h +++ b/sources/c/tacocat/main/common/enumeration.h @@ -133,7 +133,8 @@ extern "C" { * - none: No flags set. * - control: Reading and processing the Control block and Size block. * - packet: Reading and processing the rest of the Packet block (the Header and Payload). - * - check: Process and check the loaded Payload block, processing the Header. + * - find: Find the Header block and everything else up until the Payload block. + * - check: Process and check the loaded Payload block, processing the Header block. * - write: Save the loaded Payload block to the file (write to the file). * - done: Done processing file. */ @@ -142,9 +143,10 @@ extern "C" { kt_tacocat_socket_flag_receive_none_e = 0x0, kt_tacocat_socket_flag_receive_control_e = 0x1, kt_tacocat_socket_flag_receive_packet_e = 0x2, - kt_tacocat_socket_flag_receive_check_e = 0x4, - kt_tacocat_socket_flag_receive_write_e = 0x8, - kt_tacocat_socket_flag_receive_done_e = 0x10, + kt_tacocat_socket_flag_receive_find_e = 0x4, + kt_tacocat_socket_flag_receive_check_e = 0x8, + kt_tacocat_socket_flag_receive_write_e = 0x10, + kt_tacocat_socket_flag_receive_done_e = 0x20, }; // enum #endif // _di_kt_tacocat_socket_flag_receive_e_ diff --git a/sources/c/tacocat/main/common/print.c b/sources/c/tacocat/main/common/print.c index 7596c25..0cb7f20 100644 --- a/sources/c/tacocat/main/common/print.c +++ b/sources/c/tacocat/main/common/print.c @@ -14,6 +14,7 @@ extern "C" { "f_file_seek", "f_file_size_by_id", "f_file_write", + "f_file_write_range", "f_fss_simple_packet_decode_range", "f_fss_simple_packet_encode", "f_memory_array_increase_by", diff --git a/sources/c/tacocat/main/common/print.h b/sources/c/tacocat/main/common/print.h index 9d1e8d1..b157657 100644 --- a/sources/c/tacocat/main/common/print.h +++ b/sources/c/tacocat/main/common/print.h @@ -47,6 +47,7 @@ extern "C" { kt_tacocat_f_f_file_seek_e, kt_tacocat_f_f_file_size_by_id_e, kt_tacocat_f_f_file_write_e, + kt_tacocat_f_f_file_write_range_e, kt_tacocat_f_f_fss_simple_packet_decode_range_e, kt_tacocat_f_f_fss_simple_packet_encode_e, kt_tacocat_f_f_memory_array_increase_by_e, diff --git a/sources/c/tacocat/main/print/error.c b/sources/c/tacocat/main/print/error.c index 6f2f538..633b5d8 100644 --- a/sources/c/tacocat/main/print/error.c +++ b/sources/c/tacocat/main/print/error.c @@ -174,8 +174,8 @@ extern "C" { } #endif // _di_kt_tacocat_print_error_on_packet_invalid_ -#ifndef _di_kt_tacocat_print_error_on_max_retries_ - f_status_t kt_tacocat_print_error_on_max_retries(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_string_static_t name) { +#ifndef _di_kt_tacocat_print_error_on_max_retries_receive_ + f_status_t kt_tacocat_print_error_on_max_retries_receive(fl_print_t * const print, kt_tacocat_socket_set_t * const set) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -183,18 +183,70 @@ extern "C" { f_file_stream_lock(print->to); fl_print_format("%[%QMax retry on failure reached while trying to%] ", print->to, print->set->error, print->prefix, print->set->error); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, on, print->set->notable); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, kt_tacocat_receive_s, print->set->notable); fl_print_format(" %[for '%]", print->to, print->set->error, print->set->error, f_string_eol_s); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, network, print->set->notable); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, set->network, print->set->notable); fl_print_format("%[' with file '%]", print->to, print->set->error, print->set->error, f_string_eol_s); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, name, print->set->notable); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, set->name, print->set->notable); + fl_print_format("%['", print->to, print->set->error); + + if (set->flag & kt_tacocat_socket_flag_receive_find_e) { + fl_print_format(" while trying to process the Packet headers", print->to); + } + + fl_print_format(".%]%r", print->to, print->set->error, f_string_eol_s); + + f_file_stream_unlock(print->to); + + return F_okay; + } +#endif // _di_kt_tacocat_print_error_on_max_retries_receive_ + +#ifndef _di_kt_tacocat_print_error_on_max_retries_send_ + f_status_t kt_tacocat_print_error_on_max_retries_send(fl_print_t * const print, kt_tacocat_socket_set_t * const set) { + + if (!print) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print->to); + + fl_print_format("%[%QMax retry on failure reached while trying to%] ", print->to, print->set->error, print->prefix, print->set->error); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, kt_tacocat_send_s, print->set->notable); + fl_print_format(" %[for '%]", print->to, print->set->error, print->set->error, f_string_eol_s); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, set->network, print->set->notable); + fl_print_format("%[' with file '%]", print->to, print->set->error, print->set->error, f_string_eol_s); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, set->name, print->set->notable); fl_print_format("%['.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s); f_file_stream_unlock(print->to); return F_okay; } -#endif // _di_kt_tacocat_print_error_on_max_retries_ +#endif // _di_kt_tacocat_print_error_on_max_retries_send_ + +#ifndef _di_kt_tacocat_print_error_on_packet_too_large_ + f_status_t kt_tacocat_print_error_on_packet_too_large(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got) { + + if (!print) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print->to); + + fl_print_format("%[%QNetwork on%] ", print->to, print->set->error, print->prefix, print->set->error); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, on, print->set->notable); + fl_print_format(" %[for '%]", print->to, print->set->error, print->set->error, f_string_eol_s); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, network, print->set->notable); + fl_print_format("%[', the received packet is too large (expecting%] ", print->to, print->set->error, print->set->error); + fl_print_format("%[%ul%]", print->to, print->set->notable, size_expect, print->set->notable); + fl_print_format(" %[bytes but instead got%] ", print->to, print->set->error, print->set->error, f_string_eol_s); + fl_print_format("%[%ul%]", print->to, print->set->notable, size_got, print->set->notable); + fl_print_format("%[ bytes).%]%r", print->to, print->set->error, print->set->error, f_string_eol_s); + + f_file_stream_unlock(print->to); + + return F_okay; + } +#endif // _di_kt_tacocat_print_error_on_packet_too_large_ #ifndef _di_kt_tacocat_print_error_on_packet_too_small_ f_status_t kt_tacocat_print_error_on_packet_too_small(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got) { diff --git a/sources/c/tacocat/main/print/error.h b/sources/c/tacocat/main/print/error.h index 0a3fc5c..342e77d 100644 --- a/sources/c/tacocat/main/print/error.h +++ b/sources/c/tacocat/main/print/error.h @@ -269,7 +269,7 @@ extern "C" { #endif // _di_kt_tacocat_print_error_on_packet_invalid_ /** - * Print error message regarding maximum retries after error reached. + * Print error message regarding maximum retries after error reached, when receiving. * * This could be on any error, such as errors on file load, memory, access, or network failures. * @@ -277,12 +277,66 @@ extern "C" { * The output structure to print to. * * This does not alter print.custom.setting.state.status. + * @param set + * The socket set to process. + * Must not be NULL. + * + * This does not alter set.status. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_kt_tacocat_print_error_on_max_retries_receive_ + extern f_status_t kt_tacocat_print_error_on_max_retries_receive(fl_print_t * const print, kt_tacocat_socket_set_t * const set); +#endif // _di_kt_tacocat_print_error_on_max_retries_receive_ + +/** + * Print error message regarding maximum retries after error reached, when sending. + * + * This could be on any error, such as errors on file load, memory, access, or network failures. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param set + * The socket set to process. + * Must not be NULL. + * + * This does not alter set.status. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_kt_tacocat_print_error_on_max_retries_send_ + extern f_status_t kt_tacocat_print_error_on_max_retries_send(fl_print_t * const print, kt_tacocat_socket_set_t * const set); +#endif // _di_kt_tacocat_print_error_on_max_retries_send_ + +/** + * Print network-related error message for when the packet is too large. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. * @param on * The network connection direction, which should either be "receive" or "send". * @param network * The name of the network in which the error is related. - * @param name - * Th name of the file. + * @param size_expect + * The expected buffer size. + * @param size_got + * The provided buffer size. * * @return * F_okay on success. @@ -292,12 +346,12 @@ extern "C" { * * @see fll_error_file_print() */ -#ifndef _di_kt_tacocat_print_error_on_max_retries_ - extern f_status_t kt_tacocat_print_error_on_max_retries(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_string_static_t name); -#endif // _di_kt_tacocat_print_error_on_max_retries_ +#ifndef _di_kt_tacocat_print_error_on_packet_too_large_ + extern f_status_t kt_tacocat_print_error_on_packet_too_large(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got); +#endif // _di_kt_tacocat_print_error_on_packet_too_large_ /** - * Print network-related error message for when the connection is busy. + * Print network-related error message for when the the packet is too small. * * @param print * The output structure to print to. diff --git a/sources/c/tacocat/main/receive.c b/sources/c/tacocat/main/receive.c index ace18ca..6f5fe7b 100644 --- a/sources/c/tacocat/main/receive.c +++ b/sources/c/tacocat/main/receive.c @@ -46,10 +46,13 @@ extern "C" { if (main->setting.receive.array[i].flag) { main->setting.receive.array[i].flag = 0; - --main->setting.active_receive; + + if (main->setting.active_receive) { + --main->setting.active_receive; + } } - kt_tacocat_print_error_on_max_retries(&main->program.error, kt_tacocat_receive_s, main->setting.receive.array[i].network, main->setting.receive.array[i].name); + kt_tacocat_print_error_on_max_retries_receive(&main->program.error, &main->setting.receive.array[i]); } // @todo if flag is kt_tacocat_socket_flag_receive_control_e, check if error is either F_packet_too_small or F_packet_too_large. This is a non-retrying error. @@ -65,10 +68,13 @@ extern "C" { if (main->setting.receive.array[i].flag) { main->setting.receive.array[i].flag = 0; - --main->setting.active_receive; + + if (main->setting.active_receive) { + --main->setting.active_receive; + } } - kt_tacocat_print_error_on_max_retries(&main->program.error, kt_tacocat_receive_s, main->setting.receive.array[i].network, main->setting.receive.array[i].name); + kt_tacocat_print_error_on_max_retries_receive(&main->program.error, &main->setting.receive.array[i]); } } } @@ -118,12 +124,14 @@ extern "C" { set->file.size_read = set->size_block; set->socket.size_read = kt_tacocat_packet_read_d; set->socket.id_data = -1; - set->range.start = -1; + set->range.start = 1; set->range.stop = 0; set->state.status = F_none; set->status = F_none; set->packet.control = 0; set->packet.size = 0; + set->packet.payload.start = 1; + set->packet.payload.stop = 0; set->flag = kt_tacocat_socket_flag_receive_control_e; ++main->setting.active_receive; @@ -135,9 +143,12 @@ extern "C" { // Keep error bit but set state to done to designate that nothing else is to be done. set->status = F_status_set_error(F_done); set->flag = 0; - --main->setting.active_receive; - kt_tacocat_print_error_on_max_retries(&main->program.error, kt_tacocat_receive_s, set->network, set->name); + if (main->setting.active_receive) { + --main->setting.active_receive; + } + + kt_tacocat_print_error_on_max_retries_receive(&main->program.error, set); return F_done; } @@ -147,56 +158,150 @@ extern "C" { kt_tacocat_receive_process_control(main, set); if (set->buffer.used < kt_tacocat_packet_peek_d || F_status_is_error(set->status)) { - --main->setting.active_receive; + if (main->setting.active_receive) { + --main->setting.active_receive; + } return F_done; } // Reset the buffer to allow for reusing and writing to the file in blocks. set->buffer.used = 0; - set->socket.size_read = kt_tacocat_packet_read_d; // Make sure the buffer is large enough for payload processing block reads. set->status = f_memory_array_increase_by(set->socket.size_read, sizeof(f_char_t), (void **) &set->buffer.string, &set->buffer.used, &set->buffer.size); macro_kt_receive_process_handle_error_exit_1(main, f_memory_array_increase_by, set->network, set->status, set->name, set->flag, &set->socket.id_data); set->retry = 0; + set->buffer.used = 0; set->flag = kt_tacocat_socket_flag_receive_packet_e; } if (set->flag & kt_tacocat_socket_flag_receive_packet_e) { size_t length_read = 0; - set->status = f_socket_read_stream(&set->socket, 0, (void *) set->buffer.string, &length_read); + set->status = f_socket_read_stream(&set->socket, 0, (void *) (set->buffer.string + set->buffer.used), &length_read); macro_kt_receive_process_handle_error_exit_1(main, f_socket_read_stream, set->network, set->status, set->name, set->flag, &set->socket.id_data); if (length_read) { set->retry = 0; set->buffer.used += length_read; - set->flag = kt_tacocat_socket_flag_receive_check_e; + + // This is not a valid packet if the actual size is greater than expected. + if (set->buffer.used > set->packet.size) { + kt_tacocat_print_error_on_packet_too_large(&main->program.error, kt_tacocat_receive_s, set->network, set->packet.size, set->buffer.used); + + set->status = F_status_set_error(F_packet_too_large); + + return F_done; + } + + // Initialize the range to start reading after the Control and Size blocks. + if (set->range.start > set->range.stop) { + set->range.start = F_fss_simple_packet_block_header_size_d; + } + + set->range.stop = set->buffer.used - 1; + set->flag = kt_tacocat_socket_flag_receive_find_e; } else { ++set->retry; } } - if (set->flag & kt_tacocat_socket_flag_receive_check_e) { - // @todo after payload, a headers, and a save step. The check step will be the FSS processing check and if the proper step is reached, then set another flag to designate that the payload start has been found, process the headers (another flag), - set->range.start = 0; - set->range.stop = set->buffer.used - 1; - set->state.status = F_none; + if (set->flag & kt_tacocat_socket_flag_receive_find_e) { + set->state.status = F_none; + + fll_fss_payload_read(set->buffer, &set->range, &set->objects, &set->contents, &set->objects_delimits, &set->contents_delimits, &set->comments, &set->state); + + // Note that F_fss_found_object_content_not is not treated as an error because the "payload" section is optional. + if (F_status_is_error(set->state.status) && F_status_set_fine(set->state.status) != F_fss_found_object_content_not) { + switch (F_status_set_fine(set->state.status)) { + case F_okay: + case F_okay_eos: + case F_okay_stop: - fll_fss_payload_read(set->buffer, &set->range, &set->objects, &set->contents, &set->objects_delimits, &set->contents_delimits, &set->comments, &set->state); + if (set->buffer.used == set->packet.size) { + + // The packet is fully loaded and there is no "payload" section. + set->flag = kt_tacocat_socket_flag_receive_check_e; + } + else { + + // Seek the left-most new line from the current position to ensure that the next pass potentially reads a complete line. + while (set->range.start && set->buffer.string[set->range.start] != f_string_eol_s.string[0]) { + + --set->range.start; + } // while + + // No packet is found and is not yet finished loading the data. + set->flag = kt_tacocat_socket_flag_receive_packet_e; + } - // @todo before writing the buffer to the file, attempt to read the header, keep appending to the current buffer until in memory matches "payload:". - // @todo if the entire header is not available, then set flag back to kt_tacocat_socket_flag_receive_packet_e. - //extern void fll_fss_payload_read(const f_string_static_t buffer, f_range_t * const range, f_ranges_t * const objects, f_rangess_t * const contents, f_number_unsigneds_t * const objects_delimits, f_number_unsigneds_t * const contents_delimits, f_ranges_t * const comments, f_state_t * const state); + break; - /*if (set->packet.payload.stop + 1 < set->packet.size) { - set->flag = kt_tacocat_socket_flag_receive_packet_e; + default: - return F_data_not; - }*/ + // Seek the left-most new line from the current position to ensure that the next pass potentially reads a complete line. + while (set->range.start && set->buffer.string[set->range.start] != f_string_eol_s.string[0]) { + + --set->range.start; + } // while + + if (set->buffer.used != set->packet.size) { + set->flag = kt_tacocat_socket_flag_receive_packet_e; + } + + ++set->retry; + + break; + } + } + else { + switch (F_status_set_fine(set->state.status)) { + case F_okay: + case F_okay_eos: + case F_okay_stop: + case F_data_not: + case F_data_not_eos: + case F_data_not_stop: + case F_fss_found_object_content_not: + set->flag = kt_tacocat_socket_flag_receive_check_e; + + break; + + default: + ++set->retry; + + break; + } + } + } + + if (set->flag & kt_tacocat_socket_flag_receive_check_e) { + + // @todo this probably should be in a separate function, similar to how kt_tacocat_receive_process_control() is. + { + uint8_t found_not = F_true; + + for (f_number_unsigned_t i = 0; i < set->objects.used; ++i) { + + if (f_compare_dynamic_partial_string(f_fss_payload_object_header_s.string, set->buffer, f_fss_payload_object_header_s.used, set->objects.array[i]) == F_equal_to) { + // @todo walk through header, mapping it. + } + else if (f_compare_dynamic_partial_string(f_fss_payload_object_signature_s.string, set->buffer, f_fss_payload_object_signature_s.used, set->objects.array[i]) == F_equal_to) { + // @todo walk through signature, mapping it. + } + else if (f_compare_dynamic_partial_string(f_fss_payload_object_payload_s.string, set->buffer, f_fss_payload_object_payload_s.used, set->objects.array[i]) == F_equal_to) { + if (found_not) { + set->packet.payload = set->contents.array[i].array[0]; + found_not = F_false; + } + } + } // for + } + + // @todo walk through each set->objects and their respective set->contents, checking and processing the data. set->flag = kt_tacocat_socket_flag_receive_write_e; } @@ -210,22 +315,18 @@ extern "C" { return F_done_not; // @todo consider sending a file error to caller. This should not infinitely attempt to open on failure. } - // @todo write only the Payload. - set->status = f_file_write(set->file, set->buffer, 0); + set->status = f_file_write_range(set->file, set->buffer, set->packet.payload, 0); // Keep going on error, but in the future more advanced error handling/recovery is needed to make this more robust. if (F_status_is_error(set->status)) { f_file_close(&set->file); - kt_tacocat_print_error_on_file_receive(&main->program.error, macro_kt_tacocat_f(f_file_write), kt_tacocat_receive_s, set->network, set->status, set->name, f_file_operation_write_s); + kt_tacocat_print_error_on_file_receive(&main->program.error, macro_kt_tacocat_f(f_file_write_range), kt_tacocat_receive_s, set->network, set->status, set->name, f_file_operation_write_s); } - // Reset buffer used and increment counter. - set->packet.payload.stop += set->buffer.used; - set->buffer.used = 0; - f_file_close(&set->file); + set->buffer.used = 0; set->flag = kt_tacocat_socket_flag_receive_done_e; } @@ -237,7 +338,10 @@ extern "C" { set->flag = 0; set->status = F_okay; - --main->setting.active_receive; + + if (main->setting.active_receive) { + --main->setting.active_receive; + } if (set->buffer.size > kt_tacocat_max_maintain_d) { set->buffer.used = 0; @@ -275,7 +379,7 @@ extern "C" { set->socket.size_read = kt_tacocat_packet_peek_d; - set->status = f_socket_read_stream(&set->socket, 0, (void *) (set->buffer.string + set->buffer.used), &length_read); + set->status = f_socket_read_stream(&set->socket, f_socket_flag_peek_e, (void *) (set->buffer.string + set->buffer.used), &length_read); set->socket.size_read = size_read; @@ -351,12 +455,6 @@ extern "C" { return; } - set->flag = kt_tacocat_socket_flag_receive_packet_e; - - // The payload range "stop" is used to represent the total amount of bytes processed so far (uncluding the header). - set->packet.payload.start = 0; - set->packet.payload.stop = set->buffer.used - 1; - kt_tacocat_print_message_receive_operation_control_size(&main->program.message, *set); } #endif // _di_kt_tacocat_receive_process_control_ diff --git a/sources/c/tacocat/main/receive.h b/sources/c/tacocat/main/receive.h index a04d60f..d1e79ac 100644 --- a/sources/c/tacocat/main/receive.h +++ b/sources/c/tacocat/main/receive.h @@ -48,9 +48,18 @@ extern "C" { * This alters set.status: * F_okay on success. * + * F_done (with error bit) on too many retries. + * F_packet_too_small (with error bit) on total packet size is too small. * F_packet_too_large (with error bit) on total packet size is too large. * F_payload_too_large (with error bit) on total payload size is too large. * + * Errors (with error bit) from: f_file_open(). + * Errors (with error bit) from: f_file_write(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * Errors (with error bit) from: f_socket_read_stream(). + * Errors (with error bit) from: kt_tacocat_receive_process_control(). + * * @see f_socket_read_stream() */ #ifndef _di_kt_tacocat_receive_process_ diff --git a/sources/c/tacocat/main/send.c b/sources/c/tacocat/main/send.c index 6e7643b..bd4bac8 100644 --- a/sources/c/tacocat/main/send.c +++ b/sources/c/tacocat/main/send.c @@ -149,7 +149,14 @@ extern "C" { // Index 6 is the salt. set->abstruses.array[6].key = kt_tacocat_salt_s; set->abstruses.array[6].value.type = f_abstruse_unsigned_e; - set->abstruses.array[6].value.is.a_unsigned = random(); + + { + long salt = 0; + + f_random_get(&salt); + + set->abstruses.array[6].value.is.a_unsigned = (f_number_unsigned_t) salt; + } set->abstruses.used = 7; @@ -166,7 +173,7 @@ extern "C" { // Keep error bit but set state to done to designate that nothing else is to be done. set->status = F_status_set_error(F_done); - kt_tacocat_print_error_on_max_retries(&main->program.error, kt_tacocat_send_s, set->network, set->name); + kt_tacocat_print_error_on_max_retries_send(&main->program.error, set); return F_done; } diff --git a/sources/c/tacocat/main/tacocat.c b/sources/c/tacocat/main/tacocat.c index 4ff0112..734af51 100644 --- a/sources/c/tacocat/main/tacocat.c +++ b/sources/c/tacocat/main/tacocat.c @@ -39,7 +39,7 @@ extern "C" { return; } - main->setting.state.status = f_random_seed(GRND_NONBLOCK); + main->setting.state.status = f_random_seed(F_random_seed_flag_block_not_d); // Try again, but only once if blocked. if (main->setting.state.status == F_status_set_error(F_again)) { @@ -49,7 +49,7 @@ extern "C" { nanosleep(&time, 0); } - main->setting.state.status = f_random_seed(GRND_NONBLOCK); + main->setting.state.status = f_random_seed(F_random_seed_flag_block_not_d); } if (F_status_is_error(main->setting.state.status)) { -- 1.8.3.1