mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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:
parent
aaaeac8f3d
commit
69c8da64cf
|
@ -84,16 +84,19 @@ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t
|
||||||
|
|
||||||
uint32_t file_sent;
|
uint32_t file_sent;
|
||||||
uint32_t sendf_ok;
|
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)
|
const uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
if (*((uint32_t *)userdata) != 974536)
|
if (*((uint32_t *)userdata) != 974536)
|
||||||
return;
|
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;
|
file_sent = 1;
|
||||||
|
|
||||||
if (send_recieve == 1 && control_type == TOX_FILECONTROL_ACCEPT)
|
if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT)
|
||||||
sendf_ok = 1;
|
sendf_ok = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1486,9 +1486,11 @@ int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILECONTROL_KILL:
|
case FILECONTROL_KILL:
|
||||||
case FILECONTROL_FINISHED:
|
|
||||||
m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
|
m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FILECONTROL_FINISHED:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1609,8 +1611,9 @@ static int handle_filecontrol(const Messenger *m, int32_t friendnumber, uint8_t
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
case FILECONTROL_KILL:
|
case FILECONTROL_KILL:
|
||||||
case FILECONTROL_FINISHED:
|
|
||||||
m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
|
m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
|
||||||
|
|
||||||
|
case FILECONTROL_FINISHED:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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
|
* 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(...)
|
* 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
|
* 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:
|
* HOW TO RECEIVE FILES CORRECTLY:
|
||||||
* 1. wait for the callback set with tox_callback_file_send_request(...)
|
* 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.
|
* 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
|
* 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.
|
* 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.
|
* tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user