summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-06-04 17:35:38 -0400
committerirungentoo <irungentoo@gmail.com>2014-06-04 17:35:38 -0400
commitdc6f46a24089d4134a72951f4cf18f0dc314218c (patch)
tree218359bd8580129ffee14b31ded3f719ed1fe219 /toxcore/net_crypto.c
parentb44b58cae41ba8da806dc0b6149ab21da252e884 (diff)
Request packets are now sent with send_data_packet_helper().
This means all data packets are now padded the same way.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c18
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 */
610static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array *recv_array, uint32_t send_buffer_end) 610static 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.