ffi-tox 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/ProjectTox-Core/AUTHORS +0 -0
  3. data/ProjectTox-Core/ChangeLog +0 -0
  4. data/ProjectTox-Core/INSTALL +370 -0
  5. data/ProjectTox-Core/INSTALL.md +455 -56
  6. data/ProjectTox-Core/Makefile.am +35 -0
  7. data/ProjectTox-Core/NEWS +0 -0
  8. data/ProjectTox-Core/README +43 -0
  9. data/ProjectTox-Core/README.md +34 -44
  10. data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
  11. data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
  12. data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
  13. data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
  14. data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
  15. data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
  16. data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
  17. data/ProjectTox-Core/auto_tests/helpers.h +15 -0
  18. data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
  19. data/ProjectTox-Core/auto_tests/network_test.c +171 -0
  20. data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
  21. data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
  22. data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
  23. data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
  24. data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
  25. data/ProjectTox-Core/autogen.sh +6 -0
  26. data/ProjectTox-Core/build/Makefile.am +14 -0
  27. data/ProjectTox-Core/configure.ac +694 -0
  28. data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
  29. data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
  30. data/ProjectTox-Core/dist-build/android-build.sh +59 -0
  31. data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
  32. data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
  33. data/ProjectTox-Core/docs/Group-Chats.md +71 -0
  34. data/ProjectTox-Core/docs/Hardening.txt +60 -0
  35. data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
  36. data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
  37. data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
  38. data/ProjectTox-Core/docs/TODO +62 -0
  39. data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
  40. data/ProjectTox-Core/docs/av_api.md +194 -0
  41. data/ProjectTox-Core/libtoxav.pc.in +11 -0
  42. data/ProjectTox-Core/libtoxcore.pc.in +11 -0
  43. data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
  44. data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
  45. data/ProjectTox-Core/m4/pkg.m4 +199 -0
  46. data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
  47. data/ProjectTox-Core/other/DHTnodes +3 -0
  48. data/ProjectTox-Core/other/Makefile.inc +20 -0
  49. data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
  50. data/ProjectTox-Core/other/tox.png +0 -0
  51. data/ProjectTox-Core/testing/DHT_test.c +170 -98
  52. data/ProjectTox-Core/testing/Makefile.inc +112 -0
  53. data/ProjectTox-Core/testing/Messenger_test.c +133 -69
  54. data/ProjectTox-Core/testing/dns3_test.c +115 -0
  55. data/ProjectTox-Core/testing/misc_tools.c +59 -13
  56. data/ProjectTox-Core/testing/nTox.c +1127 -264
  57. data/ProjectTox-Core/testing/nTox.h +10 -19
  58. data/ProjectTox-Core/testing/tox_shell.c +159 -0
  59. data/ProjectTox-Core/testing/tox_sync.c +299 -0
  60. data/ProjectTox-Core/tools/README +11 -0
  61. data/ProjectTox-Core/tools/astylerc +11 -0
  62. data/ProjectTox-Core/tools/pre-commit +17 -0
  63. data/ProjectTox-Core/toxav/Makefile.inc +36 -0
  64. data/ProjectTox-Core/toxav/codec.c +357 -0
  65. data/ProjectTox-Core/toxav/codec.h +116 -0
  66. data/ProjectTox-Core/toxav/msi.c +1949 -0
  67. data/ProjectTox-Core/toxav/msi.h +267 -0
  68. data/ProjectTox-Core/toxav/rtp.c +600 -0
  69. data/ProjectTox-Core/toxav/rtp.h +196 -0
  70. data/ProjectTox-Core/toxav/toxav.c +1148 -0
  71. data/ProjectTox-Core/toxav/toxav.h +389 -0
  72. data/ProjectTox-Core/toxcore/DHT.c +2521 -0
  73. data/ProjectTox-Core/toxcore/DHT.h +412 -0
  74. data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
  75. data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
  76. data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
  77. data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
  78. data/ProjectTox-Core/toxcore/Messenger.h +818 -0
  79. data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
  80. data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
  81. data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
  82. data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
  83. data/ProjectTox-Core/toxcore/assoc.c +1033 -0
  84. data/ProjectTox-Core/toxcore/assoc.h +104 -0
  85. data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
  86. data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
  87. data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
  88. data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
  89. data/ProjectTox-Core/toxcore/group_chats.c +837 -0
  90. data/ProjectTox-Core/toxcore/group_chats.h +199 -0
  91. data/ProjectTox-Core/toxcore/list.c +256 -0
  92. data/ProjectTox-Core/toxcore/list.h +85 -0
  93. data/ProjectTox-Core/toxcore/logger.c +153 -0
  94. data/ProjectTox-Core/toxcore/logger.h +84 -0
  95. data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
  96. data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
  97. data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
  98. data/ProjectTox-Core/toxcore/network.c +979 -0
  99. data/ProjectTox-Core/toxcore/network.h +367 -0
  100. data/ProjectTox-Core/toxcore/onion.c +540 -0
  101. data/ProjectTox-Core/toxcore/onion.h +150 -0
  102. data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
  103. data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
  104. data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
  105. data/ProjectTox-Core/toxcore/onion_client.h +253 -0
  106. data/ProjectTox-Core/toxcore/ping.c +346 -0
  107. data/ProjectTox-Core/toxcore/ping.h +47 -0
  108. data/ProjectTox-Core/toxcore/ping_array.c +162 -0
  109. data/ProjectTox-Core/toxcore/ping_array.h +75 -0
  110. data/ProjectTox-Core/toxcore/tox.c +940 -0
  111. data/ProjectTox-Core/toxcore/tox.h +734 -0
  112. data/ProjectTox-Core/toxcore/util.c +193 -0
  113. data/ProjectTox-Core/toxcore/util.h +63 -0
  114. data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
  115. data/ProjectTox-Core/toxdns/toxdns.c +238 -0
  116. data/ProjectTox-Core/toxdns/toxdns.h +88 -0
  117. data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
  118. data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
  119. data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
  120. data/interfaces/libtox.i +2 -6
  121. data/lib/ffi-tox/libtox.rb +406 -28
  122. metadata +124 -46
  123. data/ProjectTox-Core/CMakeLists.txt +0 -50
  124. data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
  125. data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
  126. data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
  127. data/ProjectTox-Core/core/CMakeLists.txt +0 -19
  128. data/ProjectTox-Core/core/DHT.c +0 -1104
  129. data/ProjectTox-Core/core/DHT.h +0 -111
  130. data/ProjectTox-Core/core/LAN_discovery.c +0 -79
  131. data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
  132. data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
  133. data/ProjectTox-Core/core/Messenger.c +0 -596
  134. data/ProjectTox-Core/core/Messenger.h +0 -165
  135. data/ProjectTox-Core/core/friend_requests.c +0 -131
  136. data/ProjectTox-Core/core/friend_requests.h +0 -51
  137. data/ProjectTox-Core/core/net_crypto.c +0 -575
  138. data/ProjectTox-Core/core/net_crypto.h +0 -134
  139. data/ProjectTox-Core/core/network.c +0 -205
  140. data/ProjectTox-Core/core/network.h +0 -134
  141. data/ProjectTox-Core/docs/commands.md +0 -25
  142. data/ProjectTox-Core/docs/start_guide.de.md +0 -40
  143. data/ProjectTox-Core/docs/start_guide.md +0 -38
  144. data/ProjectTox-Core/other/CMakeLists.txt +0 -9
  145. data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
  146. data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
  147. data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
  148. data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
  149. data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
  150. data/ProjectTox-Core/testing/misc_tools.h +0 -29
  151. data/ProjectTox-Core/testing/nTox_win32.c +0 -387
  152. data/ProjectTox-Core/testing/nTox_win32.h +0 -40
  153. data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,49 @@
1
+ #ifdef HAVE_CONFIG_H
2
+ #include "config.h"
3
+ #endif
4
+
5
+ #include <sys/types.h>
6
+ #include <stdint.h>
7
+ #include <string.h>
8
+ #include <check.h>
9
+ #include <stdlib.h>
10
+ #include <time.h>
11
+
12
+ #include "helpers.h"
13
+
14
+ /*
15
+ #include "../<stuff to test>"
16
+ */
17
+
18
+ START_TEST(test_creativetestnamegoeshere)
19
+ {
20
+ uint8_t test = 0;
21
+ ck_assert_msg(test == 0, "test: expected result 0, got %u.", test);
22
+ }
23
+ END_TEST
24
+
25
+ Suite *creativesuitenamegoeshere_suite(void)
26
+ {
27
+ Suite *s = suite_create("creativesuitedescritptiongoeshere");
28
+
29
+ DEFTESTCASE(/* remove test_ from test function names */ creativetestnamegoeshere);
30
+
31
+ return s;
32
+ }
33
+
34
+ int main(int argc, char *argv[])
35
+ {
36
+ srand((unsigned int) time(NULL));
37
+
38
+ Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
39
+ SRunner *test_runner = srunner_create(creativesuitenamegoeshere);
40
+
41
+ int number_failed = 0;
42
+ srunner_run_all(test_runner, CK_NORMAL);
43
+ number_failed = srunner_ntests_failed(test_runner);
44
+
45
+ srunner_free(test_runner);
46
+
47
+ return number_failed;
48
+ }
49
+
@@ -0,0 +1,454 @@
1
+ #ifdef HAVE_CONFIG_H
2
+ #include "config.h"
3
+ #endif
4
+
5
+ #include <sys/types.h>
6
+ #include <stdint.h>
7
+ #include <string.h>
8
+ #include <stdio.h>
9
+ #include <check.h>
10
+ #include <stdlib.h>
11
+ #include <time.h>
12
+
13
+ #include "../toxcore/tox.h"
14
+
15
+ #include "helpers.h"
16
+
17
+ #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
18
+ #define c_sleep(x) Sleep(1*x)
19
+ #else
20
+ #include <unistd.h>
21
+ #define c_sleep(x) usleep(1000*x)
22
+ #endif
23
+
24
+ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
25
+ {
26
+ if (*((uint32_t *)userdata) != 974536)
27
+ return;
28
+
29
+ if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
30
+ tox_add_friend_norequest(m, public_key);
31
+ }
32
+ }
33
+ uint32_t messages_received;
34
+
35
+ void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
36
+ {
37
+ if (*((uint32_t *)userdata) != 974536)
38
+ return;
39
+
40
+ uint8_t cmp_msg[TOX_MAX_MESSAGE_LENGTH];
41
+ memset(cmp_msg, 'G', sizeof(cmp_msg));
42
+
43
+ if (length == TOX_MAX_MESSAGE_LENGTH && memcmp(string, cmp_msg, sizeof(cmp_msg)) == 0)
44
+ ++messages_received;
45
+ }
46
+
47
+ uint32_t name_changes;
48
+
49
+ void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
50
+ {
51
+ if (*((uint32_t *)userdata) != 974536)
52
+ return;
53
+
54
+ if (length == sizeof("Gentoo") && memcmp(string, "Gentoo", sizeof("Gentoo")) == 0)
55
+ ++name_changes;
56
+ }
57
+
58
+ uint32_t typing_changes;
59
+
60
+ void print_typingchange(Tox *m, int friendnumber, uint8_t typing, void *userdata)
61
+ {
62
+ if (*((uint32_t *)userdata) != 974536)
63
+ return;
64
+
65
+ if (!typing)
66
+ typing_changes = 1;
67
+ else
68
+ typing_changes = 2;
69
+ }
70
+
71
+ uint32_t custom_packet;
72
+
73
+ int handle_custom_packet(void *object, const uint8_t *data, uint32_t len)
74
+ {
75
+ uint8_t number = *((uint32_t *)object);
76
+
77
+ if (len != TOX_MAX_CUSTOM_PACKET_SIZE)
78
+ return -1;
79
+
80
+ uint8_t f_data[len];
81
+ memset(f_data, number, len);
82
+ if (memcmp(f_data, data, len) == 0) {
83
+ ++custom_packet;
84
+ } else {
85
+ printf("Custom packet fail. %u\n",number );
86
+ }
87
+ }
88
+
89
+ uint8_t filenum;
90
+ uint32_t file_accepted;
91
+ uint64_t file_size;
92
+ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename,
93
+ uint16_t filename_length, void *userdata)
94
+ {
95
+ if (*((uint32_t *)userdata) != 974536)
96
+ return;
97
+
98
+ if (filename_length == sizeof("Gentoo.exe") && memcmp(filename, "Gentoo.exe", sizeof("Gentoo.exe")) == 0)
99
+ ++file_accepted;
100
+
101
+ file_size = filesize;
102
+ tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_ACCEPT, NULL, 0);
103
+ }
104
+
105
+ uint32_t file_sent;
106
+ uint32_t sendf_ok;
107
+ void file_print_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
108
+ const uint8_t *data, uint16_t length, void *userdata)
109
+ {
110
+ if (*((uint32_t *)userdata) != 974536)
111
+ return;
112
+
113
+ if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED)
114
+ tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0);
115
+
116
+ if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED)
117
+ file_sent = 1;
118
+
119
+ if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT)
120
+ sendf_ok = 1;
121
+
122
+ }
123
+
124
+ uint64_t size_recv;
125
+ uint8_t num;
126
+ void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata)
127
+ {
128
+ if (*((uint32_t *)userdata) != 974536)
129
+ return;
130
+
131
+ uint8_t f_data[length];
132
+ memset(f_data, num, length);
133
+ ++num;
134
+
135
+ if (memcmp(f_data, data, length) == 0) {
136
+ size_recv += length;
137
+ } else {
138
+ printf("FILE_CORRUPTED\n");
139
+ }
140
+ }
141
+
142
+ START_TEST(test_few_clients)
143
+ {
144
+ long long unsigned int con_time, cur_time = time(NULL);
145
+ Tox *tox1 = tox_new(0);
146
+ Tox *tox2 = tox_new(0);
147
+ Tox *tox3 = tox_new(0);
148
+ ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
149
+ uint32_t to_compare = 974536;
150
+ tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
151
+ uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
152
+ tox_get_address(tox2, address);
153
+ int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7);
154
+ ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
155
+
156
+ uint8_t off = 1;
157
+
158
+ while (1) {
159
+ tox_do(tox1);
160
+ tox_do(tox2);
161
+ tox_do(tox3);
162
+
163
+ if (tox_isconnected(tox1) && tox_isconnected(tox2) && tox_isconnected(tox3) && off) {
164
+ printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
165
+ con_time = time(NULL);
166
+ off = 0;
167
+ }
168
+
169
+
170
+ if (tox_get_friend_connection_status(tox2, 0) == 1 && tox_get_friend_connection_status(tox3, 0) == 1)
171
+ break;
172
+
173
+ c_sleep(50);
174
+ }
175
+
176
+ printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
177
+ to_compare = 974536;
178
+ tox_callback_friend_message(tox3, print_message, &to_compare);
179
+ uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1];
180
+ memset(msgs, 'G', sizeof(msgs));
181
+ ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1) == 0,
182
+ "TOX_MAX_MESSAGE_LENGTH is too small\n");
183
+ ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH) != 0, "TOX_MAX_MESSAGE_LENGTH is too big\n");
184
+
185
+ while (1) {
186
+ messages_received = 0;
187
+ tox_do(tox1);
188
+ tox_do(tox2);
189
+ tox_do(tox3);
190
+
191
+ if (messages_received)
192
+ break;
193
+
194
+ c_sleep(50);
195
+ }
196
+
197
+ printf("tox clients messaging succeeded\n");
198
+
199
+ tox_callback_name_change(tox3, print_nickchange, &to_compare);
200
+ tox_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"));
201
+
202
+ while (1) {
203
+ name_changes = 0;
204
+ tox_do(tox1);
205
+ tox_do(tox2);
206
+ tox_do(tox3);
207
+
208
+ if (name_changes)
209
+ break;
210
+
211
+ c_sleep(50);
212
+ }
213
+
214
+ uint8_t temp_name[sizeof("Gentoo")];
215
+ tox_get_name(tox3, 0, temp_name);
216
+ ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
217
+
218
+ tox_callback_typing_change(tox2, &print_typingchange, &to_compare);
219
+ tox_set_user_is_typing(tox3, 0, 1);
220
+
221
+ while (1) {
222
+ typing_changes = 0;
223
+ tox_do(tox1);
224
+ tox_do(tox2);
225
+ tox_do(tox3);
226
+
227
+
228
+ if (typing_changes == 2)
229
+ break;
230
+ else
231
+ ck_assert_msg(typing_changes == 0, "Typing fail");
232
+
233
+ c_sleep(50);
234
+ }
235
+
236
+ ck_assert_msg(tox_get_is_typing(tox2, 0) == 1, "Typing fail");
237
+ tox_set_user_is_typing(tox3, 0, 0);
238
+
239
+ while (1) {
240
+ typing_changes = 0;
241
+ tox_do(tox1);
242
+ tox_do(tox2);
243
+ tox_do(tox3);
244
+
245
+ if (typing_changes == 1)
246
+ break;
247
+ else
248
+ ck_assert_msg(typing_changes == 0, "Typing fail");
249
+
250
+ c_sleep(50);
251
+ }
252
+
253
+ ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail");
254
+
255
+ uint32_t packet_number = 160;
256
+ int ret = tox_lossless_packet_registerhandler(tox3, 0, packet_number, handle_custom_packet, &packet_number);
257
+ ck_assert_msg(ret == 0, "tox_lossless_packet_registerhandler fail %i", ret);
258
+ uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
259
+ memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
260
+ ret = tox_send_lossless_packet(tox2, 0, data_c, sizeof(data_c));
261
+ ck_assert_msg(ret == -1, "tox_send_lossless_packet bigger fail %i", ret);
262
+ ret = tox_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE);
263
+ ck_assert_msg(ret == 0, "tox_send_lossless_packet fail %i", ret);
264
+
265
+ while (1) {
266
+ custom_packet = 0;
267
+ tox_do(tox1);
268
+ tox_do(tox2);
269
+ tox_do(tox3);
270
+
271
+ if (custom_packet == 1)
272
+ break;
273
+ else
274
+ ck_assert_msg(custom_packet == 0, "Lossless packet fail");
275
+
276
+ c_sleep(50);
277
+ }
278
+
279
+ packet_number = 200;
280
+ ret = tox_lossy_packet_registerhandler(tox3, 0, packet_number, handle_custom_packet, &packet_number);
281
+ ck_assert_msg(ret == 0, "tox_lossy_packet_registerhandler fail %i", ret);
282
+ memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
283
+ ret = tox_send_lossy_packet(tox2, 0, data_c, sizeof(data_c));
284
+ ck_assert_msg(ret == -1, "tox_send_lossy_packet bigger fail %i", ret);
285
+ ret = tox_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE);
286
+ ck_assert_msg(ret == 0, "tox_send_lossy_packet fail %i", ret);
287
+
288
+ while (1) {
289
+ custom_packet = 0;
290
+ tox_do(tox1);
291
+ tox_do(tox2);
292
+ tox_do(tox3);
293
+
294
+ if (custom_packet == 1)
295
+ break;
296
+ else
297
+ ck_assert_msg(custom_packet == 0, "lossy packet fail");
298
+
299
+ c_sleep(50);
300
+ }
301
+
302
+ filenum = file_accepted = file_size = file_sent = sendf_ok = size_recv = 0;
303
+ long long unsigned int f_time = time(NULL);
304
+ tox_callback_file_data(tox3, write_file, &to_compare);
305
+ tox_callback_file_control(tox2, file_print_control, &to_compare);
306
+ tox_callback_file_control(tox3, file_print_control, &to_compare);
307
+ tox_callback_file_send_request(tox3, file_request_accept, &to_compare);
308
+ uint64_t totalf_size = 100 * 1024 * 1024;
309
+ int fnum = tox_new_file_sender(tox2, 0, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"));
310
+ ck_assert_msg(fnum != -1, "tox_new_file_sender fail");
311
+ int fpiece_size = tox_file_data_size(tox2, 0);
312
+ uint8_t f_data[fpiece_size];
313
+ uint8_t num = 0;
314
+ memset(f_data, num, fpiece_size);
315
+
316
+ while (1) {
317
+ file_sent = 0;
318
+ tox_do(tox1);
319
+ tox_do(tox2);
320
+ tox_do(tox3);
321
+
322
+ if (sendf_ok)
323
+ while (tox_file_send_data(tox2, 0, fnum, f_data, fpiece_size < totalf_size ? fpiece_size : totalf_size) == 0) {
324
+ if (totalf_size <= fpiece_size) {
325
+ sendf_ok = 0;
326
+ tox_file_send_control(tox2, 0, 0, fnum, TOX_FILECONTROL_FINISHED, NULL, 0);
327
+ }
328
+
329
+ ++num;
330
+ memset(f_data, num, fpiece_size);
331
+
332
+ totalf_size -= fpiece_size;
333
+ }
334
+
335
+ if (file_sent && size_recv == file_size)
336
+ break;
337
+
338
+ uint32_t tox1_interval = tox_do_interval(tox1);
339
+ uint32_t tox2_interval = tox_do_interval(tox2);
340
+ uint32_t tox3_interval = tox_do_interval(tox3);
341
+
342
+ if (tox2_interval > tox3_interval) {
343
+ c_sleep(tox3_interval);
344
+ } else {
345
+ c_sleep(tox2_interval);
346
+ }
347
+ }
348
+
349
+ printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
350
+
351
+ printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
352
+
353
+ tox_kill(tox1);
354
+ tox_kill(tox2);
355
+ tox_kill(tox3);
356
+ }
357
+ END_TEST
358
+
359
+ #define NUM_TOXES 66
360
+ #define NUM_FRIENDS 50
361
+
362
+ START_TEST(test_many_clients)
363
+ {
364
+ long long unsigned int cur_time = time(NULL);
365
+ Tox *toxes[NUM_TOXES];
366
+ uint32_t i, j;
367
+ uint32_t to_comp = 974536;
368
+
369
+ for (i = 0; i < NUM_TOXES; ++i) {
370
+ toxes[i] = tox_new(0);
371
+ ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
372
+ tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
373
+ }
374
+
375
+ struct {
376
+ uint16_t tox1;
377
+ uint16_t tox2;
378
+ } pairs[NUM_FRIENDS];
379
+
380
+ uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
381
+
382
+ for (i = 0; i < NUM_FRIENDS; ++i) {
383
+ loop_top:
384
+ pairs[i].tox1 = rand() % NUM_TOXES;
385
+ pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
386
+
387
+ for (j = 0; j < i; ++j) {
388
+ if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2)
389
+ goto loop_top;
390
+ }
391
+
392
+ tox_get_address(toxes[pairs[i].tox1], address);
393
+ int test = tox_add_friend(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7);
394
+
395
+ if (test == TOX_FAERR_ALREADYSENT) {
396
+ goto loop_top;
397
+ }
398
+
399
+ ck_assert_msg(test >= 0, "Failed to add friend error code: %i", test);
400
+ }
401
+
402
+ while (1) {
403
+ uint16_t counter = 0;
404
+
405
+ for (i = 0; i < NUM_TOXES; ++i) {
406
+ for (j = 0; j < tox_count_friendlist(toxes[i]); ++j)
407
+ if (tox_get_friend_connection_status(toxes[i], j) == 1)
408
+ ++counter;
409
+ }
410
+
411
+ if (counter == NUM_FRIENDS * 2) {
412
+ break;
413
+ }
414
+
415
+ for (i = 0; i < NUM_TOXES; ++i) {
416
+ tox_do(toxes[i]);
417
+ }
418
+
419
+ c_sleep(50);
420
+ }
421
+
422
+ printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
423
+
424
+ for (i = 0; i < NUM_TOXES; ++i) {
425
+ tox_kill(toxes[i]);
426
+ }
427
+ }
428
+ END_TEST
429
+
430
+ Suite *tox_suite(void)
431
+ {
432
+ Suite *s = suite_create("Tox");
433
+
434
+ DEFTESTCASE_SLOW(few_clients, 50);
435
+ DEFTESTCASE_SLOW(many_clients, 150);
436
+ return s;
437
+ }
438
+
439
+ int main(int argc, char *argv[])
440
+ {
441
+ srand((unsigned int) time(NULL));
442
+
443
+ Suite *tox = tox_suite();
444
+ SRunner *test_runner = srunner_create(tox);
445
+
446
+ int number_failed = 0;
447
+ srunner_run_all(test_runner, CK_NORMAL);
448
+ number_failed = srunner_ntests_failed(test_runner);
449
+
450
+ srunner_free(test_runner);
451
+
452
+ return number_failed;
453
+ }
454
+