diff options
Diffstat (limited to 'core/DHT.h')
-rw-r--r-- | core/DHT.h | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -18,6 +18,10 @@ | |||
18 | 18 | ||
19 | #endif | 19 | #endif |
20 | 20 | ||
21 | //Current time, unix format | ||
22 | #define unix_time() ((uint32_t)time(NULL)) | ||
23 | |||
24 | #define CLIENT_ID_SIZE 32 | ||
21 | 25 | ||
22 | typedef union | 26 | typedef union |
23 | { | 27 | { |
@@ -36,7 +40,7 @@ typedef struct | |||
36 | 40 | ||
37 | typedef struct | 41 | typedef struct |
38 | { | 42 | { |
39 | char client_id[32]; | 43 | char client_id[CLIENT_ID_SIZE]; |
40 | IP_Port ip_port; | 44 | IP_Port ip_port; |
41 | uint32_t timestamp; | 45 | uint32_t timestamp; |
42 | 46 | ||
@@ -45,7 +49,7 @@ typedef struct | |||
45 | 49 | ||
46 | typedef struct | 50 | typedef struct |
47 | { | 51 | { |
48 | char client_id[32]; | 52 | char client_id[CLIENT_ID_SIZE]; |
49 | Client_data client_list[8]; | 53 | Client_data client_list[8]; |
50 | 54 | ||
51 | }Friend; | 55 | }Friend; |
@@ -73,18 +77,18 @@ typedef struct | |||
73 | 77 | ||
74 | 78 | ||
75 | //Add a new friend to the friends list | 79 | //Add a new friend to the friends list |
76 | //client_id must be 32 bytes long. | 80 | //client_id must be CLIENT_ID_SIZE bytes long. |
77 | void addfriend(char * client_id); | 81 | void addfriend(char * client_id); |
78 | 82 | ||
79 | //Delete a friend from the friends list | 83 | //Delete a friend from the friends list |
80 | //client_id must be 32 bytes long. | 84 | //client_id must be CLIENT_ID_SIZE bytes long. |
81 | //returns 0 if success | 85 | //returns 0 if success |
82 | //returns 1 if failure (client_id not in friends list) | 86 | //returns 1 if failure (client_id not in friends list) |
83 | char delfriend(char * client_id); | 87 | char delfriend(char * client_id); |
84 | 88 | ||
85 | 89 | ||
86 | //Get ip of friend | 90 | //Get ip of friend |
87 | //client_id must be 32 bytes long. | 91 | //client_id must be CLIENT_ID_SIZE bytes long. |
88 | //ip must be 4 bytes long. | 92 | //ip must be 4 bytes long. |
89 | //port must be 2 bytes long. | 93 | //port must be 2 bytes long. |
90 | //returns ip if success | 94 | //returns ip if success |
@@ -110,7 +114,7 @@ void bootstrap(IP_Port ip_port); | |||
110 | //Global variables | 114 | //Global variables |
111 | 115 | ||
112 | //Our client id | 116 | //Our client id |
113 | char self_client_id[32]; | 117 | char self_client_id[CLIENT_ID_SIZE]; |
114 | 118 | ||
115 | //Our UDP socket. | 119 | //Our UDP socket. |
116 | //We only use one so it's much easier to have it as a global variable | 120 | //We only use one so it's much easier to have it as a global variable |