diff options
Diffstat (limited to 'testing/DHT_test.c')
-rw-r--r-- | testing/DHT_test.c | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 3883f3a7..8ab9157e 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -28,8 +28,8 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | //#include "../core/network.h" | 30 | //#include "../core/network.h" |
31 | #include "../core/DHT.c" | 31 | #include "../core/DHT.h" |
32 | #include "../core/friend_requests.c" | 32 | #include "../core/friend_requests.h" |
33 | #include "misc_tools.h" | 33 | #include "misc_tools.h" |
34 | 34 | ||
35 | #include <string.h> | 35 | #include <string.h> |
@@ -48,7 +48,7 @@ | |||
48 | 48 | ||
49 | #define PORT 33445 | 49 | #define PORT 33445 |
50 | 50 | ||
51 | void print_clientlist() | 51 | void print_clientlist(DHT *dht) |
52 | { | 52 | { |
53 | uint32_t i, j; | 53 | uint32_t i, j; |
54 | IP_Port p_ip; | 54 | IP_Port p_ip; |
@@ -58,34 +58,34 @@ void print_clientlist() | |||
58 | printf("ClientID: "); | 58 | printf("ClientID: "); |
59 | 59 | ||
60 | for (j = 0; j < 32; j++) { | 60 | for (j = 0; j < 32; j++) { |
61 | printf("%02hhX", close_clientlist[i].client_id[j]); | 61 | printf("%02hhX", dht->close_clientlist[i].client_id[j]); |
62 | } | 62 | } |
63 | 63 | ||
64 | p_ip = close_clientlist[i].ip_port; | 64 | p_ip = dht->close_clientlist[i].ip_port; |
65 | printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 65 | printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
66 | printf("\nTimestamp: %llu", (long long unsigned int) close_clientlist[i].timestamp); | 66 | printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp); |
67 | printf("\nLast pinged: %llu\n", (long long unsigned int) close_clientlist[i].last_pinged); | 67 | printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged); |
68 | p_ip = close_clientlist[i].ret_ip_port; | 68 | p_ip = dht->close_clientlist[i].ret_ip_port; |
69 | printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 69 | printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
70 | printf("Timestamp: %llu\n", (long long unsigned int) close_clientlist[i].ret_timestamp); | 70 | printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | void print_friendlist() | 74 | void print_friendlist(DHT *dht) |
75 | { | 75 | { |
76 | uint32_t i, j, k; | 76 | uint32_t i, j, k; |
77 | IP_Port p_ip; | 77 | IP_Port p_ip; |
78 | printf("_________________FRIENDS__________________________________\n"); | 78 | printf("_________________FRIENDS__________________________________\n"); |
79 | 79 | ||
80 | for (k = 0; k < num_friends; k++) { | 80 | for (k = 0; k < dht->num_friends; k++) { |
81 | printf("FRIEND %u\n", k); | 81 | printf("FRIEND %u\n", k); |
82 | printf("ID: "); | 82 | printf("ID: "); |
83 | 83 | ||
84 | for (j = 0; j < 32; j++) { | 84 | for (j = 0; j < 32; j++) { |
85 | printf("%c", friends_list[k].client_id[j]); | 85 | printf("%c", dht->friends_list[k].client_id[j]); |
86 | } | 86 | } |
87 | 87 | ||
88 | p_ip = DHT_getfriendip(friends_list[k].client_id); | 88 | p_ip = DHT_getfriendip(dht, dht->friends_list[k].client_id); |
89 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 89 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
90 | 90 | ||
91 | printf("\nCLIENTS IN LIST:\n\n"); | 91 | printf("\nCLIENTS IN LIST:\n\n"); |
@@ -94,19 +94,19 @@ void print_friendlist() | |||
94 | printf("ClientID: "); | 94 | printf("ClientID: "); |
95 | 95 | ||
96 | for (j = 0; j < 32; j++) { | 96 | for (j = 0; j < 32; j++) { |
97 | if (friends_list[k].client_list[i].client_id[j] < 16) | 97 | if (dht->friends_list[k].client_list[i].client_id[j] < 16) |
98 | printf("0"); | 98 | printf("0"); |
99 | 99 | ||
100 | printf("%hhX", friends_list[k].client_list[i].client_id[j]); | 100 | printf("%hhX", dht->friends_list[k].client_list[i].client_id[j]); |
101 | } | 101 | } |
102 | 102 | ||
103 | p_ip = friends_list[k].client_list[i].ip_port; | 103 | p_ip = dht->friends_list[k].client_list[i].ip_port; |
104 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 104 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
105 | printf("\nTimestamp: %llu", (long long unsigned int) friends_list[k].client_list[i].timestamp); | 105 | printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp); |
106 | printf("\nLast pinged: %llu\n", (long long unsigned int) friends_list[k].client_list[i].last_pinged); | 106 | printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged); |
107 | p_ip = friends_list[k].client_list[i].ret_ip_port; | 107 | p_ip = dht->friends_list[k].client_list[i].ret_ip_port; |
108 | printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 108 | printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
109 | printf("Timestamp: %llu\n", (long long unsigned int)friends_list[k].client_list[i].ret_timestamp); | 109 | printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | } | 112 | } |
@@ -130,21 +130,28 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | |||
130 | int main(int argc, char *argv[]) | 130 | int main(int argc, char *argv[]) |
131 | { | 131 | { |
132 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); | 132 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); |
133 | /* initialize networking */ | ||
134 | /* bind to ip 0.0.0.0:PORT */ | ||
135 | IP ip; | ||
136 | ip.i = 0; | ||
137 | |||
138 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | ||
139 | init_cryptopackets(dht); | ||
133 | 140 | ||
134 | if (argc < 4) { | 141 | if (argc < 4) { |
135 | printf("usage %s ip port public_key\n", argv[0]); | 142 | printf("usage %s ip port public_key\n", argv[0]); |
136 | exit(0); | 143 | exit(0); |
137 | } | 144 | } |
138 | 145 | ||
139 | new_keys(); | 146 | new_keys(dht->c); |
140 | printf("OUR ID: "); | 147 | printf("OUR ID: "); |
141 | uint32_t i; | 148 | uint32_t i; |
142 | 149 | ||
143 | for (i = 0; i < 32; i++) { | 150 | for (i = 0; i < 32; i++) { |
144 | if (self_public_key[i] < 16) | 151 | if (dht->c->self_public_key[i] < 16) |
145 | printf("0"); | 152 | printf("0"); |
146 | 153 | ||
147 | printf("%hhX", self_public_key[i]); | 154 | printf("%hhX", dht->c->self_public_key[i]); |
148 | } | 155 | } |
149 | 156 | ||
150 | char temp_id[128]; | 157 | char temp_id[128]; |
@@ -153,13 +160,7 @@ int main(int argc, char *argv[]) | |||
153 | if (scanf("%s", temp_id) != 1) | 160 | if (scanf("%s", temp_id) != 1) |
154 | exit(0); | 161 | exit(0); |
155 | 162 | ||
156 | DHT_addfriend(hex_string_to_bin(temp_id)); | 163 | DHT_addfriend(dht, hex_string_to_bin(temp_id)); |
157 | |||
158 | /* initialize networking */ | ||
159 | /* bind to ip 0.0.0.0:PORT */ | ||
160 | IP ip; | ||
161 | ip.i = 0; | ||
162 | init_networking(ip, PORT); | ||
163 | 164 | ||
164 | 165 | ||
165 | perror("Initialization"); | 166 | perror("Initialization"); |
@@ -170,7 +171,7 @@ int main(int argc, char *argv[]) | |||
170 | * bootstrap_ip_port.ip.c[2] = 0; | 171 | * bootstrap_ip_port.ip.c[2] = 0; |
171 | * bootstrap_ip_port.ip.c[3] = 1; */ | 172 | * bootstrap_ip_port.ip.c[3] = 1; */ |
172 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | 173 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); |
173 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 174 | DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); |
174 | 175 | ||
175 | /* | 176 | /* |
176 | IP_Port ip_port; | 177 | IP_Port ip_port; |
@@ -178,12 +179,9 @@ int main(int argc, char *argv[]) | |||
178 | uint32_t length; | 179 | uint32_t length; |
179 | */ | 180 | */ |
180 | 181 | ||
181 | DHT_init(); | ||
182 | friendreq_init(); | ||
183 | |||
184 | while (1) { | 182 | while (1) { |
185 | 183 | ||
186 | doDHT(); | 184 | do_DHT(dht); |
187 | 185 | ||
188 | /* slvrTODO: | 186 | /* slvrTODO: |
189 | while(receivepacket(&ip_port, data, &length) != -1) { | 187 | while(receivepacket(&ip_port, data, &length) != -1) { |
@@ -195,13 +193,12 @@ int main(int argc, char *argv[]) | |||
195 | } | 193 | } |
196 | } | 194 | } |
197 | */ | 195 | */ |
198 | networking_poll(); | 196 | networking_poll(dht->c->lossless_udp->net); |
199 | 197 | ||
200 | print_clientlist(); | 198 | print_clientlist(dht); |
201 | print_friendlist(); | 199 | print_friendlist(dht); |
202 | c_sleep(300); | 200 | c_sleep(300); |
203 | } | 201 | } |
204 | 202 | ||
205 | shutdown_networking(); | ||
206 | return 0; | 203 | return 0; |
207 | } | 204 | } |