diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/net_crypto.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 8c1d74c7..be450499 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -607,18 +607,14 @@ static int set_buffer_end(Packets_Array *array, uint32_t number) | |||
607 | * return -1 on failure. | 607 | * return -1 on failure. |
608 | * return length of packet on success. | 608 | * return length of packet on success. |
609 | */ | 609 | */ |
610 | static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array *recv_array, uint32_t send_buffer_end) | 610 | static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array *recv_array) |
611 | { | 611 | { |
612 | if (length <= (sizeof(uint32_t) * 2)) | 612 | if (length == 0) |
613 | return -1; | 613 | return -1; |
614 | 614 | ||
615 | uint32_t recv_buffer_start = htonl(recv_array->buffer_start); | 615 | data[0] = PACKET_ID_REQUEST; |
616 | send_buffer_end = htonl(send_buffer_end); | ||
617 | memcpy(data, &recv_buffer_start, sizeof(uint32_t)); | ||
618 | memcpy(data + sizeof(uint32_t), &send_buffer_end, sizeof(uint32_t)); | ||
619 | data[sizeof(uint32_t) * 2] = PACKET_ID_REQUEST; | ||
620 | 616 | ||
621 | uint16_t cur_len = sizeof(uint32_t) * 2 + 1; | 617 | uint16_t cur_len = 1; |
622 | 618 | ||
623 | if (recv_array->buffer_start == recv_array->buffer_end) | 619 | if (recv_array->buffer_start == recv_array->buffer_end) |
624 | return cur_len; | 620 | return cur_len; |
@@ -857,13 +853,13 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id) | |||
857 | if (conn == 0) | 853 | if (conn == 0) |
858 | return -1; | 854 | return -1; |
859 | 855 | ||
860 | uint8_t packet[MAX_DATA_DATA_PACKET_SIZE]; | 856 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; |
861 | int len = generate_request_packet(packet, sizeof(packet), &conn->recv_array, conn->send_array.buffer_end); | 857 | int len = generate_request_packet(data, sizeof(data), &conn->recv_array); |
862 | 858 | ||
863 | if (len == -1) | 859 | if (len == -1) |
864 | return -1; | 860 | return -1; |
865 | 861 | ||
866 | return send_data_packet(c, crypt_connection_id, packet, len); | 862 | return send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, conn->send_array.buffer_end, data, len); |
867 | } | 863 | } |
868 | 864 | ||
869 | /* Send up to max num previously requested data packets. | 865 | /* Send up to max num previously requested data packets. |