diff options
Diffstat (limited to 'core/DHT.h')
-rw-r--r-- | core/DHT.h | 62 |
1 files changed, 5 insertions, 57 deletions
@@ -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 |