diff options
author | irungentoo <irungentoo@gmail.com> | 2014-08-04 15:18:18 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-08-04 15:18:18 -0400 |
commit | 69c8da64cf384e13a42efda46b1c3f86d0bb6bd1 (patch) | |
tree | 678c5472163e5dc970cb2393de7845b9347016a2 | |
parent | aaaeac8f3d66d2888430b4c30b58f26e9f0e1011 (diff) |
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
-rw-r--r-- | auto_tests/tox_test.c | 9 | ||||
-rw-r--r-- | toxcore/Messenger.c | 7 | ||||
-rw-r--r-- | 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 | |||
84 | 84 | ||
85 | uint32_t file_sent; | 85 | uint32_t file_sent; |
86 | uint32_t sendf_ok; | 86 | uint32_t sendf_ok; |
87 | void file_print_control(Tox *m, int friendnumber, uint8_t send_recieve, uint8_t filenumber, uint8_t control_type, | 87 | void file_print_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, |
88 | const uint8_t *data, uint16_t length, void *userdata) | 88 | const uint8_t *data, uint16_t length, void *userdata) |
89 | { | 89 | { |
90 | if (*((uint32_t *)userdata) != 974536) | 90 | if (*((uint32_t *)userdata) != 974536) |
91 | return; | 91 | return; |
92 | 92 | ||
93 | if (send_recieve == 0 && control_type == TOX_FILECONTROL_FINISHED) | 93 | if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED) |
94 | tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0); | ||
95 | |||
96 | if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED) | ||
94 | file_sent = 1; | 97 | file_sent = 1; |
95 | 98 | ||
96 | if (send_recieve == 1 && control_type == TOX_FILECONTROL_ACCEPT) | 99 | if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT) |
97 | sendf_ok = 1; | 100 | sendf_ok = 1; |
98 | 101 | ||
99 | } | 102 | } |
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, | |||
1486 | break; | 1486 | break; |
1487 | 1487 | ||
1488 | case FILECONTROL_KILL: | 1488 | case FILECONTROL_KILL: |
1489 | case FILECONTROL_FINISHED: | ||
1490 | m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE; | 1489 | m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE; |
1491 | break; | 1490 | break; |
1491 | |||
1492 | case FILECONTROL_FINISHED: | ||
1493 | break; | ||
1492 | } | 1494 | } |
1493 | 1495 | ||
1494 | return 0; | 1496 | return 0; |
@@ -1609,8 +1611,9 @@ static int handle_filecontrol(const Messenger *m, int32_t friendnumber, uint8_t | |||
1609 | return -1; | 1611 | return -1; |
1610 | 1612 | ||
1611 | case FILECONTROL_KILL: | 1613 | case FILECONTROL_KILL: |
1612 | case FILECONTROL_FINISHED: | ||
1613 | m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE; | 1614 | m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE; |
1615 | |||
1616 | case FILECONTROL_FINISHED: | ||
1614 | return 0; | 1617 | return 0; |
1615 | } | 1618 | } |
1616 | } else { | 1619 | } 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); | |||
488 | * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT | 488 | * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT |
489 | * 3. Send the data with tox_file_send_data(...) with chunk size tox_file_data_size(...) | 489 | * 3. Send the data with tox_file_send_data(...) with chunk size tox_file_data_size(...) |
490 | * 4. When sending is done, send a tox_file_send_control(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED | 490 | * 4. When sending is done, send a tox_file_send_control(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED |
491 | * 5. when the callback set with tox_callback_file_control(...) is called with receive_send == 1 and control_type == TOX_FILECONTROL_FINISHED | ||
492 | * the other person has received the file correctly. | ||
491 | * | 493 | * |
492 | * HOW TO RECEIVE FILES CORRECTLY: | 494 | * HOW TO RECEIVE FILES CORRECTLY: |
493 | * 1. wait for the callback set with tox_callback_file_send_request(...) | 495 | * 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); | |||
495 | * 3. save all the data received with the callback set with tox_callback_file_data(...) to a file. | 497 | * 3. save all the data received with the callback set with tox_callback_file_data(...) to a file. |
496 | * 4. when the callback set with tox_callback_file_control(...) is called with receive_send == 0 and control_type == TOX_FILECONTROL_FINISHED | 498 | * 4. when the callback set with tox_callback_file_control(...) is called with receive_send == 0 and control_type == TOX_FILECONTROL_FINISHED |
497 | * the file is done transferring. | 499 | * the file is done transferring. |
500 | * 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. | ||
498 | * | 501 | * |
499 | * tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive. | 502 | * tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive. |
500 | * | 503 | * |