summaryrefslogtreecommitdiff
path: root/toxcore/friend_requests.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-04-23 11:35:40 -0400
committerirungentoo <irungentoo@gmail.com>2014-04-23 11:35:40 -0400
commit384750af8cf9e339989ded452181e1238ed6e307 (patch)
treef3eb8ac28b07263fe4c8372db8a2f52230531133 /toxcore/friend_requests.c
parent1bfe15ee88844bdbd43052b4026202cf924ad6ca (diff)
Major cleanups.
Fixed circular dependency between DHT and net_crypto: DHT no longer depends on net_crypto. Moved the crypto request packets functions to crypto core and DHT. Cleaned up/added some defines that can be used to get the true maximum length of things like the friends request message. MAX_DATA_SIZE has been replaced in most places by more appropriate defines.
Diffstat (limited to 'toxcore/friend_requests.c')
-rw-r--r--toxcore/friend_requests.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c
index c5cfa4b4..eb2a791c 100644
--- a/toxcore/friend_requests.c
+++ b/toxcore/friend_requests.c
@@ -37,10 +37,10 @@
37 */ 37 */
38int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length) 38int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length)
39{ 39{
40 if (length + sizeof(nospam_num) >= MAX_DATA_SIZE) 40 if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0)
41 return -1; 41 return -1;
42 42
43 uint8_t temp[MAX_DATA_SIZE]; 43 uint8_t temp[1 + sizeof(nospam_num) + length];
44 temp[0] = CRYPTO_PACKET_FRIEND_REQ; 44 temp[0] = CRYPTO_PACKET_FRIEND_REQ;
45 memcpy(temp + 1, &nospam_num, sizeof(nospam_num)); 45 memcpy(temp + 1, &nospam_num, sizeof(nospam_num));
46 memcpy(temp + 1 + sizeof(nospam_num), data, length); 46 memcpy(temp + 1 + sizeof(nospam_num), data, length);
@@ -50,7 +50,7 @@ int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nosp
50 if (friend_num == -1) 50 if (friend_num == -1)
51 return -1; 51 return -1;
52 52
53 int num = send_onion_data(onion_c, friend_num, temp, 1 + sizeof(nospam_num) + length); 53 int num = send_onion_data(onion_c, friend_num, temp, sizeof(temp));
54 54
55 if (num <= 0) 55 if (num <= 0)
56 return -1; 56 return -1;
@@ -137,7 +137,7 @@ static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t
137{ 137{
138 Friend_Requests *fr = object; 138 Friend_Requests *fr = object;
139 139
140 if (length <= 1 + sizeof(fr->nospam) || length > MAX_DATA_SIZE) 140 if (length <= 1 + sizeof(fr->nospam) || length > ONION_CLIENT_MAX_DATA_SIZE)
141 return 1; 141 return 1;
142 142
143 ++packet; 143 ++packet;