summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 6ecae785..6b65e763 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -1,39 +1,13 @@
1#include "DHT.h" 1/* DHT.c
2 2*
3 3* An implementation of the DHT as seen in docs/DHT.txt
4//Basic network functions: 4*
5//TODO: put them somewhere else than here 5*/
6
7//Function to send packet(data) of length length to ip_port
8int sendpacket(IP_Port ip_port, char * data, uint32_t length)
9{
10 ADDR addr = {AF_INET, ip_port.port, ip_port.ip};
11 return sendto(sock, data, length, 0, (struct sockaddr *)&addr, sizeof(addr));
12
13}
14 6
15//Function to recieve data, ip and port of sender is put into ip_port
16//the packet data into data
17//the packet length into length.
18//dump all empty packets.
19int recievepacket(IP_Port * ip_port, char * data, uint32_t * length)
20{
21 ADDR addr;
22 uint32_t addrlen = sizeof(addr);
23 (*(int *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
24 if(*(int *)length <= 0)
25 {
26 //nothing recieved
27 //or empty packet
28 return -1;
29 }
30 ip_port->ip = addr.ip;
31 ip_port->port = addr.port;
32 return 0;
33
34}
35 7
8#include "DHT.h"
36 9
10char self_client_id[CLIENT_ID_SIZE];
37 11
38//Compares client_id1 and client_id2 with client_id 12//Compares client_id1 and client_id2 with client_id
39//return 0 if both are same distance 13//return 0 if both are same distance
@@ -744,7 +718,7 @@ void doFriends()
744static uint32_t close_lastgetnodes; 718static uint32_t close_lastgetnodes;
745 719
746//Ping each client in the close nodes list every 60 seconds. 720//Ping each client in the close nodes list every 60 seconds.
747//Send a get nodes request every 20 seconds to a random good node int the list. 721//Send a get nodes request every 20 seconds to a random good node in the list.
748void doClose()//tested 722void doClose()//tested
749{ 723{
750 uint32_t i; 724 uint32_t i;