summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-20 15:53:15 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-20 15:53:15 -0400
commit747c290269db58f68ce05e976af974f3904ac3d0 (patch)
tree86759848cbd147668eb27a115195f9c7998b347b /testing
parent2f66b312442f15f24adaf7216f5bc61390fdc016 (diff)
Fixed DHT_test.c and added some checks.
Diffstat (limited to 'testing')
-rw-r--r--testing/DHT_test.c75
1 files changed, 35 insertions, 40 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 3883f3a7..c128f25c 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
51void print_clientlist() 51void 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
74void print_friendlist() 74void 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,27 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
130int main(int argc, char *argv[]) 130int 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)));
133 139
134 if (argc < 4) { 140 if (argc < 4) {
135 printf("usage %s ip port public_key\n", argv[0]); 141 printf("usage %s ip port public_key\n", argv[0]);
136 exit(0); 142 exit(0);
137 } 143 }
138 144
139 new_keys(); 145 new_keys(dht->c);
140 printf("OUR ID: "); 146 printf("OUR ID: ");
141 uint32_t i; 147 uint32_t i;
142 148
143 for (i = 0; i < 32; i++) { 149 for (i = 0; i < 32; i++) {
144 if (self_public_key[i] < 16) 150 if (dht->c->self_public_key[i] < 16)
145 printf("0"); 151 printf("0");
146 152
147 printf("%hhX", self_public_key[i]); 153 printf("%hhX", dht->c->self_public_key[i]);
148 } 154 }
149 155
150 char temp_id[128]; 156 char temp_id[128];
@@ -153,13 +159,7 @@ int main(int argc, char *argv[])
153 if (scanf("%s", temp_id) != 1) 159 if (scanf("%s", temp_id) != 1)
154 exit(0); 160 exit(0);
155 161
156 DHT_addfriend(hex_string_to_bin(temp_id)); 162 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 163
164 164
165 perror("Initialization"); 165 perror("Initialization");
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
170 * bootstrap_ip_port.ip.c[2] = 0; 170 * bootstrap_ip_port.ip.c[2] = 0;
171 * bootstrap_ip_port.ip.c[3] = 1; */ 171 * bootstrap_ip_port.ip.c[3] = 1; */
172 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 172 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
173 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 173 DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
174 174
175 /* 175 /*
176 IP_Port ip_port; 176 IP_Port ip_port;
@@ -178,12 +178,9 @@ int main(int argc, char *argv[])
178 uint32_t length; 178 uint32_t length;
179 */ 179 */
180 180
181 DHT_init();
182 friendreq_init();
183
184 while (1) { 181 while (1) {
185 182
186 doDHT(); 183 do_DHT(dht);
187 184
188 /* slvrTODO: 185 /* slvrTODO:
189 while(receivepacket(&ip_port, data, &length) != -1) { 186 while(receivepacket(&ip_port, data, &length) != -1) {
@@ -195,13 +192,11 @@ int main(int argc, char *argv[])
195 } 192 }
196 } 193 }
197 */ 194 */
198 networking_poll(); 195 networking_poll(dht->c->lossless_udp->net);
199 196
200 print_clientlist(); 197 print_clientlist(dht);
201 print_friendlist(); 198 print_friendlist(dht);
202 c_sleep(300); 199 c_sleep(300);
203 } 200 }
204
205 shutdown_networking();
206 return 0; 201 return 0;
207} 202}