diff options
Diffstat (limited to 'testing/experiment/group_chats_test.c')
-rw-r--r-- | testing/experiment/group_chats_test.c | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/testing/experiment/group_chats_test.c b/testing/experiment/group_chats_test.c deleted file mode 100644 index 04fee327..00000000 --- a/testing/experiment/group_chats_test.c +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | #include "../../toxcore/group_chats.h" | ||
2 | #define NUM_CHATS 8 | ||
3 | |||
4 | #if defined(_WIN32) || defined(__WIN32__) || defined (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 | |||
57 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | ||
58 | { | ||
59 | printf("%u: %s | %u\n", peer_number, message, length); | ||
60 | } | ||
61 | |||
62 | int main() | ||
63 | { | ||
64 | IP ip; | ||
65 | ip.uint32 = 0; | ||
66 | uint32_t i; | ||
67 | |||
68 | |||
69 | for (i = 0; i < NUM_CHATS; ++i) { | ||
70 | chats[i] = new_groupchat(new_networking(ip, 12745)); | ||
71 | |||
72 | if (chats[i] == 0) | ||
73 | exit(1); | ||
74 | |||
75 | networking_registerhandler(chats[i]->net, 48, &handle_groupchatpacket, chats[i]); | ||
76 | callback_groupmessage(chats[i], &print_message, 0); | ||
77 | } | ||
78 | |||
79 | printf("ok\n"); | ||
80 | IP_Port ip_port; | ||
81 | ip_port.ip.uint32 = 0; | ||
82 | ip_port.ip.uint8[0] = 127; | ||
83 | ip_port.ip.uint8[3] = 1; | ||
84 | ip_port.port = htons(12745); | ||
85 | |||
86 | for (i = 0; i < NUM_CHATS; ++i) { | ||
87 | group_newpeer(chats[0], chats[i]->self_public_key); | ||
88 | chat_bootstrap(chats[i], ip_port, chats[0]->self_public_key); | ||
89 | printf("%u\n", i); | ||
90 | } | ||
91 | |||
92 | while (1) { | ||
93 | for (i = 0; i < NUM_CHATS; ++i) { | ||
94 | networking_poll(chats[i]->net); | ||
95 | do_groupchat(chats[i]); | ||
96 | printf("%u\n", chats[i]->numpeers); | ||
97 | print_close(chats[i]->close); | ||
98 | print_group(chats[i]); | ||
99 | } | ||
100 | |||
101 | c_sleep(100); | ||
102 | } | ||
103 | |||
104 | return 0; | ||
105 | } | ||