diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-07 11:54:25 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-07 11:54:25 -0400 |
commit | a632d960f8d8095566530d1d0dc1393f02e1e07f (patch) | |
tree | 77af042fcf487468691b2dbfc7273a05fd133f48 /core | |
parent | 2528ec148c6b1865a489c232800377f1d3952f04 (diff) |
Fixed to be confilcts with the DHT and the messenger part.
Diffstat (limited to 'core')
-rw-r--r-- | core/DHT.c | 65 | ||||
-rw-r--r-- | core/DHT.h | 62 |
2 files changed, 66 insertions, 61 deletions
@@ -27,8 +27,65 @@ | |||
27 | 27 | ||
28 | #include "DHT.h" | 28 | #include "DHT.h" |
29 | 29 | ||
30 | |||
31 | typedef 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 | ||
40 | typedef struct | ||
41 | { | ||
42 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
43 | Client_data client_list[MAX_FRIEND_CLIENTS]; | ||
44 | |||
45 | }Friend; | ||
46 | |||
47 | |||
48 | typedef struct | ||
49 | { | ||
50 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
51 | IP_Port ip_port; | ||
52 | }Node_format; | ||
53 | |||
54 | typedef struct | ||
55 | { | ||
56 | IP_Port ip_port; | ||
57 | uint32_t ping_id; | ||
58 | uint32_t timestamp; | ||
59 | |||
60 | }Pinged; | ||
61 | |||
62 | |||
30 | uint8_t self_client_id[CLIENT_ID_SIZE]; | 63 | uint8_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 | ||
69 | Client_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. | ||
76 | Friend friends_list[MAX_FRIENDS]; | ||
77 | uint16_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 | |||
82 | Pinged pings[LPING_ARRAY]; | ||
83 | |||
84 | #define LSEND_NODES_ARRAY LPING_ARRAY/2 | ||
85 | |||
86 | Pinged 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 | ||
596 | int addfriend(uint8_t * client_id) | 653 | int 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 | ||
613 | int delfriend(uint8_t * client_id) | 670 | int 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. |
633 | IP_Port getfriendip(uint8_t * client_id) | 690 | IP_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 | ||
788 | void bootstrap(IP_Port ip_port) | 845 | void DHT_bootstrap(IP_Port ip_port) |
789 | { | 846 | { |
790 | 847 | ||
791 | getnodes(ip_port, self_client_id); | 848 | getnodes(ip_port, self_client_id); |
@@ -34,49 +34,19 @@ | |||
34 | //size of the client_id in bytes | 34 | //size of the client_id in bytes |
35 | #define CLIENT_ID_SIZE 32 | 35 | #define CLIENT_ID_SIZE 32 |
36 | 36 | ||
37 | typedef struct | ||
38 | { | ||
39 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
40 | IP_Port ip_port; | ||
41 | uint32_t timestamp; | ||
42 | uint32_t last_pinged; | ||
43 | }Client_data; | ||
44 | //maximum number of clients stored per friend. | ||
45 | #define MAX_FRIEND_CLIENTS 8 | ||
46 | typedef struct | ||
47 | { | ||
48 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
49 | Client_data client_list[MAX_FRIEND_CLIENTS]; | ||
50 | |||
51 | }Friend; | ||
52 | |||
53 | |||
54 | typedef struct | ||
55 | { | ||
56 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
57 | IP_Port ip_port; | ||
58 | }Node_format; | ||
59 | |||
60 | typedef struct | ||
61 | { | ||
62 | IP_Port ip_port; | ||
63 | uint32_t ping_id; | ||
64 | uint32_t timestamp; | ||
65 | |||
66 | }Pinged; | ||
67 | 37 | ||
68 | 38 | ||
69 | //Add a new friend to the friends list | 39 | //Add a new friend to the friends list |
70 | //client_id must be CLIENT_ID_SIZE bytes long. | 40 | //client_id must be CLIENT_ID_SIZE bytes long. |
71 | //returns 0 if success | 41 | //returns 0 if success |
72 | //returns 1 if failure (friends list is full) | 42 | //returns 1 if failure (friends list is full) |
73 | int addfriend(uint8_t * client_id); | 43 | int DHT_addfriend(uint8_t * client_id); |
74 | 44 | ||
75 | //Delete a friend from the friends list | 45 | //Delete a friend from the friends list |
76 | //client_id must be CLIENT_ID_SIZE bytes long. | 46 | //client_id must be CLIENT_ID_SIZE bytes long. |
77 | //returns 0 if success | 47 | //returns 0 if success |
78 | //returns 1 if failure (client_id not in friends list) | 48 | //returns 1 if failure (client_id not in friends list) |
79 | int delfriend(uint8_t * client_id); | 49 | int DHT_delfriend(uint8_t * client_id); |
80 | 50 | ||
81 | 51 | ||
82 | //Get ip of friend | 52 | //Get ip of friend |
@@ -86,7 +56,7 @@ int delfriend(uint8_t * client_id); | |||
86 | //returns ip if success | 56 | //returns ip if success |
87 | //returns ip of 0 if failure (This means the friend is either offline or we have not found him yet.) | 57 | //returns ip of 0 if failure (This means the friend is either offline or we have not found him yet.) |
88 | //returns ip of 1 if friend is not in list. | 58 | //returns ip of 1 if friend is not in list. |
89 | IP_Port getfriendip(uint8_t * client_id); | 59 | IP_Port DHT_getfriendip(uint8_t * client_id); |
90 | 60 | ||
91 | 61 | ||
92 | //Run this function at least a couple times per second (It's the main loop) | 62 | //Run this function at least a couple times per second (It's the main loop) |
@@ -99,7 +69,7 @@ int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source); | |||
99 | 69 | ||
100 | //Use this function to bootstrap the client | 70 | //Use this function to bootstrap the client |
101 | //Sends a get nodes request to the given ip port | 71 | //Sends a get nodes request to the given ip port |
102 | void bootstrap(IP_Port ip_port); | 72 | void DHT_bootstrap(IP_Port ip_port); |
103 | 73 | ||
104 | 74 | ||
105 | //TODO: | 75 | //TODO: |
@@ -112,27 +82,5 @@ void bootstrap(IP_Port ip_port); | |||
112 | extern uint8_t self_client_id[CLIENT_ID_SIZE]; | 82 | extern uint8_t self_client_id[CLIENT_ID_SIZE]; |
113 | 83 | ||
114 | 84 | ||
115 | //TODO: Move these out of here and put them into the .c file. | ||
116 | //A list of the clients mathematically closest to ours. | ||
117 | #define LCLIENT_LIST 32 | ||
118 | Client_data close_clientlist[LCLIENT_LIST]; | ||
119 | |||
120 | |||
121 | //Hard maximum number of friends | ||
122 | #define MAX_FRIENDS 256 | ||
123 | |||
124 | //Let's start with a static array for testing. | ||
125 | Friend friends_list[MAX_FRIENDS]; | ||
126 | uint16_t num_friends; | ||
127 | |||
128 | //The list of ip ports along with the ping_id of what we sent them and a timestamp | ||
129 | #define LPING_ARRAY 128 | ||
130 | |||
131 | Pinged pings[LPING_ARRAY]; | ||
132 | |||
133 | #define LSEND_NODES_ARRAY LPING_ARRAY/2 | ||
134 | |||
135 | Pinged send_nodes[LSEND_NODES_ARRAY]; | ||
136 | |||
137 | 85 | ||
138 | #endif \ No newline at end of file | 86 | #endif |