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
@@ -1,214 +0,0 @@
1
- /* Lossless_UDP testclient
2
- * A program that connects and sends a file using our lossless UDP algorithm.
3
- * NOTE: this program simulates a 33% packet loss.
4
- *
5
- * Best used in combination with Lossless_UDP_testserver
6
- *
7
- * Compile with: gcc -O2 -Wall -lsodium -o testclient ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testclient.c
8
- *
9
- * Command line arguments are the ip and port to connect and send the file to.
10
- * EX: ./testclient 127.0.0.1 33445 filename.txt
11
- *
12
- * Copyright (C) 2013 Tox project All Rights Reserved.
13
- *
14
- * This file is part of Tox.
15
- *
16
- * Tox is free software: you can redistribute it and/or modify
17
- * it under the terms of the GNU General Public License as published by
18
- * the Free Software Foundation, either version 3 of the License, or
19
- * (at your option) any later version.
20
- *
21
- * Tox is distributed in the hope that it will be useful,
22
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- * GNU General Public License for more details.
25
- *
26
- * You should have received a copy of the GNU General Public License
27
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
28
- *
29
- */
30
-
31
- #include "../core/network.h"
32
- #include "../core/Lossless_UDP.h"
33
-
34
- #ifdef WIN32
35
-
36
- #define c_sleep(x) Sleep(1*x)
37
-
38
- #else
39
- #include <unistd.h>
40
- #include <arpa/inet.h>
41
- #define c_sleep(x) usleep(1000*x)
42
-
43
- #endif
44
-
45
- #define PORT 33446
46
-
47
- void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
48
- {
49
- uint32_t i;
50
- printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
51
- printf("--------------------BEGIN-----------------------------\n");
52
- for (i = 0; i < length; i++) {
53
- if (data[i] < 16)
54
- printf("0");
55
- printf("%hhX",data[i]);
56
- }
57
- printf("\n--------------------END-----------------------------\n\n\n");
58
- }
59
-
60
- void printip(IP_Port ip_port)
61
- {
62
- printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.c[0], ip_port.ip.c[1], ip_port.ip.c[2], ip_port.ip.c[3], ntohs(ip_port.port));
63
- }
64
- /*
65
- void printpackets(Data test)
66
- {
67
- int i;
68
- if(test.size == 0)
69
- return;
70
- printf("SIZE: %u\n", test.size);
71
- for(i =0; i < test.size; i++)
72
- {
73
- printf("%hhX", test.data[i]);
74
- }
75
- printf("\n");
76
- }
77
-
78
- void printconnection(int connection_id)
79
- {
80
- printf("--------------------BEGIN---------------------\n");
81
- IP_Port ip_port = connections[connection_id].ip_port;
82
- printf("IP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
83
- printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
84
- connections[connection_id].inbound, connections[connection_id].SYNC_rate);
85
- printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
86
- connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
87
- int i;
88
- for(i =0; i < MAX_QUEUE_NUM; i++)
89
- {
90
- printf(" %u ",i);
91
- printpackets(connections[connection_id].sendbuffer[i]);
92
- }
93
- for(i =0; i < MAX_QUEUE_NUM; i++)
94
- {
95
- printf(" %u ",i);
96
- printpackets(connections[connection_id].recvbuffer[i]);
97
- }
98
- Data sendbuffer[MAX_QUEUE_NUM];
99
- Data recvbuffer[MAX_QUEUE_NUM];
100
- printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
101
- connections[connection_id].recv_packetnum,
102
- connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
103
- connections[connection_id].successful_sent,
104
- connections[connection_id].successful_read);
105
-
106
- printf("req packets: \n");
107
- for(i = 0; i < BUFFER_PACKET_NUM; i++)
108
- {
109
- printf(" %u ", connections[connection_id].req_packets[i]);
110
- }
111
- printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
112
- connections[connection_id].recv_counter, connections[connection_id].send_counter);
113
-
114
- printf("--------------------END---------------------\n");
115
-
116
- }
117
- */
118
-
119
- /*( recieve packets and send them to the packethandler */
120
- /*run doLossless_UDP(); */
121
- void Lossless_UDP()
122
- {
123
- IP_Port ip_port;
124
- uint8_t data[MAX_UDP_PACKET_SIZE];
125
- uint32_t length;
126
- while (receivepacket(&ip_port, data, &length) != -1) {
127
- printf("packet with length: %u\n", length);
128
- /* if(rand() % 3 != 1)//add packet loss
129
- { */
130
- if (LosslessUDP_handlepacket(data, length, ip_port))
131
- printpacket(data, length, ip_port);
132
- else
133
- printf("Received handled packet with length: %u\n", length); //printconnection(0);
134
-
135
- /* } */
136
- }
137
-
138
- doLossless_UDP();
139
-
140
- }
141
-
142
- int main(int argc, char *argv[])
143
- {
144
- if (argc < 4) {
145
- printf("usage: %s ip port filename\n", argv[0]);
146
- exit(0);
147
- }
148
-
149
- uint8_t buffer[512];
150
- int read;
151
-
152
- FILE *file = fopen(argv[3], "rb");
153
- if (file == NULL)
154
- return 1;
155
-
156
-
157
- /* initialize networking */
158
- /* bind to ip 0.0.0.0:PORT */
159
- IP ip;
160
- ip.i = 0;
161
- init_networking(ip, PORT);
162
- perror("Initialization");
163
- IP_Port serverip;
164
- serverip.ip.i = inet_addr(argv[1]);
165
- serverip.port = htons(atoi(argv[2]));
166
- printip(serverip);
167
- int connection = new_connection(serverip);
168
- uint64_t timer = current_time();
169
- while (1) {
170
- /* printconnection(connection); */
171
- Lossless_UDP();
172
- if (is_connected(connection) == 3) {
173
- printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer));
174
- break;
175
- }
176
- if (is_connected(connection) == 0) {
177
- printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer));
178
- return 1;
179
- }
180
- c_sleep(1);
181
- }
182
- timer = current_time();
183
-
184
-
185
- /*read first part of file */
186
- read = fread(buffer, 1, 512, file);
187
-
188
- while (1) {
189
- /* printconnection(connection); */
190
- Lossless_UDP();
191
- if (is_connected(connection) == 3) {
192
-
193
- if (write_packet(connection, buffer, read)) {
194
- /* printf("Wrote data.\n"); */
195
- read = fread(buffer, 1, 512, file);
196
-
197
- }
198
- /* printf("%u\n", sendqueue(connection)); */
199
- if (sendqueue(connection) == 0) {
200
- if (read == 0) {
201
- printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer));
202
- break;
203
- }
204
- }
205
- }
206
- else {
207
- printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
208
- return 0;
209
- }
210
- /* c_sleep(1); */
211
- }
212
-
213
- return 0;
214
- }
@@ -1,201 +0,0 @@
1
- /* Lossless_UDP testserver
2
- * A program that waits for a lossless UDP connection and then saves all the data recieved to a file.
3
- * NOTE: this program simulates a 33% packet loss.
4
- *
5
- * Best used in combination with Lossless_UDP_testclient
6
- *
7
- * Compile with: gcc -O2 -Wall -lsodium -o testserver ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testserver.c
8
- *
9
- * Command line argument is the name of the file to save what we recieve to.
10
- * EX: ./testserver filename1.txt
11
- *
12
- * Copyright (C) 2013 Tox project All Rights Reserved.
13
- *
14
- * This file is part of Tox.
15
- *
16
- * Tox is free software: you can redistribute it and/or modify
17
- * it under the terms of the GNU General Public License as published by
18
- * the Free Software Foundation, either version 3 of the License, or
19
- * (at your option) any later version.
20
- *
21
- * Tox is distributed in the hope that it will be useful,
22
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- * GNU General Public License for more details.
25
- *
26
- * You should have received a copy of the GNU General Public License
27
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
28
- *
29
- */
30
-
31
- #include "../core/network.h"
32
- #include "../core/Lossless_UDP.h"
33
-
34
- //Sleep function (x = milliseconds)
35
- #ifdef WIN32
36
-
37
- #define c_sleep(x) Sleep(1*x)
38
-
39
- #else
40
- #include <unistd.h>
41
- #include <arpa/inet.h>
42
- #define c_sleep(x) usleep(1000*x)
43
-
44
- #endif
45
-
46
- #define PORT 33445
47
-
48
- void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
49
- {
50
- uint32_t i;
51
- printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
52
- printf("--------------------BEGIN-----------------------------\n");
53
- for (i = 0; i < length; i++) {
54
- if(data[i] < 16)
55
- printf("0");
56
- printf("%hhX",data[i]);
57
- }
58
- printf("\n--------------------END-----------------------------\n\n\n");
59
- }
60
-
61
- /*
62
- void printpackets(Data test)
63
- {
64
- int i;
65
- if(test.size == 0)
66
- return;
67
- printf("SIZE: %u\n", test.size);
68
- for(i =0; i < test.size; i++)
69
- {
70
- printf("%hhX", test.data[i]);
71
- }
72
- printf("\n");
73
- }
74
-
75
- void printconnection(int connection_id)
76
- {
77
- printf("--------------------BEGIN---------------------\n");
78
- IP_Port ip_port = connections[connection_id].ip_port;
79
- printf("IP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
80
- printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
81
- connections[connection_id].inbound, connections[connection_id].SYNC_rate);
82
- printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
83
- connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
84
- int i;
85
- for(i =0; i < MAX_QUEUE_NUM; i++)
86
- {
87
- printf(" %u ",i);
88
- printpackets(connections[connection_id].sendbuffer[i]);
89
- }
90
- for(i =0; i < MAX_QUEUE_NUM; i++)
91
- {
92
- printf(" %u ",i);
93
- printpackets(connections[connection_id].recvbuffer[i]);
94
- }
95
- Data sendbuffer[MAX_QUEUE_NUM];
96
- Data recvbuffer[MAX_QUEUE_NUM];
97
- printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
98
- connections[connection_id].recv_packetnum,
99
- connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
100
- connections[connection_id].successful_sent,
101
- connections[connection_id].successful_read);
102
-
103
- printf("req packets: \n");
104
- for(i = 0; i < BUFFER_PACKET_NUM; i++)
105
- {
106
- printf(" %u ", connections[connection_id].req_packets[i]);
107
- }
108
- printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
109
- connections[connection_id].recv_counter, connections[connection_id].send_counter);
110
-
111
- printf("--------------------END---------------------\n");
112
-
113
- }
114
- */
115
-
116
- /* recieve packets and send them to the packethandler
117
- * run doLossless_UDP(); */
118
- void Lossless_UDP()
119
- {
120
- IP_Port ip_port;
121
- uint8_t data[MAX_UDP_PACKET_SIZE];
122
- uint32_t length;
123
- while (receivepacket(&ip_port, data, &length) != -1) {
124
- //if(rand() % 3 != 1)//add packet loss
125
- //{
126
- if (LosslessUDP_handlepacket(data, length, ip_port)) {
127
- printpacket(data, length, ip_port);
128
- } else {
129
- //printconnection(0);
130
- printf("Received handled packet with length: %u\n", length);
131
- }
132
- //}
133
- }
134
-
135
- doLossless_UDP();
136
- }
137
-
138
-
139
- int main(int argc, char *argv[])
140
- {
141
- if (argc < 2) {
142
- printf("usage: %s filename\n", argv[0]);
143
- exit(0);
144
- }
145
-
146
- uint8_t buffer[512];
147
- int read;
148
-
149
- FILE *file = fopen(argv[1], "wb");
150
- if (file == NULL)
151
- return 1;
152
-
153
-
154
- //initialize networking
155
- //bind to ip 0.0.0.0:PORT
156
- IP ip;
157
- ip.i = 0;
158
- init_networking(ip, PORT);
159
- perror("Initialization");
160
-
161
- int connection;
162
- uint64_t timer = current_time();
163
-
164
-
165
- while (1) {
166
- Lossless_UDP();
167
- connection = incoming_connection();
168
- if(connection != -1) {
169
- if(is_connected(connection) == 2) {
170
- printf("Recieved the connection.\n");
171
-
172
- }
173
- break;
174
- }
175
- c_sleep(1);
176
- }
177
-
178
- timer = current_time();
179
-
180
- while (1) {
181
- //printconnection(0);
182
- Lossless_UDP();
183
- if (is_connected(connection) >= 2) {
184
- kill_connection_in(connection, 3000000);
185
- read = read_packet(connection, buffer);
186
- if (read != 0) {
187
- // printf("Recieved data.\n");
188
- if (!fwrite(buffer, read, 1, file))
189
- printf("file write error\n");
190
- }
191
- }
192
- if(is_connected(connection) == 4) {
193
- printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
194
- fclose(file);
195
- return 1;
196
- }
197
- c_sleep(1);
198
- }
199
-
200
- return 0;
201
- }
@@ -1,29 +0,0 @@
1
- /* misc_tools.h
2
- *
3
- * Miscellaneous functions and data structures for doing random things.
4
- *
5
- * Copyright (C) 2013 Tox project All Rights Reserved.
6
- *
7
- * This file is part of Tox.
8
- *
9
- * Tox is free software: you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation, either version 3 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * Tox is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21
- *
22
- */
23
-
24
- #ifndef MISC_TOOLS_H
25
- #define MISC_TOOLS_H
26
-
27
- unsigned char * hex_string_to_bin(char hex_string[]);
28
-
29
- #endif // MISC_TOOLS_H
@@ -1,387 +0,0 @@
1
- /* nTox_win32.c
2
- *
3
- * Textual frontend for Tox - Windows version
4
- *
5
- * Copyright (C) 2013 Tox project All Rights Reserved.
6
- *
7
- * This file is part of Tox.
8
- *
9
- * Tox is free software: you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation, either version 3 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * Tox is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21
- *
22
- */
23
-
24
- #include "nTox_win32.h"
25
- #include "misc_tools.h"
26
-
27
- #include <process.h>
28
-
29
- uint8_t pending_requests[256][CLIENT_ID_SIZE];
30
- uint8_t num_requests = 0;
31
-
32
- char line[STRING_LENGTH];
33
- char users_id[200];
34
-
35
- void do_header()
36
- {
37
- system("cls");
38
- printf(users_id);
39
- printf("\n---------------------------------");
40
- printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)");
41
- printf("\n---------------------------------");
42
- }
43
-
44
- void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
45
- {
46
- printf("\n\n[i] received friend request with message\n");
47
- printf((char *)data);
48
- char numchar[100];
49
- sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests);
50
- printf(numchar);
51
- memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
52
- ++num_requests;
53
- }
54
-
55
- void print_message(int friendnumber, uint8_t * string, uint16_t length)
56
- {
57
- char name[MAX_NAME_LENGTH];
58
- getname(friendnumber, (uint8_t*)name);
59
- char msg[100+length+strlen(name)+1];
60
- time_t rawtime;
61
- struct tm * timeinfo;
62
- time (&rawtime);
63
- timeinfo = localtime (&rawtime);
64
- char* temp = asctime(timeinfo);
65
- size_t len = strlen(temp);
66
- temp[len-1]='\0';
67
- sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp
68
- printf(msg);
69
- }
70
-
71
- void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
72
- {
73
- char name[MAX_NAME_LENGTH];
74
- getname(friendnumber, (uint8_t*)name);
75
- char msg[100+length];
76
- sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
77
- printf(msg);
78
- }
79
-
80
- void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
81
- {
82
- char name[MAX_NAME_LENGTH];
83
- getname(friendnumber, (uint8_t*)name);
84
- char msg[100+length+strlen(name)+1];
85
- sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
86
- printf(msg);
87
- }
88
-
89
- void load_key()
90
- {
91
- FILE *data_file = NULL;
92
- data_file = fopen("data","r");
93
- if (data_file) {
94
- fseek(data_file, 0, SEEK_END);
95
- int size = ftell(data_file);
96
- fseek(data_file, 0, SEEK_SET);
97
- uint8_t data[size];
98
- if (fread(data, sizeof(uint8_t), size, data_file) != size) {
99
- printf("\n[i] Could not read the data file. Exiting.");
100
- exit(1);
101
- }
102
-
103
- Messenger_load(data, size);
104
- } else {
105
- int size = Messenger_size();
106
- uint8_t data[size];
107
- Messenger_save(data);
108
- data_file = fopen("data", "w");
109
-
110
- if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
111
- printf("\n[i] Could not write data to file. Exiting.");
112
- exit(1);
113
- }
114
- }
115
- fclose(data_file);
116
- }
117
-
118
- void line_eval(char* line)
119
- {
120
- if(line[0] == '/') {
121
- char inpt_command = line[1];
122
- /* Add friend */
123
- if(inpt_command == 'f') {
124
- int i;
125
- char temp_id[128];
126
- for (i = 0; i < 128; i++)
127
- temp_id[i] = line[i+3];
128
- int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
129
- if (num >= 0) {
130
- char numstring[100];
131
- sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
132
- printf(numstring);
133
- }
134
- else if (num == -1)
135
- printf("\nWrong key size\n\n");
136
- else if (num == -2)
137
- printf("\nYou can't add yourself\n\n");
138
- else if (num == -3)
139
- printf("\nYou already have this person added\n\n");
140
- else if (num == -4)
141
- printf("\nUndefined error when adding friend");
142
- }
143
-
144
- else if (inpt_command == 'r') {
145
- do_header();
146
- printf("\n\n");
147
- }
148
-
149
- else if (inpt_command == 'l') {
150
- int activefriends = 0;
151
- int i;
152
-
153
- for (i = 0; i <= getnumfriends(); i++)
154
- {
155
- if (m_friendstatus(i) == 4)
156
- activefriends++;
157
- }
158
-
159
- printf("\n[i] Friend List | Total: %d\n\n", activefriends);
160
-
161
- for (i = 0; i <= getnumfriends(); i++) {
162
- char name[MAX_NAME_LENGTH];
163
- getname(i, (uint8_t*)name);
164
- if (m_friendstatus(i) == 4)
165
- printf("[%d] %s\n\n", i, (uint8_t*)name);
166
- }
167
- }
168
-
169
- else if (inpt_command == 'd') {
170
- size_t len = strlen(line);
171
- char numstring[len-3];
172
- int i;
173
- for (i = 0; i < len; i++) {
174
- if (line[i+3] != ' ') {
175
- numstring[i] = line[i+3];
176
- }
177
- }
178
- int num = atoi(numstring);
179
- m_delfriend(num);
180
- printf("\n\n");
181
- }
182
- /* Send message to friend */
183
- else if (inpt_command == 'm') {
184
- size_t len = strlen(line);
185
- char numstring[len-3];
186
- char message[len-3];
187
- int i;
188
- for (i = 0; i < len; i++) {
189
- if (line[i+3] != ' ') {
190
- numstring[i] = line[i+3];
191
- } else {
192
- int j;
193
- for (j = (i+1); j < len; j++)
194
- message[j-i-1] = line[j+3];
195
- break;
196
- }
197
- }
198
- int num = atoi(numstring);
199
- if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
200
- printf("\n[i] could not send message (they may be offline): %s\n", message);
201
- } else {
202
- //simply for aesthetics
203
- printf("\n");
204
- }
205
- }
206
-
207
- else if (inpt_command == 'n') {
208
- uint8_t name[MAX_NAME_LENGTH];
209
- int i = 0;
210
- size_t len = strlen(line);
211
- for (i = 3; i < len; i++) {
212
- if (line[i] == 0 || line[i] == '\n') break;
213
- name[i-3] = line[i];
214
- }
215
- name[i-3] = 0;
216
- setname(name, i);
217
- char numstring[100];
218
- sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
219
- printf(numstring);
220
-
221
- FILE *name_file = NULL;
222
- name_file = fopen("namefile.txt", "w");
223
- fprintf(name_file, "%s", (char*)name);
224
- fclose(name_file);
225
- }
226
-
227
- else if (inpt_command == 's') {
228
- uint8_t status[MAX_USERSTATUS_LENGTH];
229
- int i = 0;
230
- size_t len = strlen(line);
231
- for (i = 3; i < len; i++) {
232
- if (line[i] == 0 || line[i] == '\n') break;
233
- status[i-3] = line[i];
234
- }
235
- status[i-3] = 0;
236
- m_set_userstatus(status, strlen((char*)status));
237
- char numstring[100];
238
- sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
239
- printf(numstring);
240
-
241
- FILE* status_file = NULL;
242
- status_file = fopen("statusfile.txt", "w");
243
- fprintf(status_file, "%s", (char*)status);
244
- fclose(status_file);
245
- }
246
-
247
- else if (inpt_command == 'a') {
248
- uint8_t numf = atoi(line + 3);
249
- char numchar[100];
250
- sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
251
- printf(numchar);
252
- int num = m_addfriend_norequest(pending_requests[numf]);
253
- sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
254
- printf(numchar);
255
- }
256
- /* EXIT */
257
- else if (inpt_command == 'q') {
258
- uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline";
259
- m_set_userstatus(status, strlen((char*)status));
260
- exit(EXIT_SUCCESS);
261
- }
262
- } else {
263
- //nothing atm
264
- }
265
- }
266
-
267
- void get_input()
268
- {
269
- while(1) {
270
- fgets(line, STRING_LENGTH, stdin);
271
- line_eval(line);
272
- strcpy(line, "");
273
- }
274
- }
275
-
276
- int main(int argc, char *argv[])
277
- {
278
- if (argc < 4) {
279
- printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
280
- exit(0);
281
- }
282
- if (initMessenger() == -1) {
283
- printf("initMessenger failed");
284
- exit(0);
285
- }
286
- if (argc > 4) {
287
- if(strncmp(argv[4], "nokey", 6) < 0) {
288
- }
289
- } else {
290
- load_key();
291
- }
292
-
293
- int nameloaded = 0;
294
- int statusloaded = 0;
295
-
296
- FILE* name_file = NULL;
297
- name_file = fopen("namefile.txt", "r");
298
- if(name_file) {
299
- uint8_t name[MAX_NAME_LENGTH];
300
- while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
301
- sscanf(line, "%s", (char*)name);
302
- }
303
- setname(name, strlen((char*)name)+1);
304
- nameloaded = 1;
305
- printf("%s\n", name);
306
- }
307
- fclose(name_file);
308
-
309
- FILE* status_file = NULL;
310
- status_file = fopen("statusfile.txt", "r");
311
- if(status_file) {
312
- uint8_t status[MAX_USERSTATUS_LENGTH];
313
- while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
314
- sscanf(line, "%s", (char*)status);
315
- }
316
- m_set_userstatus(status, strlen((char*)status)+1);
317
- statusloaded = 1;
318
- printf("%s\n", status);
319
- }
320
- fclose(status_file);
321
-
322
- m_callback_friendrequest(print_request);
323
- m_callback_friendmessage(print_message);
324
- m_callback_namechange(print_nickchange);
325
- m_callback_userstatus(print_statuschange);
326
- char idstring1[PUB_KEY_BYTES][5];
327
- char idstring2[PUB_KEY_BYTES][5];
328
- int i;
329
- for(i = 0; i < PUB_KEY_BYTES; i++)
330
- {
331
- if(self_public_key[i] < (PUB_KEY_BYTES/2))
332
- strcpy(idstring1[i],"0");
333
- else
334
- strcpy(idstring1[i], "");
335
- sprintf(idstring2[i], "%hhX",self_public_key[i]);
336
- }
337
- strcpy(users_id,"[i] your ID: ");
338
- int j;
339
- for (j = 0; j < PUB_KEY_BYTES; j++) {
340
- strcat(users_id,idstring1[j]);
341
- strcat(users_id,idstring2[j]);
342
- }
343
-
344
- do_header();
345
-
346
- IP_Port bootstrap_ip_port;
347
- bootstrap_ip_port.port = htons(atoi(argv[2]));
348
- int resolved_address = resolve_addr(argv[1]);
349
- if (resolved_address != 0)
350
- bootstrap_ip_port.ip.i = resolved_address;
351
- else
352
- exit(1);
353
-
354
- DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
355
-
356
- int c;
357
- int on = 0;
358
-
359
- _beginthread(get_input, 0, NULL);
360
-
361
- if (nameloaded == 1) {
362
- printf("\nNickname automatically loaded");
363
- printf("\n---------------------------------");
364
- }
365
-
366
- if (statusloaded == 1) {
367
- printf("\nStatus automatically loaded");
368
- printf("\n---------------------------------");
369
- }
370
-
371
- while(1) {
372
- if (on == 1 && DHT_isconnected() == -1) {
373
- printf("\n---------------------------------");
374
- printf("\n[i] Disconnected from the DHT");
375
- printf("\n---------------------------------\n\n");
376
- on = 0;
377
- }
378
- if (on == 0 && DHT_isconnected()) {
379
- printf("\n[i] Connected to DHT");
380
- printf("\n---------------------------------\n\n");
381
- on = 1;
382
- }
383
- doMessenger();
384
- Sleep(1);
385
- }
386
- return 0;
387
- }