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
This commit is contained in:
irungentoo 2014-08-04 15:18:18 -04:00
parent aaaeac8f3d
commit 69c8da64cf
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 14 additions and 5 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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.
*