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,25 +0,0 @@
1
- # Tox User Commands
2
- Here's a list of commands that nTox accepts,
3
- which can all be used by starting your line with
4
- a */*. Currently there can be no spaces before this.
5
-
6
- * */f* [ID]
7
- + Add a friend with ID [ID].
8
- * */d*
9
- + Call doMessenger() which does...something?
10
- * */m* \[FRIEND\_NUM\] \[MESSAGE\]
11
- + Message \[FRIEND\_NUM\] \[MESSAGE\].
12
- * */n* \[NAME\]
13
- + Change your username to \[NAME\].
14
- * */l*
15
- + Print your list of friends. (like you have any)
16
- * */s* \[STATUS\]
17
- + Set your status to \[STATUS\].
18
- * */a* \[ID\]
19
- + Accept friend request from \[ID\].
20
- * */i*
21
- + Print useful info about your client.
22
- * */h*
23
- + Print some help.
24
- * */q/*
25
- + Quit Tox. (why ;_;)
@@ -1,40 +0,0 @@
1
- # Tox nutzen
2
- 1. Tox erstellen
3
- 2. Fehler korrigieren
4
- 3. Im IRC nach Hilfe fragen
5
- 4. Auf Debug-Reise für Entwickler
6
- 5. Tox wirklich erstellen
7
- 6. ???
8
-
9
- Trotz der ganzen Arbeit, die wir bisher in Tox
10
- gesteckt haben, gibt es noch keine richtige
11
- Anleitung, wie man Tox _benutzt_.
12
- Dies ist ein anwenderfreundlicher Versuch.
13
-
14
- 1. Verbinde dich zum Netzwerk!
15
- + Du musst dich zu einem Bootstrap-Server verbinden, um einen öffentlichen Schlüssel zu erhalten.
16
- + Wo finde ich einen öffentlichen Server? Zur Zeit hier:
17
- (die Hilfe-Nachricht von nTox ohne Kommandos hilft auch)
18
- + 198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854
19
- + 192.81.133.111 33445 8CD5A9BF0A6CE358BA36F7A653F99FA6B258FF756E490F52C1F98CC420F78858
20
- + 66.175.223.88 33445 AC4112C975240CAD260BB2FCD134266521FAAF0A5D159C5FD3201196191E4F5D
21
- + 192.184.81.118 33445 5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143
22
- 2. Finde einen Freund!
23
- + Jetzt, da du im Netzwerk bist, brauchst du einen Freund. Um einen zu bekommen,
24
- musst du eine Anfrage senden oder erhalten. Was eine Anfrage ist?
25
- Es ist wie eine Freundschaftsanfrage, jedoch benutzen wir unglaublich schaurige
26
- und kryptische Nummern anstatt Namen. When nTox startet, erscheint _deine_ lange,
27
- schaurige Nummer, auch *öffentlicher Schlüssel* genannt. Diesen kannst du an
28
- andere Personen weitergeben und sie können dich als "Freund" hinzufügen. Oder du
29
- fügst andere Personen mit dem */f*-Befehl hinzu, wenn du möchtest.
30
- 3. Chatte drauf los!
31
- + Benutze nun den */m*-Befehl, um eine Nachricht an jemanden zu senden. Wow, du chattest!
32
- 4. Mach etwas kaputt!
33
- + Jep, pre-alpha-alpha-Software stürzt manchmal ab. Wir arbeiten daran.
34
- + Bitte melde alle Abstürze entweder an die GitHub-Seite oder #tox-dev im freenode-IRC.
35
- 5. Nichts ist kaputt, aber was bedeutet */f*?
36
- + nTox liest einen Text als Befehl, wenn das erste Zeichen ein Schrägstrich ist ('/').
37
- Du kannst alle Befehle in commands.md nachlesen.
38
- 6. Benutze und unterstütze Tox!
39
- + Programmiere, debugge, dokumentiere, übersetze für uns, oder sprich einfach über uns!
40
- + Je mehr Interesse wir erhalten, desto mehr Arbeit wird getan und desto besser wird Tox.
@@ -1,38 +0,0 @@
1
- # Using Tox
2
- 1. [Build Tox](../INSTALL.md)
3
- 2. Fix errors
4
- 3. Consult IRC for help
5
- 4. Go on debugging journey for devs
6
- 5. Build Tox for real
7
- 6. ???
8
-
9
- For all the work we've put into Tox so far,
10
- there isn't yet a decent guide for how you _use_
11
- Tox. Here's a user-friendly attempt at it.
12
-
13
- 1. Connect to the network!
14
- + You need to connect to a bootstrapping server, to give you a public key.
15
- + Where can I find a public server? Right here, as of now:
16
- (the help message from running `nTox` with no args will help)
17
- + `198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854`
18
- + `192.81.133.111 33445 8CD5A9BF0A6CE358BA36F7A653F99FA6B258FF756E490F52C1F98CC420F78858`
19
- + `66.175.223.88 33445 AC4112C975240CAD260BB2FCD134266521FAAF0A5D159C5FD3201196191E4F5D`
20
- + `192.184.81.118 33445 5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143`
21
- 2. Find a friend!
22
- + Now that you're on the network, you need a friend. To get one of those,
23
- you need to to send or receive a request. What's a request, you ask?
24
- It's like a friend request, but we use really scary and cryptic numbers
25
- instead of names. When `nTox` starts, it shows _your_ long, scary number,
26
- called your *public key*. Give that to people, and they can add you as
27
- a "friend". Or, you can add someone else, with the `/f` command, if you like.
28
- 3. Chat it up!
29
- + Now use the `/m` command to send a message to someone. Wow, you're chatting!
30
- 4. But something broke!
31
- + Yeah, pre-alpha-alpha software tends to do that. We're working on it.
32
- + Please report all crashes to either the GitHub page, or `#tox-dev` on freenode.
33
- 5. Nothing broke, but what does `/f` mean?
34
- + `nTox` parses text as a command if the first character is a forward-slash (`/`).
35
- You can check all commands in commands.md.
36
- 6. Use and support Tox!
37
- + Code for us, debug for us, document for us, translate for us, even just talk about us!
38
- + The more interest we get, the more work gets done, the better Tox is.
@@ -1,9 +0,0 @@
1
- cmake_minimum_required(VERSION 2.6.0)
2
-
3
- cmake_policy(SET CMP0011 NEW)
4
-
5
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake)
6
-
7
- if(NOT WIN32)
8
- add_subdirectory(bootstrap_serverdaemon)
9
- endif()
@@ -1,18 +0,0 @@
1
- cmake_minimum_required(VERSION 2.6.0)
2
-
3
- cmake_policy(SET CMP0011 NEW)
4
-
5
- #include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_cryptosendfiletest.cmake)
6
- #include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_sendfiletest.cmake)
7
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake)
8
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
9
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
10
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
11
- if(WIN32)
12
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
13
- endif()
14
-
15
- if(NOT WIN32)
16
- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
17
- add_subdirectory(toxic)
18
- endif()
@@ -1,228 +0,0 @@
1
- /* DHT cryptosendfiletest
2
- *
3
- * This program sends or recieves a friend request.
4
- *
5
- * it also sends the encrypted data from a file to another client.
6
- * Receives the file data that that client sends us.
7
- *
8
- * NOTE: this program simulates 33% packet loss.
9
- *
10
- * This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../nacl/build/$HOSTNAME/lib/amd64/* DHT_cryptosendfiletest.c
11
- *
12
- *
13
- * Command line arguments are the ip and port of a node (for bootstrapping).
14
- *
15
- * Saves all received data to: received.txt
16
- *
17
- * EX: ./test 127.0.0.1 33445 filename.txt
18
- *
19
- * Copyright (C) 2013 Tox project All Rights Reserved.
20
- *
21
- * This file is part of Tox.
22
- *
23
- * Tox is free software: you can redistribute it and/or modify
24
- * it under the terms of the GNU General Public License as published by
25
- * the Free Software Foundation, either version 3 of the License, or
26
- * (at your option) any later version.
27
- *
28
- * Tox is distributed in the hope that it will be useful,
29
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
- * GNU General Public License for more details.
32
- *
33
- * You should have received a copy of the GNU General Public License
34
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
35
- *
36
- */
37
-
38
- #include "../core/network.h"
39
- #include "../core/DHT.h"
40
- #include "../core/net_crypto.h"
41
- #include "misc_tools.h"
42
-
43
- #include <string.h>
44
-
45
- /* Sleep function (x = milliseconds) */
46
- #ifdef WIN32
47
-
48
- #define c_sleep(x) Sleep(1*x)
49
-
50
- #else
51
- #include <unistd.h>
52
- #include <arpa/inet.h>
53
- #define c_sleep(x) usleep(1000*x)
54
-
55
- #endif
56
-
57
- #define PORT 33445
58
-
59
- void printip(IP_Port ip_port)
60
- {
61
- printf("\nIP: %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));
62
- }
63
-
64
- uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
65
-
66
- int main(int argc, char *argv[])
67
- {
68
- if (argc < 4) {
69
- printf("usage %s ip port filename(of file to send)\n", argv[0]);
70
- exit(0);
71
- }
72
- new_keys();
73
- printf("OUR ID: ");
74
- uint32_t i;
75
- for(i = 0; i < 32; i++) {
76
- if(self_public_key[i] < 16)
77
- printf("0");
78
- printf("%hhX",self_public_key[i]);
79
- }
80
- printf("\n");
81
-
82
- memcpy(self_client_id, self_public_key, 32);
83
-
84
- char temp_id[128];
85
- printf("Enter the client_id of the friend to connect to (32 bytes HEX format):\n");
86
- scanf("%s", temp_id);
87
-
88
- uint8_t friend_id[32];
89
- memcpy(friend_id, hex_string_to_bin(temp_id), 32);
90
-
91
- /* memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); */
92
-
93
-
94
- DHT_addfriend(friend_id);
95
- IP_Port friend_ip;
96
- int connection = -1;
97
- int inconnection = -1;
98
-
99
- uint8_t acceptedfriend_public_key[crypto_box_PUBLICKEYBYTES];
100
- int friendrequest = -1;
101
- uint8_t request_data[512];
102
-
103
- /* initialize networking
104
- * bind to ip 0.0.0.0:PORT */
105
- IP ip;
106
- ip.i = 0;
107
- init_networking(ip, PORT);
108
- initNetCrypto();
109
-
110
- perror("Initialization");
111
- IP_Port bootstrap_ip_port;
112
- bootstrap_ip_port.port = htons(atoi(argv[2]));
113
- bootstrap_ip_port.ip.i = inet_addr(argv[1]);
114
- DHT_bootstrap(bootstrap_ip_port);
115
-
116
- IP_Port ip_port;
117
- uint8_t data[MAX_UDP_PACKET_SIZE];
118
- uint32_t length;
119
-
120
- uint8_t buffer1[128];
121
- int read1 = 0;
122
- uint8_t buffer2[128];
123
- int read2 = 0;
124
- FILE *file1 = fopen(argv[3], "rb");
125
- if ( file1==NULL ){printf("Error opening file.\n");return 1;}
126
- FILE *file2 = fopen("received.txt", "wb");
127
- if ( file2==NULL ){return 1;}
128
- read1 = fread(buffer1, 1, 128, file1);
129
-
130
- while(1) {
131
- while(receivepacket(&ip_port, data, &length) != -1) {
132
- if(rand() % 3 != 1) { /* simulate packet loss */
133
- if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) {
134
- /* if packet is not recognized */
135
- printf("Received unhandled packet with length: %u\n", length);
136
- } else {
137
- printf("Received handled packet with length: %u\n", length);
138
- }
139
- }
140
- }
141
- friend_ip = DHT_getfriendip(friend_id);
142
- if(friend_ip.ip.i != 0) {
143
- if(connection == -1 && friendrequest == -1) {
144
- printf("Sending friend request to peer:");
145
- printip(friend_ip);
146
- friendrequest = send_friendrequest(friend_id, friend_ip,(uint8_t *) "Hello World", 12);
147
- /* connection = crypto_connect((uint8_t *)friend_id, friend_ip); */
148
- /* connection = new_connection(friend_ip); */
149
- }
150
- if(check_friendrequest(friendrequest) == 1) {
151
- printf("Started connecting to friend:");
152
- connection = crypto_connect(friend_id, friend_ip);
153
- }
154
- }
155
- if(inconnection == -1) {
156
- uint8_t secret_nonce[crypto_box_NONCEBYTES];
157
- uint8_t public_key[crypto_box_PUBLICKEYBYTES];
158
- uint8_t session_key[crypto_box_PUBLICKEYBYTES];
159
- inconnection = crypto_inbound(public_key, secret_nonce, session_key);
160
- inconnection = accept_crypto_inbound(inconnection, acceptedfriend_public_key, secret_nonce, session_key);
161
- /* inconnection = incoming_connection(); */
162
- if(inconnection != -1) {
163
- printf("Someone connected to us:\n");
164
- /* printip(connection_ip(inconnection)); */
165
- }
166
- }
167
- if(handle_friendrequest(acceptedfriend_public_key, request_data) > 1) {
168
- printf("RECIEVED FRIEND REQUEST: %s\n", request_data);
169
- }
170
-
171
- /* if someone connected to us write what he sends to a file
172
- * also send him our file. */
173
- if(inconnection != -1) {
174
- if(write_cryptpacket(inconnection, buffer1, read1)) {
175
- printf("Wrote data1.\n");
176
- read1 = fread(buffer1, 1, 128, file1);
177
- }
178
- read2 = read_cryptpacket(inconnection, buffer2);
179
- if(read2 != 0) {
180
- printf("Received data1.\n");
181
- if(!fwrite(buffer2, read2, 1, file2)) {
182
- printf("file write error1\n");
183
- }
184
- if(read2 < 128) {
185
- printf("Closed file1 %u\n", read2);
186
- fclose(file2);
187
- }
188
- }
189
- /* if buffer is empty and the connection timed out. */
190
- else if(is_cryptoconnected(inconnection) == 4) {
191
- crypto_kill(inconnection);
192
- }
193
- }
194
- /* if we are connected to a friend send him data from the file.
195
- * also put what he sends us in a file. */
196
- if(is_cryptoconnected(connection) >= 3) {
197
- if(write_cryptpacket(0, buffer1, read1)) {
198
- printf("Wrote data2.\n");
199
- read1 = fread(buffer1, 1, 128, file1);
200
- }
201
- read2 = read_cryptpacket(0, buffer2);
202
- if(read2 != 0) {
203
- printf("Received data2.\n");
204
- if(!fwrite(buffer2, read2, 1, file2)) {
205
- printf("file write error2\n");
206
- }
207
- if(read2 < 128) {
208
- printf("Closed file2 %u\n", read2);
209
- fclose(file2);
210
- }
211
- }
212
- /* if buffer is empty and the connection timed out. */
213
- else if(is_cryptoconnected(connection) == 4) {
214
- crypto_kill(connection);
215
- }
216
- }
217
- doDHT();
218
- doLossless_UDP();
219
- doNetCrypto();
220
- /*print_clientlist();
221
- *print_friendlist();
222
- *c_sleep(300); */
223
- c_sleep(1);
224
- }
225
-
226
- shutdown_networking();
227
- return 0;
228
- }
@@ -1,176 +0,0 @@
1
- /* DHT sendfiletest
2
- *
3
- * Sends the data from a file to another client.
4
- * Receives the file data that that client sends us.
5
- *
6
- * NOTE: this program simulates 33% packet loss.
7
- *
8
- * Compile with: gcc -O2 -Wall -o test ../core/DHT.c ../core/network.c ../core/Lossless_UDP.c DHT_sendfiletest.c
9
- *
10
- * Command line arguments are the ip and port of a node (for bootstrapping), the
11
- * client_id (32 bytes) of the friend you want to send the data in filename to and
12
- * the client_id this node will take.
13
- *
14
- * Saves all received data to: received.txt
15
- *
16
- * EX: ./test 127.0.0.1 33445 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef filename.txt ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeg
17
- *
18
- * Copyright (C) 2013 Tox project All Rights Reserved.
19
- *
20
- * This file is part of Tox.
21
- *
22
- * Tox is free software: you can redistribute it and/or modify
23
- * it under the terms of the GNU General Public License as published by
24
- * the Free Software Foundation, either version 3 of the License, or
25
- * (at your option) any later version.
26
- *
27
- * Tox is distributed in the hope that it will be useful,
28
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
- * GNU General Public License for more details.
31
- *
32
- * You should have received a copy of the GNU General Public License
33
- * along with Tox. If not, see <http://www.gnu.org/licenses/>.
34
- *
35
- */
36
-
37
- #include "../core/network.h"
38
- #include "../core/DHT.h"
39
- #include "../core/Lossless_UDP.h"
40
-
41
- #include <string.h>
42
-
43
- //Sleep function (x = milliseconds)
44
- #ifdef WIN32
45
-
46
- #define c_sleep(x) Sleep(1*x)
47
-
48
- #else
49
- #include <unistd.h>
50
- #include <arpa/inet.h>
51
- #define c_sleep(x) usleep(1000*x)
52
-
53
- #endif
54
-
55
- #define PORT 33445
56
-
57
- void printip(IP_Port ip_port)
58
- {
59
- printf("\nIP: %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));
60
- }
61
-
62
- int main(int argc, char *argv[])
63
- {
64
- //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
65
-
66
- if (argc < 6) {
67
- printf("usage %s ip port client_id(of friend to find ip_port of) filename(of file to send) client_id(ours)\n", argv[0]);
68
- exit(0);
69
- }
70
- DHT_addfriend((uint8_t *)argv[3]);
71
- IP_Port friend_ip;
72
- int connection = -1;
73
- int inconnection = -1;
74
-
75
- //initialize networking
76
- //bind to ip 0.0.0.0:PORT
77
- IP ip;
78
- ip.i = 0;
79
- init_networking(ip, PORT);
80
-
81
- memcpy(self_client_id, argv[5], 32);
82
-
83
-
84
- perror("Initialization");
85
- IP_Port bootstrap_ip_port;
86
- bootstrap_ip_port.port = htons(atoi(argv[2]));
87
- bootstrap_ip_port.ip.i = inet_addr(argv[1]);
88
- DHT_bootstrap(bootstrap_ip_port);
89
-
90
- IP_Port ip_port;
91
- uint8_t data[MAX_UDP_PACKET_SIZE];
92
- uint32_t length;
93
-
94
- uint8_t buffer1[128];
95
- int read1 = 0;
96
- uint8_t buffer2[128];
97
- int read2 = 0;
98
- FILE *file1 = fopen(argv[4], "rb");
99
- if (file1 == NULL) {
100
- printf("Error opening file.\n");
101
- return 1;
102
- }
103
- FILE *file2 = fopen("received.txt", "wb");
104
- if (file2 == NULL)
105
- return 1;
106
-
107
- read1 = fread(buffer1, 1, 128, file1);
108
-
109
- while (1) {
110
- while (receivepacket(&ip_port, data, &length) != -1) {
111
- if (rand() % 3 != 1) { /* simulate packet loss */
112
- if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
113
- printf("Received unhandled packet with length: %u\n", length); /* if packet is not recognized */
114
- else
115
- printf("Received handled packet with length: %u\n", length);
116
- }
117
- }
118
- friend_ip = DHT_getfriendip((uint8_t *)argv[3]);
119
- if (friend_ip.ip.i != 0) {
120
- if (connection == -1) {
121
- printf("Started connecting to friend:");
122
- printip(friend_ip);
123
- connection = new_connection(friend_ip);
124
- }
125
- }
126
- if (inconnection == -1) {
127
- inconnection = incoming_connection();
128
- if (inconnection != -1) {
129
- printf("Someone connected to us:");
130
- printip(connection_ip(inconnection));
131
- }
132
- }
133
- /* if someone connected to us write what he sends to a file */
134
- /* also send him our file. */
135
- if (inconnection != -1) {
136
- if (write_packet(inconnection, buffer1, read1)) {
137
- printf("Wrote data.\n");
138
- read1 = fread(buffer1, 1, 128, file1);
139
- }
140
- read2 = read_packet(inconnection, buffer2);
141
- if (read2 != 0) {
142
- printf("Received data.\n");
143
- if (!fwrite(buffer2, read2, 1, file2))
144
- printf("file write error\n");
145
- if (read2 < 128) {
146
- fclose(file2);
147
- }
148
- }
149
- }
150
- /* if we are connected to a friend send him data from the file.
151
- * also put what he sends us in a file. */
152
- if (is_connected(connection) == 3) {
153
- if (write_packet(0, buffer1, read1)) {
154
- printf("Wrote data.\n");
155
- read1 = fread(buffer1, 1, 128, file1);
156
- }
157
- read2 = read_packet(0, buffer2);
158
- if (read2 != 0) {
159
- printf("Received data.\n");
160
- if(!fwrite(buffer2, read2, 1, file2))
161
- printf("file write error\n");
162
- if(read2 < 128)
163
- fclose(file2);
164
- }
165
- }
166
- doDHT();
167
- doLossless_UDP();
168
- /* print_clientlist();
169
- * print_friendlist();
170
- * c_sleep(300); */
171
- c_sleep(1);
172
- }
173
-
174
- shutdown_networking();
175
- return 0;
176
- }