From 69c8da64cf384e13a42efda46b1c3f86d0bb6bd1 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 4 Aug 2014 15:18:18 -0400 Subject: [PATCH] The receiver of a file now needs to confirm that he did receive it correctly. This should fix an issue that happened when both clients got disconnected when the file was almost finished sending. The sender would show that the file had been sent successfully when it had not. See the modifications to tox.h --- auto_tests/tox_test.c | 9 ++++++--- toxcore/Messenger.c | 7 +++++-- toxcore/tox.h | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 8d4d6c4b..43fb7a1c 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -84,16 +84,19 @@ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t uint32_t file_sent; uint32_t sendf_ok; -void file_print_control(Tox *m, int friendnumber, uint8_t send_recieve, uint8_t filenumber, uint8_t control_type, +void file_print_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) return; - if (send_recieve == 0 && control_type == TOX_FILECONTROL_FINISHED) + if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED) + tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0); + + if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED) file_sent = 1; - if (send_recieve == 1 && control_type == TOX_FILECONTROL_ACCEPT) + if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT) sendf_ok = 1; } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b65f09ae..5212b9c5 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1486,9 +1486,11 @@ int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive, break; case FILECONTROL_KILL: - case FILECONTROL_FINISHED: m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE; break; + + case FILECONTROL_FINISHED: + break; } return 0; @@ -1609,8 +1611,9 @@ static int handle_filecontrol(const Messenger *m, int32_t friendnumber, uint8_t return -1; case FILECONTROL_KILL: - case FILECONTROL_FINISHED: m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE; + + case FILECONTROL_FINISHED: return 0; } } else { diff --git a/toxcore/tox.h b/toxcore/tox.h index 39beb004..8caa01e0 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -488,6 +488,8 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT * 3. Send the data with tox_file_send_data(...) with chunk size tox_file_data_size(...) * 4. When sending is done, send a tox_file_send_control(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED + * 5. when the callback set with tox_callback_file_control(...) is called with receive_send == 1 and control_type == TOX_FILECONTROL_FINISHED + * the other person has received the file correctly. * * HOW TO RECEIVE FILES CORRECTLY: * 1. wait for the callback set with tox_callback_file_send_request(...) @@ -495,6 +497,7 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); * 3. save all the data received with the callback set with tox_callback_file_data(...) to a file. * 4. when the callback set with tox_callback_file_control(...) is called with receive_send == 0 and control_type == TOX_FILECONTROL_FINISHED * the file is done transferring. + * 5. send a tox_file_send_control(...) with send_receive = 1 and message_id = TOX_FILECONTROL_FINISHED to confirm that we did receive the file. * * tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive. *