summaryrefslogtreecommitdiff
path: root/testing/DHT_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-06-25 09:19:01 -0400
committerirungentoo <irungentoo@gmail.com>2013-06-25 09:19:01 -0400
commitc93858110bb17ce35143bae7ba9aa68fac93f46b (patch)
treecf2df0b4b2af4d829e3583fedc1fe7e30f666a57 /testing/DHT_test.c
parentb9563fd9e27261ef3d48cb82decfa198e61cca86 (diff)
DHT almost done, started testing. Fixed ADDR compiling problem. No more warnings with GCC and clang.
Diffstat (limited to 'testing/DHT_test.c')
-rw-r--r--testing/DHT_test.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index c7caf7d7..fae4e001 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -16,16 +16,34 @@
16 16
17#else 17#else
18#include <unistd.h> 18#include <unistd.h>
19#include <arpa/inet.h>
19#define c_sleep(x) usleep(1000*x) 20#define c_sleep(x) usleep(1000*x)
20 21
21#endif 22#endif
22 23
23#define PORT 33445 24#define PORT 33445
24 25
25 26void print_clientlist()
27{
28 uint32_t i, j;
29 IP_Port p_ip;
30 printf("___________________________________________________\n");
31 for(i = 0; i < 4; i++)
32 {
33 printf("ClientID: ");
34 for(j = 0; j < 32; j++)
35 {
36 printf("%c", close_clientlist[i].client_id[j]);
37 }
38 p_ip = close_clientlist[i].ip_port;
39 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));
40 printf("\nTimestamp: %u\n", close_clientlist[i].timestamp);
41 }
42}
26 43
27int main(int argc, char *argv[]) 44int main(int argc, char *argv[])
28{ 45{
46 memcpy(self_client_id,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",32);
29 #ifdef WIN32 47 #ifdef WIN32
30 WSADATA wsaData; 48 WSADATA wsaData;
31 if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) 49 if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR)
@@ -52,9 +70,9 @@ int main(int argc, char *argv[])
52 #endif 70 #endif
53 71
54 //Bind our socket to port PORT and address 0.0.0.0 72 //Bind our socket to port PORT and address 0.0.0.0
55 ADDR addr = {.family = AF_INET, .ip.i = 0, .port = htons(PORT)}; 73 ADDR addr = {AF_INET, htons(PORT), {{0}}};
56 bind(sock, (struct sockaddr*)&addr, sizeof(addr)); 74 bind(sock, (struct sockaddr*)&addr, sizeof(addr));
57 75 perror("Initialization");
58 IP_Port bootstrap_ip_port; 76 IP_Port bootstrap_ip_port;
59 bootstrap_ip_port.port = htons(atoi(argv[2])); 77 bootstrap_ip_port.port = htons(atoi(argv[2]));
60 //bootstrap_ip_port.ip.c[0] = 127; 78 //bootstrap_ip_port.ip.c[0] = 127;
@@ -75,7 +93,7 @@ int main(int argc, char *argv[])
75 93
76 doDHT(); 94 doDHT();
77 95
78 if(recievepacket(&ip_port, data, &length) != -1) 96 while(recievepacket(&ip_port, data, &length) != -1)
79 { 97 {
80 if(DHT_recvpacket(data, length, ip_port)) 98 if(DHT_recvpacket(data, length, ip_port))
81 { 99 {
@@ -90,7 +108,8 @@ int main(int argc, char *argv[])
90 printf("Received handled packet with length: %u\n", length); 108 printf("Received handled packet with length: %u\n", length);
91 } 109 }
92 } 110 }
93 c_sleep(100); 111 print_clientlist();
112 c_sleep(300);
94 } 113 }
95 114
96 #ifdef WIN32 115 #ifdef WIN32