summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 226a38ca..55f34994 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -741,8 +741,8 @@ IP_Port DHT_getfriendip(uint8_t *client_id)
741 return empty; 741 return empty;
742} 742}
743 743
744/* Ping each client in the "friends" list every 60 seconds. Send a get nodes request 744/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
745 * every 20 seconds to a random good node for each "friend" in our "friends" list. 745 * every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
746 */ 746 */
747static void doDHTFriends(void) 747static void doDHTFriends(void)
748{ 748{
@@ -783,8 +783,8 @@ static void doDHTFriends(void)
783 783
784static uint64_t close_lastgetnodes; 784static uint64_t close_lastgetnodes;
785 785
786/* Ping each client in the close nodes list every 60 seconds. 786/* Ping each client in the close nodes list every PING_INTERVAL seconds.
787 * Send a get nodes request every 20 seconds to a random good node in the list. 787 * Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
788 */ 788 */
789static void doClose(void) 789static void doClose(void)
790{ 790{
@@ -823,6 +823,7 @@ static void doClose(void)
823void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key) 823void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key)
824{ 824{
825 getnodes(ip_port, public_key, self_public_key); 825 getnodes(ip_port, public_key, self_public_key);
826 send_ping_request(ip_port, (clientid_t *) public_key);
826} 827}
827 828
828/* send the given packet to node with client_id 829/* send the given packet to node with client_id
@@ -875,8 +876,11 @@ static int friend_iplist(IP_Port *ip_portlist, uint16_t friend_num)
875 return num_ips; 876 return num_ips;
876} 877}
877 878
879
878/* Send the following packet to everyone who tells us they are connected to friend_id 880/* Send the following packet to everyone who tells us they are connected to friend_id
879 * returns the number of nodes it sent the packet to 881 * returns the number of nodes it sent the packet to
882 *
883 * Only works if more than (MAX_FRIEND_CLIENTS / 2) return an ip for friend.
880 */ 884 */
881int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length) 885int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
882{ 886{
@@ -886,6 +890,13 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
886 return 0; 890 return 0;
887 891
888 uint32_t i, sent = 0; 892 uint32_t i, sent = 0;
893
894 IP_Port ip_list[MAX_FRIEND_CLIENTS];
895 int ip_num = friend_iplist(ip_list, num);
896
897 if (ip_num < (MAX_FRIEND_CLIENTS / 2))
898 return 0;
899
889 uint64_t temp_time = unix_time(); 900 uint64_t temp_time = unix_time();
890 Friend *friend = &friends_list[num]; 901 Friend *friend = &friends_list[num];
891 Client_data *client; 902 Client_data *client;
@@ -895,7 +906,6 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
895 906
896 /*If ip is not zero and node is good */ 907 /*If ip is not zero and node is good */
897 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 908 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
898
899 if (sendpacket(client->ip_port, packet, length) == length) 909 if (sendpacket(client->ip_port, packet, length) == length)
900 ++sent; 910 ++sent;
901 } 911 }