diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-21 20:18:29 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-21 20:18:29 -0500 |
commit | 6bbb9398558d226711450feea45417bcf3eafe70 (patch) | |
tree | ed946e3fa14ccc4aec0dbdddc481dcd1e2de3e69 /toxcore/onion.c | |
parent | e74225039e08e7be6e60cf7e2f5e279eb0559ce7 (diff) |
Cleaned up packet length types in toxcore.
They are now all uint16_t instead of sometimes being uint32_t.
Replaced some other uint32_t with unsigned ints.
Diffstat (limited to 'toxcore/onion.c')
-rw-r--r-- | toxcore/onion.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/toxcore/onion.c b/toxcore/onion.c index 938b861e..963c9b11 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c | |||
@@ -94,7 +94,7 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n | |||
94 | * return length of created packet on success. | 94 | * return length of created packet on success. |
95 | */ | 95 | */ |
96 | int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest, | 96 | int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest, |
97 | const uint8_t *data, uint32_t length) | 97 | const uint8_t *data, uint16_t length) |
98 | { | 98 | { |
99 | if (1 + length + SEND_1 > max_packet_length || length == 0) | 99 | if (1 + length + SEND_1 > max_packet_length || length == 0) |
100 | return -1; | 100 | return -1; |
@@ -151,7 +151,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion | |||
151 | * return length of created packet on success. | 151 | * return length of created packet on success. |
152 | */ | 152 | */ |
153 | int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest, | 153 | int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest, |
154 | const uint8_t *data, uint32_t length) | 154 | const uint8_t *data, uint16_t length) |
155 | { | 155 | { |
156 | if (crypto_box_NONCEBYTES + SIZE_IPPORT + SEND_BASE * 2 + length > max_packet_length || length == 0) | 156 | if (crypto_box_NONCEBYTES + SIZE_IPPORT + SEND_BASE * 2 + length > max_packet_length || length == 0) |
157 | return -1; | 157 | return -1; |
@@ -197,7 +197,7 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O | |||
197 | * return -1 on failure. | 197 | * return -1 on failure. |
198 | * return 0 on success. | 198 | * return 0 on success. |
199 | */ | 199 | */ |
200 | int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint32_t length) | 200 | int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint16_t length) |
201 | { | 201 | { |
202 | uint8_t packet[ONION_MAX_PACKET_SIZE]; | 202 | uint8_t packet[ONION_MAX_PACKET_SIZE]; |
203 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); | 203 | int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length); |
@@ -217,7 +217,7 @@ int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest | |||
217 | * return -1 on failure. | 217 | * return -1 on failure. |
218 | * return 0 on success. | 218 | * return 0 on success. |
219 | */ | 219 | */ |
220 | int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint32_t length, const uint8_t *ret) | 220 | int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint16_t length, const uint8_t *ret) |
221 | { | 221 | { |
222 | if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) | 222 | if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) |
223 | return -1; | 223 | return -1; |
@@ -233,7 +233,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, | |||
233 | return 0; | 233 | return 0; |
234 | } | 234 | } |
235 | 235 | ||
236 | static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 236 | static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
237 | { | 237 | { |
238 | Onion *onion = object; | 238 | Onion *onion = object; |
239 | 239 | ||
@@ -257,7 +257,7 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack | |||
257 | return onion_send_1(onion, plain, len, source, packet + 1); | 257 | return onion_send_1(onion, plain, len, source, packet + 1); |
258 | } | 258 | } |
259 | 259 | ||
260 | int onion_send_1(const Onion *onion, const uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce) | 260 | int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce) |
261 | { | 261 | { |
262 | if (len > ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + crypto_box_NONCEBYTES + ONION_RETURN_1)) | 262 | if (len > ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + crypto_box_NONCEBYTES + ONION_RETURN_1)) |
263 | return 1; | 263 | return 1; |
@@ -276,7 +276,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint32_t len, IP_Port | |||
276 | data[0] = NET_PACKET_ONION_SEND_1; | 276 | data[0] = NET_PACKET_ONION_SEND_1; |
277 | memcpy(data + 1, nonce, crypto_box_NONCEBYTES); | 277 | memcpy(data + 1, nonce, crypto_box_NONCEBYTES); |
278 | memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); | 278 | memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); |
279 | uint32_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); | 279 | uint16_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); |
280 | uint8_t *ret_part = data + data_len; | 280 | uint8_t *ret_part = data + data_len; |
281 | new_nonce(ret_part); | 281 | new_nonce(ret_part); |
282 | len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ip_port, SIZE_IPPORT, | 282 | len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ip_port, SIZE_IPPORT, |
@@ -293,7 +293,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint32_t len, IP_Port | |||
293 | return 0; | 293 | return 0; |
294 | } | 294 | } |
295 | 295 | ||
296 | static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 296 | static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
297 | { | 297 | { |
298 | Onion *onion = object; | 298 | Onion *onion = object; |
299 | 299 | ||
@@ -322,7 +322,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
322 | data[0] = NET_PACKET_ONION_SEND_2; | 322 | data[0] = NET_PACKET_ONION_SEND_2; |
323 | memcpy(data + 1, packet + 1, crypto_box_NONCEBYTES); | 323 | memcpy(data + 1, packet + 1, crypto_box_NONCEBYTES); |
324 | memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); | 324 | memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); |
325 | uint32_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); | 325 | uint16_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); |
326 | uint8_t *ret_part = data + data_len; | 326 | uint8_t *ret_part = data + data_len; |
327 | new_nonce(ret_part); | 327 | new_nonce(ret_part); |
328 | uint8_t ret_data[RETURN_1 + SIZE_IPPORT]; | 328 | uint8_t ret_data[RETURN_1 + SIZE_IPPORT]; |
@@ -342,7 +342,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
342 | return 0; | 342 | return 0; |
343 | } | 343 | } |
344 | 344 | ||
345 | static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 345 | static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
346 | { | 346 | { |
347 | Onion *onion = object; | 347 | Onion *onion = object; |
348 | 348 | ||
@@ -369,7 +369,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
369 | 369 | ||
370 | uint8_t data[ONION_MAX_PACKET_SIZE]; | 370 | uint8_t data[ONION_MAX_PACKET_SIZE]; |
371 | memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT); | 371 | memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT); |
372 | uint32_t data_len = (len - SIZE_IPPORT); | 372 | uint16_t data_len = (len - SIZE_IPPORT); |
373 | uint8_t *ret_part = data + (len - SIZE_IPPORT); | 373 | uint8_t *ret_part = data + (len - SIZE_IPPORT); |
374 | new_nonce(ret_part); | 374 | new_nonce(ret_part); |
375 | uint8_t ret_data[RETURN_2 + SIZE_IPPORT]; | 375 | uint8_t ret_data[RETURN_2 + SIZE_IPPORT]; |
@@ -390,7 +390,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 393 | static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
394 | { | 394 | { |
395 | Onion *onion = object; | 395 | Onion *onion = object; |
396 | 396 | ||
@@ -416,7 +416,7 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
416 | data[0] = NET_PACKET_ONION_RECV_2; | 416 | data[0] = NET_PACKET_ONION_RECV_2; |
417 | memcpy(data + 1, plain + SIZE_IPPORT, RETURN_2); | 417 | memcpy(data + 1, plain + SIZE_IPPORT, RETURN_2); |
418 | memcpy(data + 1 + RETURN_2, packet + 1 + RETURN_3, length - (1 + RETURN_3)); | 418 | memcpy(data + 1 + RETURN_2, packet + 1 + RETURN_3, length - (1 + RETURN_3)); |
419 | uint32_t data_len = 1 + RETURN_2 + (length - (1 + RETURN_3)); | 419 | uint16_t data_len = 1 + RETURN_2 + (length - (1 + RETURN_3)); |
420 | 420 | ||
421 | if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) | 421 | if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) |
422 | return 1; | 422 | return 1; |
@@ -424,7 +424,7 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
424 | return 0; | 424 | return 0; |
425 | } | 425 | } |
426 | 426 | ||
427 | static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 427 | static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
428 | { | 428 | { |
429 | Onion *onion = object; | 429 | Onion *onion = object; |
430 | 430 | ||
@@ -450,7 +450,7 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
450 | data[0] = NET_PACKET_ONION_RECV_1; | 450 | data[0] = NET_PACKET_ONION_RECV_1; |
451 | memcpy(data + 1, plain + SIZE_IPPORT, RETURN_1); | 451 | memcpy(data + 1, plain + SIZE_IPPORT, RETURN_1); |
452 | memcpy(data + 1 + RETURN_1, packet + 1 + RETURN_2, length - (1 + RETURN_2)); | 452 | memcpy(data + 1 + RETURN_1, packet + 1 + RETURN_2, length - (1 + RETURN_2)); |
453 | uint32_t data_len = 1 + RETURN_1 + (length - (1 + RETURN_2)); | 453 | uint16_t data_len = 1 + RETURN_1 + (length - (1 + RETURN_2)); |
454 | 454 | ||
455 | if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) | 455 | if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) |
456 | return 1; | 456 | return 1; |
@@ -458,7 +458,7 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
458 | return 0; | 458 | return 0; |
459 | } | 459 | } |
460 | 460 | ||
461 | static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length) | 461 | static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
462 | { | 462 | { |
463 | Onion *onion = object; | 463 | Onion *onion = object; |
464 | 464 | ||
@@ -480,7 +480,7 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
480 | IP_Port send_to; | 480 | IP_Port send_to; |
481 | ipport_unpack(&send_to, plain); | 481 | ipport_unpack(&send_to, plain); |
482 | 482 | ||
483 | uint32_t data_len = length - (1 + RETURN_1); | 483 | uint16_t data_len = length - (1 + RETURN_1); |
484 | 484 | ||
485 | if (onion->recv_1_function && send_to.ip.family != AF_INET && send_to.ip.family != AF_INET6) | 485 | if (onion->recv_1_function && send_to.ip.family != AF_INET && send_to.ip.family != AF_INET6) |
486 | return onion->recv_1_function(onion->callback_object, send_to, packet + (1 + RETURN_1), data_len); | 486 | return onion->recv_1_function(onion->callback_object, send_to, packet + (1 + RETURN_1), data_len); |