diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-21 08:35:31 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-21 08:35:31 -0400 |
commit | 8c2347222a1f5ecb19c20a8dfcefbeff66fcb848 (patch) | |
tree | 4d11bfeb91c7c11484baad5b23b54004106af8ac /toxcore | |
parent | f2a017c055a8670d3bdbea2610455b45261a334e (diff) |
Transfers with filelength == 0 now behave exactly like transfers of every
other size (except streaming of course).
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 64 | ||||
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/tox.c | 4 | ||||
-rw-r--r-- | toxcore/tox.h | 12 |
4 files changed, 32 insertions, 50 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index ac3c2752..265ff80b 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1091,7 +1091,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi | |||
1091 | * return -2 if filename length invalid. | 1091 | * return -2 if filename length invalid. |
1092 | * return -3 if no more file sending slots left. | 1092 | * return -3 if no more file sending slots left. |
1093 | * return -4 if could not send packet (friend offline). | 1093 | * return -4 if could not send packet (friend offline). |
1094 | * return -5 if succesfully sent file send request with filesize 0. | 1094 | * |
1095 | */ | 1095 | */ |
1096 | long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, | 1096 | long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, |
1097 | const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) | 1097 | 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_ | |||
1115 | if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0) | 1115 | if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0) |
1116 | return -4; | 1116 | return -4; |
1117 | 1117 | ||
1118 | /* Only init file if filesize isn't 0. */ | 1118 | struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i]; |
1119 | if (filesize) { | 1119 | ft->status = FILESTATUS_NOT_ACCEPTED; |
1120 | struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i]; | 1120 | ft->size = filesize; |
1121 | ft->status = FILESTATUS_NOT_ACCEPTED; | 1121 | ft->transferred = 0; |
1122 | ft->size = filesize; | 1122 | ft->requested = 0; |
1123 | ft->transferred = 0; | 1123 | ft->slots_allocated = 0; |
1124 | ft->requested = 0; | 1124 | ft->paused = FILE_PAUSE_NOT; |
1125 | ft->slots_allocated = 0; | 1125 | memcpy(ft->id, file_id, FILE_ID_LENGTH); |
1126 | ft->paused = FILE_PAUSE_NOT; | 1126 | |
1127 | memcpy(ft->id, file_id, FILE_ID_LENGTH); | 1127 | ++m->friendlist[friendnumber].num_sending_files; |
1128 | 1128 | ||
1129 | ++m->friendlist[friendnumber].num_sending_files; | 1129 | return i; |
1130 | return i; | ||
1131 | } else { | ||
1132 | return -5; | ||
1133 | } | ||
1134 | } | 1130 | } |
1135 | 1131 | ||
1136 | int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, | 1132 | 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) | |||
1473 | 1469 | ||
1474 | uint16_t length = MAX_FILE_DATA_SIZE; | 1470 | uint16_t length = MAX_FILE_DATA_SIZE; |
1475 | 1471 | ||
1472 | if (ft->size == 0) { | ||
1473 | /* Send 0 data to friend if file is 0 length. */ | ||
1474 | file_data(m, friendnumber, i, 0, 0, 0); | ||
1475 | break; | ||
1476 | } | ||
1477 | |||
1476 | if (ft->size == ft->requested) { | 1478 | if (ft->size == ft->requested) { |
1477 | break; | 1479 | break; |
1478 | } | 1480 | } |
@@ -2051,20 +2053,11 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2051 | if (ft->status != FILESTATUS_NONE) | 2053 | if (ft->status != FILESTATUS_NONE) |
2052 | break; | 2054 | break; |
2053 | 2055 | ||
2054 | uint32_t real_filenumber = UINT32_MAX; | 2056 | ft->status = FILESTATUS_NOT_ACCEPTED; |
2055 | 2057 | ft->size = filesize; | |
2056 | if (filesize) { | 2058 | ft->transferred = 0; |
2057 | /* Don't */ | 2059 | ft->paused = FILE_PAUSE_NOT; |
2058 | ft->status = FILESTATUS_NOT_ACCEPTED; | 2060 | memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH); |
2059 | ft->size = filesize; | ||
2060 | ft->transferred = 0; | ||
2061 | ft->paused = FILE_PAUSE_NOT; | ||
2062 | memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH); | ||
2063 | |||
2064 | real_filenumber = filenumber; | ||
2065 | real_filenumber += 1; | ||
2066 | real_filenumber <<= 16; | ||
2067 | } | ||
2068 | 2061 | ||
2069 | uint8_t filename_terminated[filename_length + 1]; | 2062 | uint8_t filename_terminated[filename_length + 1]; |
2070 | uint8_t *filename = NULL; | 2063 | uint8_t *filename = NULL; |
@@ -2076,6 +2069,9 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2076 | filename = filename_terminated; | 2069 | filename = filename_terminated; |
2077 | } | 2070 | } |
2078 | 2071 | ||
2072 | uint32_t real_filenumber = filenumber; | ||
2073 | real_filenumber += 1; | ||
2074 | real_filenumber <<= 16; | ||
2079 | 2075 | ||
2080 | if (m->file_sendrequest) | 2076 | if (m->file_sendrequest) |
2081 | (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length, | 2077 | (*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) | |||
2099 | } | 2095 | } |
2100 | 2096 | ||
2101 | case PACKET_ID_FILE_DATA: { | 2097 | case PACKET_ID_FILE_DATA: { |
2102 | if (data_length <= 1) | 2098 | if (data_length < 1) |
2103 | break; | 2099 | break; |
2104 | 2100 | ||
2105 | uint8_t filenumber = data[0]; | 2101 | uint8_t filenumber = data[0]; |
2106 | struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber]; | 2102 | struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber]; |
2107 | 2103 | ||
2108 | if (ft->status == FILESTATUS_NONE) | 2104 | if (ft->status != FILESTATUS_TRANSFERRING) |
2109 | break; | 2105 | break; |
2110 | 2106 | ||
2111 | uint64_t position = ft->transferred; | 2107 | uint64_t position = ft->transferred; |
@@ -2126,7 +2122,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2126 | 2122 | ||
2127 | ft->transferred += file_data_length; | 2123 | ft->transferred += file_data_length; |
2128 | 2124 | ||
2129 | if (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE) { | 2125 | if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) { |
2130 | file_data_length = 0; | 2126 | file_data_length = 0; |
2131 | file_data = NULL; | 2127 | file_data = NULL; |
2132 | position = ft->transferred; | 2128 | position = ft->transferred; |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 21b474f6..d1a2ed9b 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -618,7 +618,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u | |||
618 | * return -2 if filename length invalid. | 618 | * return -2 if filename length invalid. |
619 | * return -3 if no more file sending slots left. | 619 | * return -3 if no more file sending slots left. |
620 | * return -4 if could not send packet (friend offline). | 620 | * return -4 if could not send packet (friend offline). |
621 | * return -5 if succesfully sent file send request with filesize 0. | 621 | * |
622 | */ | 622 | */ |
623 | long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, | 623 | long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, |
624 | const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length); | 624 | const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length); |
diff --git a/toxcore/tox.c b/toxcore/tox.c index f17eb758..44845138 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -1000,10 +1000,6 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t | |||
1000 | case -4: | 1000 | case -4: |
1001 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED); | 1001 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED); |
1002 | return UINT32_MAX; | 1002 | return UINT32_MAX; |
1003 | |||
1004 | case -5: | ||
1005 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK_ZERO_LENGTH); | ||
1006 | return UINT32_MAX; | ||
1007 | } | 1003 | } |
1008 | 1004 | ||
1009 | /* can't happen */ | 1005 | /* can't happen */ |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 0953daee..5a8d6ab2 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -1610,12 +1610,7 @@ typedef enum TOX_ERR_FILE_SEND { | |||
1610 | * Too many ongoing transfers. The maximum number of concurrent file transfers | 1610 | * Too many ongoing transfers. The maximum number of concurrent file transfers |
1611 | * is 256 per friend per direction (sending and receiving). | 1611 | * is 256 per friend per direction (sending and receiving). |
1612 | */ | 1612 | */ |
1613 | TOX_ERR_FILE_SEND_TOO_MANY, | 1613 | TOX_ERR_FILE_SEND_TOO_MANY |
1614 | /** | ||
1615 | * A file request packet was successfully sent to the friend however since it was zero | ||
1616 | * length, no file number was allocated for the file transfer. | ||
1617 | */ | ||
1618 | TOX_ERR_FILE_SEND_OK_ZERO_LENGTH | ||
1619 | } TOX_ERR_FILE_SEND; | 1614 | } TOX_ERR_FILE_SEND; |
1620 | 1615 | ||
1621 | /** | 1616 | /** |
@@ -1634,9 +1629,6 @@ typedef enum TOX_ERR_FILE_SEND { | |||
1634 | * When a friend goes offline, all file transfers associated with the friend are | 1629 | * When a friend goes offline, all file transfers associated with the friend are |
1635 | * purged from core. | 1630 | * purged from core. |
1636 | * | 1631 | * |
1637 | * if file_size is 0, this function will not allocate a file transfer in core and so | ||
1638 | * will not return a valid file number however it will send a file request packet. | ||
1639 | * | ||
1640 | * If the file contents change during a transfer, the behaviour is unspecified | 1632 | * If the file contents change during a transfer, the behaviour is unspecified |
1641 | * in general. What will actually happen depends on the mode in which the file | 1633 | * in general. What will actually happen depends on the mode in which the file |
1642 | * was modified and how the client determines the file size. | 1634 | * 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 | |||
1787 | * control command before any other control commands. It can be accepted by | 1779 | * control command before any other control commands. It can be accepted by |
1788 | * sending TOX_FILE_CONTROL_RESUME. | 1780 | * sending TOX_FILE_CONTROL_RESUME. |
1789 | * | 1781 | * |
1790 | * If file_size is zero, the file_number is invalid and should be ignored. | ||
1791 | * | ||
1792 | * @param friend_number The friend number of the friend who is sending the file | 1782 | * @param friend_number The friend number of the friend who is sending the file |
1793 | * transfer request. | 1783 | * transfer request. |
1794 | * @param file_number The friend-specific file number the data received is | 1784 | * @param file_number The friend-specific file number the data received is |