summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-07 11:54:25 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-07 11:54:25 -0400
commita632d960f8d8095566530d1d0dc1393f02e1e07f (patch)
tree77af042fcf487468691b2dbfc7273a05fd133f48 /core/DHT.c
parent2528ec148c6b1865a489c232800377f1d3952f04 (diff)
Fixed to be confilcts with the DHT and the messenger part.
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c65
1 files changed, 61 insertions, 4 deletions
diff --git a/core/DHT.c b/core/DHT.c
index d5af3a08..31a3fad3 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -27,8 +27,65 @@
27 27
28#include "DHT.h" 28#include "DHT.h"
29 29
30
31typedef struct
32{
33 uint8_t client_id[CLIENT_ID_SIZE];
34 IP_Port ip_port;
35 uint32_t timestamp;
36 uint32_t last_pinged;
37}Client_data;
38//maximum number of clients stored per friend.
39#define MAX_FRIEND_CLIENTS 8
40typedef struct
41{
42 uint8_t client_id[CLIENT_ID_SIZE];
43 Client_data client_list[MAX_FRIEND_CLIENTS];
44
45}Friend;
46
47
48typedef struct
49{
50 uint8_t client_id[CLIENT_ID_SIZE];
51 IP_Port ip_port;
52}Node_format;
53
54typedef struct
55{
56 IP_Port ip_port;
57 uint32_t ping_id;
58 uint32_t timestamp;
59
60}Pinged;
61
62
30uint8_t self_client_id[CLIENT_ID_SIZE]; 63uint8_t self_client_id[CLIENT_ID_SIZE];
31 64
65
66//TODO: Move these out of here and put them into the .c file.
67//A list of the clients mathematically closest to ours.
68#define LCLIENT_LIST 32
69Client_data close_clientlist[LCLIENT_LIST];
70
71
72//Hard maximum number of friends
73#define MAX_FRIENDS 256
74
75//Let's start with a static array for testing.
76Friend friends_list[MAX_FRIENDS];
77uint16_t num_friends;
78
79//The list of ip ports along with the ping_id of what we sent them and a timestamp
80#define LPING_ARRAY 128
81
82Pinged pings[LPING_ARRAY];
83
84#define LSEND_NODES_ARRAY LPING_ARRAY/2
85
86Pinged send_nodes[LSEND_NODES_ARRAY];
87
88
32//Compares client_id1 and client_id2 with client_id 89//Compares client_id1 and client_id2 with client_id
33//return 0 if both are same distance 90//return 0 if both are same distance
34//return 1 if client_id1 is closer. 91//return 1 if client_id1 is closer.
@@ -593,7 +650,7 @@ int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source)//tested
593 650
594 651
595 652
596int addfriend(uint8_t * client_id) 653int DHT_addfriend(uint8_t * client_id)
597{ 654{
598 //TODO:Maybe make the array of friends dynamic instead of a static array with MAX_FRIENDS 655 //TODO:Maybe make the array of friends dynamic instead of a static array with MAX_FRIENDS
599 if(MAX_FRIENDS > num_friends) 656 if(MAX_FRIENDS > num_friends)
@@ -610,7 +667,7 @@ int addfriend(uint8_t * client_id)
610 667
611 668
612 669
613int delfriend(uint8_t * client_id) 670int DHT_delfriend(uint8_t * client_id)
614{ 671{
615 uint32_t i; 672 uint32_t i;
616 for(i = 0; i < num_friends; i++) 673 for(i = 0; i < num_friends; i++)
@@ -630,7 +687,7 @@ int delfriend(uint8_t * client_id)
630 687
631 688
632//TODO: Optimize this. 689//TODO: Optimize this.
633IP_Port getfriendip(uint8_t * client_id) 690IP_Port DHT_getfriendip(uint8_t * client_id)
634{ 691{
635 uint32_t i, j; 692 uint32_t i, j;
636 IP_Port empty = {{{0}}, 0}; 693 IP_Port empty = {{{0}}, 0};
@@ -785,7 +842,7 @@ void doDHT()
785 842
786 843
787 844
788void bootstrap(IP_Port ip_port) 845void DHT_bootstrap(IP_Port ip_port)
789{ 846{
790 847
791 getnodes(ip_port, self_client_id); 848 getnodes(ip_port, self_client_id);