diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 1c5286e7..59b0233e 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -25,11 +25,12 @@ | |||
25 | 25 | ||
26 | #define PORT 33445 | 26 | #define PORT 33445 |
27 | 27 | ||
28 | |||
28 | void print_clientlist() | 29 | void print_clientlist() |
29 | { | 30 | { |
30 | uint32_t i, j; | 31 | uint32_t i, j; |
31 | IP_Port p_ip; | 32 | IP_Port p_ip; |
32 | printf("___________________________________________________\n"); | 33 | printf("___________________CLOSE________________________________\n"); |
33 | for(i = 0; i < 4; i++) | 34 | for(i = 0; i < 4; i++) |
34 | { | 35 | { |
35 | printf("ClientID: "); | 36 | printf("ClientID: "); |
@@ -43,9 +44,46 @@ void print_clientlist() | |||
43 | } | 44 | } |
44 | } | 45 | } |
45 | 46 | ||
47 | void print_friendlist() | ||
48 | { | ||
49 | uint32_t i, j, k; | ||
50 | IP_Port p_ip; | ||
51 | printf("_________________FRIENDS__________________________________\n"); | ||
52 | for(k = 0; k < num_friends; k++) | ||
53 | { | ||
54 | printf("FRIEND %u\n", k); | ||
55 | printf("ID: "); | ||
56 | for(j = 0; j < 32; j++) | ||
57 | { | ||
58 | printf("%c", friends_list[k].client_id[j]); | ||
59 | } | ||
60 | p_ip = getfriendip(friends_list[k].client_id); | ||
61 | 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)); | ||
62 | |||
63 | printf("\nCLIENTS IN LIST:\n\n "); | ||
64 | |||
65 | for(i = 0; i < 4; i++) | ||
66 | { | ||
67 | printf("ClientID: "); | ||
68 | for(j = 0; j < 32; j++) | ||
69 | { | ||
70 | printf("%X", friends_list[k].client_list[i].client_id[j]); | ||
71 | } | ||
72 | p_ip = friends_list[k].client_list[i].ip_port; | ||
73 | 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)); | ||
74 | printf("\nTimestamp: %u\n", friends_list[k].client_list[i].timestamp); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | |||
80 | |||
46 | int main(int argc, char *argv[]) | 81 | int main(int argc, char *argv[]) |
47 | { | 82 | { |
48 | memcpy(self_client_id,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",32); | 83 | srand(time(NULL)); |
84 | int randdomnum = rand(); | ||
85 | memcpy(self_client_id, &randdomnum, 4); | ||
86 | |||
49 | #ifdef WIN32 | 87 | #ifdef WIN32 |
50 | WSADATA wsaData; | 88 | WSADATA wsaData; |
51 | if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) | 89 | if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) |
@@ -54,10 +92,11 @@ int main(int argc, char *argv[]) | |||
54 | } | 92 | } |
55 | #endif | 93 | #endif |
56 | 94 | ||
57 | if (argc < 3) { | 95 | if (argc < 4) { |
58 | printf("usage %s ip port\n", argv[0]); | 96 | printf("usage %s ip port client_id\n", argv[0]); |
59 | exit(0); | 97 | exit(0); |
60 | } | 98 | } |
99 | addfriend(argv[3]); | ||
61 | 100 | ||
62 | //initialize our socket | 101 | //initialize our socket |
63 | sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | 102 | sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
@@ -115,6 +154,7 @@ int main(int argc, char *argv[]) | |||
115 | } | 154 | } |
116 | } | 155 | } |
117 | print_clientlist(); | 156 | print_clientlist(); |
157 | print_friendlist(); | ||
118 | c_sleep(300); | 158 | c_sleep(300); |
119 | } | 159 | } |
120 | 160 | ||