Small fixes.

This commit is contained in:
irungentoo 2013-12-07 21:13:07 -05:00
parent 1c45e59938
commit 606c2c12ab
3 changed files with 12 additions and 7 deletions

View File

@ -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: -The packet is a get nodes test request:
send a get_node request to that node with the id to query in the 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: 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 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) have to store in your memory where/if to send back the response from the send node)

View File

@ -1023,6 +1023,8 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3
&sendback_node)) &sendback_node))
return 1; return 1;
if (num_nodes == 0)
return 0;
Node4_format *nodes4_list = (Node4_format *)(plain); 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)) &sendback_node))
return 1; return 1;
if (num_nodes == 0)
return 0;
Node_format *nodes_list = (Node_format *)(plain); Node_format *nodes_list = (Node_format *)(plain);
uint64_t time_now = unix_time(); uint64_t time_now = unix_time();
uint32_t i; 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. * check how many nodes in nodes are also present in the closelist.
* TODO: make this function better. * 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]; 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); 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); 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; uint32_t i, j;
for (i = 0; i < num; ++i) { 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; ++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 (id_equal(nodes[i].client_id, nodes_list[j].client_id)) {
if (ipport_equal(&nodes[i].ip_port, &nodes_list[j].ip_port)) { if (ipport_equal(&nodes[i].ip_port, &nodes_list[j].ip_port)) {
++counter; ++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); memcpy(nodes, packet + 1 + CLIENT_ID_SIZE, sizeof(Node_format)*num);
/* NOTE: This should work for now but should be changed to something better. */ /* 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; return 1;

View File

@ -170,7 +170,7 @@ static void increment_nonce(uint8_t *nonce)
} }
#if crypto_box_NONCEBYTES != crypto_secretbox_NONCEBYTES #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. #error random_nonce(): crypto_box_NONCEBYTES must equal crypto_secretbox_NONCEBYTES.
#endif #endif
/* Fill the given nonce with random bytes. */ /* 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; static uint8_t nonce_set = 0;
#if crypto_box_NONCEBYTES != crypto_secretbox_NONCEBYTES #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. #error new_nonce(): crypto_box_NONCEBYTES must equal crypto_secretbox_NONCEBYTES.
#endif #endif
/* Gives a nonce guaranteed to be different from previous ones.*/ /* Gives a nonce guaranteed to be different from previous ones.*/