diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-05 17:00:41 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-05 17:00:41 -0400 |
commit | cc8a536cb07484396354c4880f3631666a1cf874 (patch) | |
tree | 708f598799ebef55e2b3f261b96472b7099e99e8 /testing/experiment/group_chats_test.c | |
parent | c59975dd7ecdabe864f341b699f986e5e474acb6 (diff) |
Base of group chats seems to be working now.
Diffstat (limited to 'testing/experiment/group_chats_test.c')
-rw-r--r-- | testing/experiment/group_chats_test.c | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/testing/experiment/group_chats_test.c b/testing/experiment/group_chats_test.c index f08e4e15..8ef5b10e 100644 --- a/testing/experiment/group_chats_test.c +++ b/testing/experiment/group_chats_test.c | |||
@@ -1,18 +1,97 @@ | |||
1 | #include "group_chats.h" | 1 | #include "group_chats.h" |
2 | #define NUM_CHATS 8 | 2 | #define NUM_CHATS 8 |
3 | 3 | ||
4 | #ifdef WIN32 | ||
5 | #define c_sleep(x) Sleep(1*x) | ||
6 | #else | ||
7 | #define c_sleep(x) usleep(1000*x) | ||
8 | #endif | ||
9 | Group_Chat *chats[NUM_CHATS]; | ||
10 | |||
11 | void print_close(Group_Close *close) | ||
12 | { | ||
13 | uint32_t i, j; | ||
14 | IP_Port p_ip; | ||
15 | printf("___________________CLOSE________________________________\n"); | ||
16 | |||
17 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; i++) { | ||
18 | printf("ClientID: "); | ||
19 | |||
20 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
21 | printf("%02hhX", close[i].client_id[j]); | ||
22 | } | ||
23 | |||
24 | p_ip = close[i].ip_port; | ||
25 | printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], | ||
26 | ntohs(p_ip.port)); | ||
27 | printf("\nTimestamp: %llu", (long long unsigned int) close[i].last_recv); | ||
28 | printf("\n"); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | void print_group(Group_Chat *chat) | ||
33 | { | ||
34 | uint32_t i, j; | ||
35 | printf("-----------------\nClientID: "); | ||
36 | |||
37 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
38 | printf("%02hhX", chat->self_public_key[j]); | ||
39 | } | ||
40 | |||
41 | printf("\n___________________GROUP________________________________\n"); | ||
42 | |||
43 | for (i = 0; i < chat->numpeers; i++) { | ||
44 | printf("ClientID: "); | ||
45 | |||
46 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
47 | printf("%02hhX", chat->group[i].client_id[j]); | ||
48 | } | ||
49 | |||
50 | printf("\nTimestamp: %llu", (long long unsigned int) chat->group[i].last_recv); | ||
51 | printf("\nlast_pinged: %llu", (long long unsigned int) chat->group[i].last_pinged); | ||
52 | printf("\npingid: %llu", (long long unsigned int) chat->group[i].pingid); | ||
53 | printf("\n"); | ||
54 | } | ||
55 | } | ||
56 | |||
4 | int main() | 57 | int main() |
5 | { | 58 | { |
6 | IP ip; | 59 | IP ip; |
7 | ip.uint32 = 0; | 60 | ip.uint32 = 0; |
8 | uint32_t i; | 61 | uint32_t i; |
9 | Group_Chat *chats[NUM_CHATS]; | 62 | |
10 | 63 | ||
11 | for (i = 0; i < NUM_CHATS; ++i) { | 64 | for (i = 0; i < NUM_CHATS; ++i) { |
12 | chats[i] = new_groupchat(new_networking(ip, 1234)); | 65 | chats[i] = new_groupchat(new_networking(ip, 12745)); |
13 | 66 | ||
14 | if (chats[i] == 0) | 67 | if (chats[i] == 0) |
15 | exit(1); | 68 | exit(1); |
69 | |||
70 | networking_registerhandler(chats[i]->net, 48, &handle_groupchatpacket, chats[i]); | ||
71 | } | ||
72 | |||
73 | printf("ok\n"); | ||
74 | IP_Port ip_port; | ||
75 | ip_port.ip.uint32 = 0; | ||
76 | ip_port.ip.uint8[0] = 127; | ||
77 | ip_port.ip.uint8[3] = 1; | ||
78 | ip_port.port = htons(12745); | ||
79 | |||
80 | for (i = 0; i < NUM_CHATS; ++i) { | ||
81 | chat_bootstrap(chats[i], ip_port, chats[0]->self_public_key); | ||
82 | printf("%u\n", i); | ||
83 | } | ||
84 | |||
85 | while (1) { | ||
86 | for (i = 0; i < NUM_CHATS; ++i) { | ||
87 | networking_poll(chats[i]->net); | ||
88 | do_groupchat(chats[i]); | ||
89 | printf("%u\n", chats[i]->numpeers); | ||
90 | print_close(chats[i]->close); | ||
91 | print_group(chats[i]); | ||
92 | } | ||
93 | |||
94 | c_sleep(100); | ||
16 | } | 95 | } |
17 | 96 | ||
18 | return 0; | 97 | return 0; |