summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-01-12 20:26:29 -0500
committerirungentoo <irungentoo@gmail.com>2015-01-12 20:26:29 -0500
commit6650f18b865043ac4980992b7c9be6e776db76b0 (patch)
treec9e6a02fb7f89b4d7c654bdaaefb0b69bb926554 /toxcore
parent36b412e3812c5c816602166ecaf297483267f0ab (diff)
Attempted fix of Tox killing routers part 2.
Reduced drastically the number of ips the DHT pings by only pinging nodes that would be included in one of the close lists.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 919655a2..4a0863d3 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -647,6 +647,21 @@ static int cmp_dht_entry(const void *a, const void *b)
647 return 0; 647 return 0;
648} 648}
649 649
650/* Is it ok to store node with client_id in client.
651 *
652 * return 0 if node can't be stored.
653 * return 1 if it can.
654 */
655static unsigned int store_node_ok(const Client_data *client, const uint8_t *client_id, const uint8_t *comp_client_id)
656{
657 if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT))
658 || (id_closest(comp_client_id, client->client_id, client_id) == 2)) {
659 return 1;
660 } else {
661 return 0;
662 }
663}
664
650/* Replace a first bad (or empty) node with this one 665/* Replace a first bad (or empty) node with this one
651 * or replace a possibly bad node (tests failed or not done yet) 666 * or replace a possibly bad node (tests failed or not done yet)
652 * that is further than any other in the list 667 * that is further than any other in the list
@@ -674,8 +689,7 @@ static int replace_all( Client_data *list,
674 689
675 Client_data *client = &list[0]; 690 Client_data *client = &list[0];
676 691
677 if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) 692 if (store_node_ok(client, client_id, comp_client_id)) {
678 || (id_closest(comp_client_id, client->client_id, client_id) == 2)) {
679 IPPTsPng *ipptp_write = NULL; 693 IPPTsPng *ipptp_write = NULL;
680 IPPTsPng *ipptp_clear = NULL; 694 IPPTsPng *ipptp_clear = NULL;
681 695
@@ -704,6 +718,29 @@ static int replace_all( Client_data *list,
704 return 0; 718 return 0;
705} 719}
706 720
721/* Check if the node obtained with a get_nodes with client_id should be pinged.
722 * NOTE: for best results call it after addto_lists;
723 *
724 * return 0 if the node should not be pinged.
725 * return 1 if it should.
726 */
727static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *client_id)
728{
729 if (store_node_ok(&dht->close_clientlist[0], client_id, dht->self_public_key)) {
730 return 1;
731 }
732
733 unsigned int i;
734
735 for (i = 0; i < dht->num_friends; ++i) {
736 if (store_node_ok(&dht->friends_list[i].client_list[0], client_id, dht->self_public_key)) {
737 return 1;
738 }
739 }
740
741 return 0;
742}
743
707/* Attempt to add client with ip_port and client_id to the friends client list 744/* Attempt to add client with ip_port and client_id to the friends client list
708 * and close_clientlist. 745 * and close_clientlist.
709 * 746 *
@@ -1091,7 +1128,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *pa
1091 uint32_t i; 1128 uint32_t i;
1092 1129
1093 for (i = 0; i < num_nodes; i++) { 1130 for (i = 0; i < num_nodes; i++) {
1094 if (ipport_isset(&plain_nodes[i].ip_port)) { 1131 if (ipport_isset(&plain_nodes[i].ip_port) && ping_node_from_getnodes_ok(dht, plain_nodes[i].client_id)) {
1095 send_ping_request(dht->ping, plain_nodes[i].ip_port, plain_nodes[i].client_id); 1132 send_ping_request(dht->ping, plain_nodes[i].ip_port, plain_nodes[i].client_id);
1096 returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].client_id, packet + 1); 1133 returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].client_id, packet + 1);
1097 } 1134 }