mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
For file transfers UINT64_MAX is now used as the size for streaming
transfers instead of 0. For avatar transfers file size 0 now means that the client has no avatar set. Added a test for streaming transfers.
This commit is contained in:
parent
8c18dd42a7
commit
b1ec157175
|
@ -182,6 +182,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number,
|
|||
sendf_ok = 1;
|
||||
}
|
||||
|
||||
uint64_t max_sending;
|
||||
_Bool m_send_reached;
|
||||
uint8_t sending_num;
|
||||
_Bool file_sending_done;
|
||||
void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length,
|
||||
|
@ -204,6 +206,15 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb
|
|||
return;
|
||||
}
|
||||
|
||||
if (position + length > max_sending) {
|
||||
if (m_send_reached) {
|
||||
ck_abort_msg("Requested done file tranfer.");
|
||||
}
|
||||
|
||||
length = max_sending - position;
|
||||
m_send_reached = 1;
|
||||
}
|
||||
|
||||
TOX_ERR_FILE_SEND_CHUNK error;
|
||||
uint8_t f_data[length];
|
||||
memset(f_data, sending_num, length);
|
||||
|
@ -552,6 +563,7 @@ START_TEST(test_few_clients)
|
|||
printf("Starting file transfer test.\n");
|
||||
|
||||
file_accepted = file_size = file_recv = sendf_ok = size_recv = 0;
|
||||
max_sending = UINT64_MAX;
|
||||
long long unsigned int f_time = time(NULL);
|
||||
tox_callback_file_recv_chunk(tox3, write_file, &to_compare);
|
||||
tox_callback_file_recv_control(tox2, file_print_control, &to_compare);
|
||||
|
@ -598,6 +610,56 @@ START_TEST(test_few_clients)
|
|||
|
||||
printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
|
||||
|
||||
printf("Starting file streaming transfer test.\n");
|
||||
|
||||
file_sending_done = file_accepted = file_size = file_recv = sendf_ok = size_recv = 0;
|
||||
f_time = time(NULL);
|
||||
tox_callback_file_recv_chunk(tox3, write_file, &to_compare);
|
||||
tox_callback_file_recv_control(tox2, file_print_control, &to_compare);
|
||||
tox_callback_file_chunk_request(tox2, tox_file_chunk_request, &to_compare);
|
||||
tox_callback_file_recv_control(tox3, file_print_control, &to_compare);
|
||||
tox_callback_file_recv(tox3, tox_file_receive, &to_compare);
|
||||
totalf_size = UINT64_MAX;
|
||||
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0);
|
||||
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
|
||||
|
||||
ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
|
||||
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, "wrong error");
|
||||
ck_assert_msg(!tox_file_get_file_id(tox2, 0, fnum + 1, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
|
||||
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_NOT_FOUND, "wrong error");
|
||||
ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
|
||||
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
|
||||
|
||||
max_sending = 100 * 1024;
|
||||
m_send_reached = 0;
|
||||
|
||||
while (1) {
|
||||
tox_iterate(tox1);
|
||||
tox_iterate(tox2);
|
||||
tox_iterate(tox3);
|
||||
|
||||
if (file_sending_done) {
|
||||
if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
|
||||
&& sending_pos == size_recv) {
|
||||
break;
|
||||
} else {
|
||||
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
|
||||
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, totalf_size, file_size,
|
||||
size_recv, sending_pos);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t tox1_interval = tox_iteration_interval(tox1);
|
||||
uint32_t tox2_interval = tox_iteration_interval(tox2);
|
||||
uint32_t tox3_interval = tox_iteration_interval(tox3);
|
||||
|
||||
if (tox2_interval > tox3_interval) {
|
||||
c_sleep(tox3_interval);
|
||||
} else {
|
||||
c_sleep(tox2_interval);
|
||||
}
|
||||
}
|
||||
|
||||
printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
|
||||
|
||||
tox_kill(tox1);
|
||||
|
|
|
@ -1282,7 +1282,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
|
|||
if (ft->status != FILESTATUS_NOT_ACCEPTED)
|
||||
return -5;
|
||||
|
||||
if (ft->size && position > ft->size) {
|
||||
if (position > ft->size) {
|
||||
return -6;
|
||||
}
|
||||
|
||||
|
@ -1356,14 +1356,12 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
|
|||
if (length > MAX_FILE_DATA_SIZE)
|
||||
return -5;
|
||||
|
||||
if (ft->size) {
|
||||
if (ft->size - ft->transferred < length) {
|
||||
return -5;
|
||||
}
|
||||
if (ft->size - ft->transferred < length) {
|
||||
return -5;
|
||||
}
|
||||
|
||||
if (length != MAX_FILE_DATA_SIZE && (ft->transferred + length) != ft->size) {
|
||||
return -5;
|
||||
}
|
||||
if (ft->size != UINT64_MAX && length != MAX_FILE_DATA_SIZE && (ft->transferred + length) != ft->size) {
|
||||
return -5;
|
||||
}
|
||||
|
||||
if (position != ft->transferred) {
|
||||
|
@ -1471,14 +1469,12 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
|
|||
|
||||
uint16_t length = MAX_FILE_DATA_SIZE;
|
||||
|
||||
if (ft->size) {
|
||||
if (ft->size == ft->requested) {
|
||||
break;
|
||||
}
|
||||
if (ft->size == ft->requested) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ft->size - ft->requested < length) {
|
||||
length = ft->size - ft->requested;
|
||||
}
|
||||
if (ft->size - ft->requested < length) {
|
||||
length = ft->size - ft->requested;
|
||||
}
|
||||
|
||||
++ft->slots_allocated;
|
||||
|
@ -1586,7 +1582,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
|
|||
memcpy(&position, data, sizeof(position));
|
||||
net_to_host((uint8_t *) &position, sizeof(position));
|
||||
|
||||
if (ft->size && position > ft->size) {
|
||||
if (position > ft->size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2117,7 +2113,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
|||
|
||||
ft->transferred += file_data_length;
|
||||
|
||||
if ((ft->size && ft->transferred >= ft->size) || file_data_length != MAX_FILE_DATA_SIZE) {
|
||||
if (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE) {
|
||||
file_data_length = 0;
|
||||
file_data = NULL;
|
||||
position = ft->transferred;
|
||||
|
|
|
@ -1395,6 +1395,9 @@ enum TOX_FILE_KIND {
|
|||
* (same length as TOX_FILE_ID_LENGTH) will contain the hash. A client can compare
|
||||
* this hash with a saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar
|
||||
* transfer if it matches.
|
||||
*
|
||||
* When file_size is set to 0 in the transfer request it means that the client has no
|
||||
* avatar.
|
||||
*/
|
||||
TOX_FILE_KIND_AVATAR
|
||||
};
|
||||
|
@ -1631,9 +1634,9 @@ typedef enum TOX_ERR_FILE_SEND {
|
|||
* was modified and how the client determines the file size.
|
||||
*
|
||||
* - If the file size was increased
|
||||
* - and sending mode was streaming (file_size = 0), the behaviour will be as
|
||||
* - and sending mode was streaming (file_size = UINT64_MAX), the behaviour will be as
|
||||
* expected.
|
||||
* - and sending mode was file (file_size != 0), the file_chunk_request
|
||||
* - and sending mode was file (file_size != UINT64_MAX), the file_chunk_request
|
||||
* callback will receive length = 0 when Core thinks the file transfer has
|
||||
* finished. If the client remembers the file size as it was when sending
|
||||
* the request, it will terminate the transfer normally. If the client
|
||||
|
@ -1654,7 +1657,7 @@ typedef enum TOX_ERR_FILE_SEND {
|
|||
* @param friend_number The friend number of the friend the file send request
|
||||
* should be sent to.
|
||||
* @param kind The meaning of the file to be sent.
|
||||
* @param file_size Size in bytes of the file the client wants to send, 0 if
|
||||
* @param file_size Size in bytes of the file the client wants to send, UINT64_MAX if
|
||||
* unknown or streaming.
|
||||
* @param file_id A file identifier of length TOX_FILE_ID_LENGTH that can be used to
|
||||
* uniquely identify file transfers across core restarts. If NULL, a random one will
|
||||
|
@ -1804,7 +1807,7 @@ void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *function, void *user_dat
|
|||
*
|
||||
* If position is equal to file_size (received in the file_receive callback)
|
||||
* when the transfer finishes, the file was received completely. Otherwise, if
|
||||
* file_size was 0, streaming ended successfully when length is 0.
|
||||
* file_size was UINT64_MAX, streaming ended successfully when length is 0.
|
||||
*
|
||||
* @param friend_number The friend number of the friend who is sending the file.
|
||||
* @param file_number The friend-specific file number the data received is
|
||||
|
|
Loading…
Reference in New Issue
Block a user