summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorYuri <yuri@tsoft.com>2017-01-14 17:34:21 -0800
committeriphydf <iphydf@users.noreply.github.com>2017-01-26 22:29:25 +0000
commit2f62fa38fc2806479d581b6246a30c0c1b34e370 (patch)
treeae3552a89d801a2a15811d9c6a085ab5c55af41b /toxcore/DHT.c
parentf00006cf1d966270b6142519ad7d8487fb5eff5a (diff)
Replace redundant packet type check in handler with assert.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index f82c1061..5f3a1d07 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2559,36 +2559,36 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
2559{ 2559{
2560 DHT *dht = (DHT *)object; 2560 DHT *dht = (DHT *)object;
2561 2561
2562 if (packet[0] == NET_PACKET_CRYPTO) { 2562 assert(packet[0] == NET_PACKET_CRYPTO);
2563 if (length <= CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1 + CRYPTO_MAC_SIZE ||
2564 length > MAX_CRYPTO_REQUEST_SIZE + CRYPTO_MAC_SIZE) {
2565 return 1;
2566 }
2567 2563
2568 if (public_key_cmp(packet + 1, dht->self_public_key) == 0) { // Check if request is for us. 2564 if (length <= CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1 + CRYPTO_MAC_SIZE ||
2569 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; 2565 length > MAX_CRYPTO_REQUEST_SIZE + CRYPTO_MAC_SIZE) {
2570 uint8_t data[MAX_CRYPTO_REQUEST_SIZE]; 2566 return 1;
2571 uint8_t number; 2567 }
2572 int len = handle_request(dht->self_public_key, dht->self_secret_key, public_key, data, &number, packet, length);
2573 2568
2574 if (len == -1 || len == 0) { 2569 if (public_key_cmp(packet + 1, dht->self_public_key) == 0) { // Check if request is for us.
2575 return 1; 2570 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
2576 } 2571 uint8_t data[MAX_CRYPTO_REQUEST_SIZE];
2572 uint8_t number;
2573 int len = handle_request(dht->self_public_key, dht->self_secret_key, public_key, data, &number, packet, length);
2577 2574
2578 if (!dht->cryptopackethandlers[number].function) { 2575 if (len == -1 || len == 0) {
2579 return 1; 2576 return 1;
2580 } 2577 }
2581 2578
2582 return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key, 2579 if (!dht->cryptopackethandlers[number].function) {
2583 data, len, userdata); 2580 return 1;
2584 } 2581 }
2585 2582
2586 /* If request is not for us, try routing it. */ 2583 return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key,
2587 int retval = route_packet(dht, packet + 1, packet, length); 2584 data, len, userdata);
2585 }
2588 2586
2589 if ((unsigned int)retval == length) { 2587 /* If request is not for us, try routing it. */
2590 return 0; 2588 int retval = route_packet(dht, packet + 1, packet, length);
2591 } 2589
2590 if ((unsigned int)retval == length) {
2591 return 0;
2592 } 2592 }
2593 2593
2594 return 1; 2594 return 1;