From 606c2c12abfa0de9b2947dcdbbb47f8f8230852a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 7 Dec 2013 21:13:07 -0500 Subject: [PATCH] Small fixes. --- docs/Hardening_docs.txt | 2 +- toxcore/DHT.c | 13 +++++++++---- toxcore/net_crypto.c | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/Hardening_docs.txt b/docs/Hardening_docs.txt index 08c6ef13..c5de6ade 100644 --- a/docs/Hardening_docs.txt +++ b/docs/Hardening_docs.txt @@ -13,7 +13,7 @@ All hardening requests must contain exactly 768 bytes of data. (The data sent mu -The packet is a get nodes test request: send a get_node request to that node with the id to query in the request. when a send_node response is received, send the following response to the person who sent us the get nodes test request packet: - [byte with value: 03 (get nodes test response)][client_id(32 bytes): the id that the node was queried with][The list of nodes it responded with in IPv6 Node format (struct Node_Format)] + [byte with value: 03 (get nodes test response)][client_id(32 bytes): the id of the tested node][The list of nodes it responded with in IPv6 Node format (struct Node_Format)] PROTIP: (get node requests and response contain an encrypted part that you can use to store information so that you don't have to store in your memory where/if to send back the response from the send node) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 40ad3929..45a68f50 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1023,6 +1023,8 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3 &sendback_node)) return 1; + if (num_nodes == 0) + return 0; Node4_format *nodes4_list = (Node4_format *)(plain); @@ -1067,6 +1069,9 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, &sendback_node)) return 1; + if (num_nodes == 0) + return 0; + Node_format *nodes_list = (Node_format *)(plain); uint64_t time_now = unix_time(); uint32_t i; @@ -1830,7 +1835,7 @@ static int send_hardening_getnode_res(DHT *dht, Node_format *sendto, uint8_t *qu * check how many nodes in nodes are also present in the closelist. * TODO: make this function better. */ -static int have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num, sa_family_t sa_family) +static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num, sa_family_t sa_family) { Node_format nodes_list[MAX_SENT_NODES]; uint32_t num_nodes = get_close_nodes(dht, dht->c->self_public_key, nodes_list, sa_family, 1, 1); @@ -1839,7 +1844,7 @@ static int have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num, sa_f num_nodes = get_close_nodes(dht, dht->c->self_public_key, nodes_list, sa_family, 1, 0); } - int counter = 0; + uint32_t counter = 0; uint32_t i, j; for (i = 0; i < num; ++i) { @@ -1847,7 +1852,7 @@ static int have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num, sa_f ++counter; } - for (j = 0; j < (uint32_t)num_nodes; ++j) { + for (j = 0; j < num_nodes; ++j) { if (id_equal(nodes[i].client_id, nodes_list[j].client_id)) { if (ipport_equal(&nodes[i].ip_port, &nodes_list[j].ip_port)) { ++counter; @@ -1924,7 +1929,7 @@ static int handle_hardening(void *object, IP_Port source, uint8_t *source_pubkey memcpy(nodes, packet + 1 + CLIENT_ID_SIZE, sizeof(Node_format)*num); /* NOTE: This should work for now but should be changed to something better. */ - if (have_nodes_closelist(dht, nodes, num, nodes[0].ip_port.ip.family) < (num + 1) / 2) + if (have_nodes_closelist(dht, nodes, num, nodes[0].ip_port.ip.family) < (uint32_t)((num + 1) / 2)) return 1; diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 8be1059e..6b64c1b6 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -170,7 +170,7 @@ static void increment_nonce(uint8_t *nonce) } #if crypto_box_NONCEBYTES != crypto_secretbox_NONCEBYTES -/*if they no longer equal each other, this function must be slit into two.*/ +/*if they no longer equal each other, this function must be split into two.*/ #error random_nonce(): crypto_box_NONCEBYTES must equal crypto_secretbox_NONCEBYTES. #endif /* Fill the given nonce with random bytes. */ @@ -189,7 +189,7 @@ static uint8_t base_nonce[crypto_box_NONCEBYTES]; static uint8_t nonce_set = 0; #if crypto_box_NONCEBYTES != crypto_secretbox_NONCEBYTES -/*if they no longer equal each other, this function must be slit into two.*/ +/*if they no longer equal each other, this function must be split into two.*/ #error new_nonce(): crypto_box_NONCEBYTES must equal crypto_secretbox_NONCEBYTES. #endif /* Gives a nonce guaranteed to be different from previous ones.*/