summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 47595d06..749eb78c 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -129,7 +129,7 @@ static int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout)
129/* Check if client with client_id is already in list of length length. 129/* Check if client with client_id is already in list of length length.
130 * If it is then set its corresponding timestamp to current time. 130 * If it is then set its corresponding timestamp to current time.
131 * If the id is already in the list with a different ip_port, update it. 131 * If the id is already in the list with a different ip_port, update it.
132 * TODO: Maybe optimize this. 132 * TODO: Maybe optimize this.
133 * 133 *
134 * return True(1) or False(0) 134 * return True(1) or False(0)
135 */ 135 */
@@ -548,7 +548,10 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl
548 sizeof(ping_id) + num_nodes * sizeof(Node_format), 548 sizeof(ping_id) + num_nodes * sizeof(Node_format),
549 encrypt ); 549 encrypt );
550 550
551 if (len != sizeof(ping_id) + num_nodes * sizeof(Node_format) + ENCRYPTION_PADDING) 551 if (len == -1)
552 return -1;
553
554 if ((unsigned int)len != sizeof(ping_id) + num_nodes * sizeof(Node_format) + ENCRYPTION_PADDING)
552 return -1; 555 return -1;
553 556
554 data[0] = NET_PACKET_SEND_NODES; 557 data[0] = NET_PACKET_SEND_NODES;
@@ -614,7 +617,7 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3
614 packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, 617 packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
615 sizeof(ping_id) + num_nodes * sizeof(Node_format) + ENCRYPTION_PADDING, plain ); 618 sizeof(ping_id) + num_nodes * sizeof(Node_format) + ENCRYPTION_PADDING, plain );
616 619
617 if (len != sizeof(ping_id) + num_nodes * sizeof(Node_format)) 620 if ((unsigned int)len != sizeof(ping_id) + num_nodes * sizeof(Node_format))
618 return 1; 621 return 1;
619 622
620 memcpy(&ping_id, plain, sizeof(ping_id)); 623 memcpy(&ping_id, plain, sizeof(ping_id));
@@ -856,7 +859,7 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
856 859
857 860
858/* Send the following packet to everyone who tells us they are connected to friend_id. 861/* Send the following packet to everyone who tells us they are connected to friend_id.
859 * 862 *
860 * return ip for friend. 863 * return ip for friend.
861 * return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 2). 864 * return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 2).
862 */ 865 */
@@ -884,7 +887,9 @@ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t lengt
884 887
885 /* If ip is not zero and node is good. */ 888 /* If ip is not zero and node is good. */
886 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 889 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
887 if (sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length) == length) 890 int retval = sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length);
891
892 if ((unsigned int)retval == length)
888 ++sent; 893 ++sent;
889 } 894 }
890 } 895 }
@@ -924,7 +929,9 @@ static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint
924 if (n < 1) 929 if (n < 1)
925 return 0; 930 return 0;
926 931
927 if (sendpacket(dht->c->lossless_udp->net->sock, ip_list[rand() % n], packet, length) == length) 932 int retval = sendpacket(dht->c->lossless_udp->net->sock, ip_list[rand() % n], packet, length);
933
934 if ((unsigned int)retval == length)
928 return 1; 935 return 1;
929 936
930 return 0; 937 return 0;
@@ -1074,7 +1081,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
1074 for (i = dht->friends_list[friend_num].punching_index; i != top; i++) { 1081 for (i = dht->friends_list[friend_num].punching_index; i != top; i++) {
1075 /* TODO: Improve port guessing algorithm. */ 1082 /* TODO: Improve port guessing algorithm. */
1076 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); 1083 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1);
1077 IP_Port pinging = {{ip, htons(port)}}; 1084 IP_Port pinging = {{ip, htons(port), 0}};
1078 send_ping_request(dht->ping, dht->c, pinging, dht->friends_list[friend_num].client_id); 1085 send_ping_request(dht->ping, dht->c, pinging, dht->friends_list[friend_num].client_id);
1079 } 1086 }
1080 1087