mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Transfers with filelength == 0 now behave exactly like transfers of every
other size (except streaming of course).
This commit is contained in:
parent
f2a017c055
commit
8c2347222a
|
@ -145,16 +145,21 @@ void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, ui
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size = filesize;
|
file_size = filesize;
|
||||||
sending_pos = size_recv = 1337;
|
|
||||||
|
|
||||||
TOX_ERR_FILE_SEEK err_s;
|
if (filesize) {
|
||||||
|
sending_pos = size_recv = 1337;
|
||||||
|
|
||||||
if (!tox_file_send_seek(tox, friend_number, file_number, 1337, &err_s)) {
|
TOX_ERR_FILE_SEEK err_s;
|
||||||
ck_abort_msg("tox_file_send_seek error");
|
|
||||||
|
if (!tox_file_send_seek(tox, friend_number, file_number, 1337, &err_s)) {
|
||||||
|
ck_abort_msg("tox_file_send_seek error");
|
||||||
|
}
|
||||||
|
|
||||||
|
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_OK, "tox_file_send_seek wrong error");
|
||||||
|
} else {
|
||||||
|
sending_pos = size_recv = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_OK, "tox_file_send_seek wrong error");
|
|
||||||
|
|
||||||
TOX_ERR_FILE_CONTROL error;
|
TOX_ERR_FILE_CONTROL error;
|
||||||
|
|
||||||
if (tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error)) {
|
if (tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error)) {
|
||||||
|
@ -163,6 +168,8 @@ void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, ui
|
||||||
ck_abort_msg("tox_file_send_control failed. %i", error);
|
ck_abort_msg("tox_file_send_control failed. %i", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TOX_ERR_FILE_SEEK err_s;
|
||||||
|
|
||||||
if (tox_file_send_seek(tox, friend_number, file_number, 1234, &err_s)) {
|
if (tox_file_send_seek(tox, friend_number, file_number, 1234, &err_s)) {
|
||||||
ck_abort_msg("tox_file_send_seek no error");
|
ck_abort_msg("tox_file_send_seek no error");
|
||||||
}
|
}
|
||||||
|
@ -593,11 +600,13 @@ START_TEST(test_few_clients)
|
||||||
tox_iterate(tox3);
|
tox_iterate(tox3);
|
||||||
|
|
||||||
if (file_sending_done) {
|
if (file_sending_done) {
|
||||||
if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv) {
|
if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
|
||||||
|
&& file_accepted == 1) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
|
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
|
||||||
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, totalf_size, size_recv, sending_pos);
|
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
|
||||||
|
sending_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,11 +653,12 @@ START_TEST(test_few_clients)
|
||||||
|
|
||||||
if (file_sending_done) {
|
if (file_sending_done) {
|
||||||
if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
|
if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
|
||||||
&& sending_pos == size_recv) {
|
&& sending_pos == size_recv && file_accepted == 1) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
|
ck_abort_msg("Something went wrong in file transfer %u %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,
|
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
|
||||||
|
totalf_size, file_size,
|
||||||
size_recv, sending_pos);
|
size_recv, sending_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -664,6 +674,54 @@ START_TEST(test_few_clients)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Starting file 0 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 = 0;
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
tox_iterate(tox1);
|
||||||
|
tox_iterate(tox2);
|
||||||
|
tox_iterate(tox3);
|
||||||
|
|
||||||
|
if (file_sending_done) {
|
||||||
|
if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
|
||||||
|
&& file_accepted == 1) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
|
||||||
|
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_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);
|
printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
|
||||||
|
|
||||||
tox_kill(tox1);
|
tox_kill(tox1);
|
||||||
|
|
|
@ -1091,7 +1091,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
|
||||||
* return -2 if filename length invalid.
|
* return -2 if filename length invalid.
|
||||||
* return -3 if no more file sending slots left.
|
* return -3 if no more file sending slots left.
|
||||||
* return -4 if could not send packet (friend offline).
|
* return -4 if could not send packet (friend offline).
|
||||||
* return -5 if succesfully sent file send request with filesize 0.
|
*
|
||||||
*/
|
*/
|
||||||
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
||||||
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
|
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
|
||||||
|
@ -1115,22 +1115,18 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
|
||||||
if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0)
|
if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0)
|
||||||
return -4;
|
return -4;
|
||||||
|
|
||||||
/* Only init file if filesize isn't 0. */
|
struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
|
||||||
if (filesize) {
|
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||||
struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
|
ft->size = filesize;
|
||||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
ft->transferred = 0;
|
||||||
ft->size = filesize;
|
ft->requested = 0;
|
||||||
ft->transferred = 0;
|
ft->slots_allocated = 0;
|
||||||
ft->requested = 0;
|
ft->paused = FILE_PAUSE_NOT;
|
||||||
ft->slots_allocated = 0;
|
memcpy(ft->id, file_id, FILE_ID_LENGTH);
|
||||||
ft->paused = FILE_PAUSE_NOT;
|
|
||||||
memcpy(ft->id, file_id, FILE_ID_LENGTH);
|
|
||||||
|
|
||||||
++m->friendlist[friendnumber].num_sending_files;
|
++m->friendlist[friendnumber].num_sending_files;
|
||||||
return i;
|
|
||||||
} else {
|
return i;
|
||||||
return -5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber,
|
int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber,
|
||||||
|
@ -1473,6 +1469,12 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
|
||||||
|
|
||||||
uint16_t length = MAX_FILE_DATA_SIZE;
|
uint16_t length = MAX_FILE_DATA_SIZE;
|
||||||
|
|
||||||
|
if (ft->size == 0) {
|
||||||
|
/* Send 0 data to friend if file is 0 length. */
|
||||||
|
file_data(m, friendnumber, i, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (ft->size == ft->requested) {
|
if (ft->size == ft->requested) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2051,20 +2053,11 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
||||||
if (ft->status != FILESTATUS_NONE)
|
if (ft->status != FILESTATUS_NONE)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
uint32_t real_filenumber = UINT32_MAX;
|
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||||
|
ft->size = filesize;
|
||||||
if (filesize) {
|
ft->transferred = 0;
|
||||||
/* Don't */
|
ft->paused = FILE_PAUSE_NOT;
|
||||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
||||||
ft->size = filesize;
|
|
||||||
ft->transferred = 0;
|
|
||||||
ft->paused = FILE_PAUSE_NOT;
|
|
||||||
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
|
||||||
|
|
||||||
real_filenumber = filenumber;
|
|
||||||
real_filenumber += 1;
|
|
||||||
real_filenumber <<= 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t filename_terminated[filename_length + 1];
|
uint8_t filename_terminated[filename_length + 1];
|
||||||
uint8_t *filename = NULL;
|
uint8_t *filename = NULL;
|
||||||
|
@ -2076,6 +2069,9 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
||||||
filename = filename_terminated;
|
filename = filename_terminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t real_filenumber = filenumber;
|
||||||
|
real_filenumber += 1;
|
||||||
|
real_filenumber <<= 16;
|
||||||
|
|
||||||
if (m->file_sendrequest)
|
if (m->file_sendrequest)
|
||||||
(*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length,
|
(*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length,
|
||||||
|
@ -2099,13 +2095,13 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
case PACKET_ID_FILE_DATA: {
|
case PACKET_ID_FILE_DATA: {
|
||||||
if (data_length <= 1)
|
if (data_length < 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
uint8_t filenumber = data[0];
|
uint8_t filenumber = data[0];
|
||||||
struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
|
struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
|
||||||
|
|
||||||
if (ft->status == FILESTATUS_NONE)
|
if (ft->status != FILESTATUS_TRANSFERRING)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
uint64_t position = ft->transferred;
|
uint64_t position = ft->transferred;
|
||||||
|
@ -2126,7 +2122,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
||||||
|
|
||||||
ft->transferred += file_data_length;
|
ft->transferred += file_data_length;
|
||||||
|
|
||||||
if (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE) {
|
if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) {
|
||||||
file_data_length = 0;
|
file_data_length = 0;
|
||||||
file_data = NULL;
|
file_data = NULL;
|
||||||
position = ft->transferred;
|
position = ft->transferred;
|
||||||
|
|
|
@ -618,7 +618,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
|
||||||
* return -2 if filename length invalid.
|
* return -2 if filename length invalid.
|
||||||
* return -3 if no more file sending slots left.
|
* return -3 if no more file sending slots left.
|
||||||
* return -4 if could not send packet (friend offline).
|
* return -4 if could not send packet (friend offline).
|
||||||
* return -5 if succesfully sent file send request with filesize 0.
|
*
|
||||||
*/
|
*/
|
||||||
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
||||||
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
|
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
|
||||||
|
|
|
@ -1000,10 +1000,6 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
|
||||||
case -4:
|
case -4:
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED);
|
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED);
|
||||||
return UINT32_MAX;
|
return UINT32_MAX;
|
||||||
|
|
||||||
case -5:
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK_ZERO_LENGTH);
|
|
||||||
return UINT32_MAX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* can't happen */
|
/* can't happen */
|
||||||
|
|
|
@ -1610,12 +1610,7 @@ typedef enum TOX_ERR_FILE_SEND {
|
||||||
* Too many ongoing transfers. The maximum number of concurrent file transfers
|
* Too many ongoing transfers. The maximum number of concurrent file transfers
|
||||||
* is 256 per friend per direction (sending and receiving).
|
* is 256 per friend per direction (sending and receiving).
|
||||||
*/
|
*/
|
||||||
TOX_ERR_FILE_SEND_TOO_MANY,
|
TOX_ERR_FILE_SEND_TOO_MANY
|
||||||
/**
|
|
||||||
* A file request packet was successfully sent to the friend however since it was zero
|
|
||||||
* length, no file number was allocated for the file transfer.
|
|
||||||
*/
|
|
||||||
TOX_ERR_FILE_SEND_OK_ZERO_LENGTH
|
|
||||||
} TOX_ERR_FILE_SEND;
|
} TOX_ERR_FILE_SEND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1634,9 +1629,6 @@ typedef enum TOX_ERR_FILE_SEND {
|
||||||
* When a friend goes offline, all file transfers associated with the friend are
|
* When a friend goes offline, all file transfers associated with the friend are
|
||||||
* purged from core.
|
* purged from core.
|
||||||
*
|
*
|
||||||
* if file_size is 0, this function will not allocate a file transfer in core and so
|
|
||||||
* will not return a valid file number however it will send a file request packet.
|
|
||||||
*
|
|
||||||
* If the file contents change during a transfer, the behaviour is unspecified
|
* If the file contents change during a transfer, the behaviour is unspecified
|
||||||
* in general. What will actually happen depends on the mode in which the file
|
* in general. What will actually happen depends on the mode in which the file
|
||||||
* was modified and how the client determines the file size.
|
* was modified and how the client determines the file size.
|
||||||
|
@ -1787,8 +1779,6 @@ void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *functi
|
||||||
* control command before any other control commands. It can be accepted by
|
* control command before any other control commands. It can be accepted by
|
||||||
* sending TOX_FILE_CONTROL_RESUME.
|
* sending TOX_FILE_CONTROL_RESUME.
|
||||||
*
|
*
|
||||||
* If file_size is zero, the file_number is invalid and should be ignored.
|
|
||||||
*
|
|
||||||
* @param friend_number The friend number of the friend who is sending the file
|
* @param friend_number The friend number of the friend who is sending the file
|
||||||
* transfer request.
|
* transfer request.
|
||||||
* @param file_number The friend-specific file number the data received is
|
* @param file_number The friend-specific file number the data received is
|
||||||
|
|
Loading…
Reference in New Issue
Block a user