summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/CMakeLists.txt2
-rw-r--r--testing/DHT_cryptosendfiletest.c258
-rw-r--r--testing/DHT_sendfiletest.c196
-rw-r--r--testing/cmake/DHT_cryptosendfiletest.cmake10
-rw-r--r--testing/cmake/DHT_sendfiletest.cmake9
5 files changed, 0 insertions, 475 deletions
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index bb66d373..9bab6efb 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.6.0)
2 2
3cmake_policy(SET CMP0011 NEW) 3cmake_policy(SET CMP0011 NEW)
4 4
5#include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_cryptosendfiletest.cmake)
6#include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_sendfiletest.cmake)
7include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake) 5include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake)
8include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake) 6include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
9include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) 7include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
diff --git a/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c
deleted file mode 100644
index 42635b35..00000000
--- a/testing/DHT_cryptosendfiletest.c
+++ /dev/null
@@ -1,258 +0,0 @@
1/* DHT cryptosendfiletest
2 *
3 * This program sends or receives 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
59void 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],
62 ntohs(ip_port.port));
63}
64
65uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
66
67int main(int argc, char *argv[])
68{
69 if (argc < 4) {
70 printf("usage %s ip port filename(of file to send)\n", argv[0]);
71 exit(0);
72 }
73
74 new_keys();
75 printf("OUR ID: ");
76 uint32_t i;
77
78 for (i = 0; i < 32; i++) {
79 if (self_public_key[i] < 16)
80 printf("0");
81
82 printf("%hhX", self_public_key[i]);
83 }
84
85 printf("\n");
86
87 memcpy(self_client_id, self_public_key, 32);
88
89 char temp_id[128];
90 printf("Enter the client_id of the friend to connect to (32 bytes HEX format):\n");
91 scanf("%s", temp_id);
92
93 uint8_t friend_id[32];
94 memcpy(friend_id, hex_string_to_bin(temp_id), 32);
95
96 /* memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); */
97
98
99 DHT_addfriend(friend_id);
100 IP_Port friend_ip;
101 int connection = -1;
102 int inconnection = -1;
103
104 uint8_t acceptedfriend_public_key[crypto_box_PUBLICKEYBYTES];
105 int friendrequest = -1;
106 uint8_t request_data[512];
107
108 /* initialize networking
109 * bind to ip 0.0.0.0:PORT */
110 IP ip;
111 ip.i = 0;
112 init_networking(ip, PORT);
113 initNetCrypto();
114
115 perror("Initialization");
116 IP_Port bootstrap_ip_port;
117 bootstrap_ip_port.port = htons(atoi(argv[2]));
118 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
119 DHT_bootstrap(bootstrap_ip_port);
120
121 IP_Port ip_port;
122 uint8_t data[MAX_UDP_PACKET_SIZE];
123 uint32_t length;
124
125 uint8_t buffer1[128];
126 int read1 = 0;
127 uint8_t buffer2[128];
128 int read2 = 0;
129 FILE *file1 = fopen(argv[3], "rb");
130
131 if ( file1 == NULL ) {
132 printf("Error opening file.\n");
133 return 1;
134 }
135
136 FILE *file2 = fopen("received.txt", "wb");
137
138 if ( file2 == NULL ) {
139 return 1;
140 }
141
142 read1 = fread(buffer1, 1, 128, file1);
143
144 while (1) {
145 while (receivepacket(&ip_port, data, &length) != -1) {
146 if (rand() % 3 != 1) { /* simulate packet loss */
147 if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) {
148 /* if packet is not recognized */
149 printf("Received unhandled packet with length: %u\n", length);
150 } else {
151 printf("Received handled packet with length: %u\n", length);
152 }
153 }
154 }
155
156 friend_ip = DHT_getfriendip(friend_id);
157
158 if (friend_ip.ip.i != 0) {
159 if (connection == -1 && friendrequest == -1) {
160 printf("Sending friend request to peer:");
161 printip(friend_ip);
162 friendrequest = send_friendrequest(friend_id, friend_ip, (uint8_t *) "Hello World", 12);
163 /* connection = crypto_connect((uint8_t *)friend_id, friend_ip); */
164 /* connection = new_connection(friend_ip); */
165 }
166
167 if (check_friendrequest(friendrequest) == 1) {
168 printf("Started connecting to friend:");
169 connection = crypto_connect(friend_id, friend_ip);
170 }
171 }
172
173 if (inconnection == -1) {
174 uint8_t secret_nonce[crypto_box_NONCEBYTES];
175 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
176 uint8_t session_key[crypto_box_PUBLICKEYBYTES];
177 inconnection = crypto_inbound(public_key, secret_nonce, session_key);
178 inconnection = accept_crypto_inbound(inconnection, acceptedfriend_public_key, secret_nonce, session_key);
179
180 /* inconnection = incoming_connection(); */
181 if (inconnection != -1) {
182 printf("Someone connected to us:\n");
183 /* printip(connection_ip(inconnection)); */
184 }
185 }
186
187 if (handle_friendrequest(acceptedfriend_public_key, request_data) > 1) {
188 printf("RECEIVED FRIEND REQUEST: %s\n", request_data);
189 }
190
191 /* if someone connected to us write what he sends to a file
192 * also send him our file. */
193 if (inconnection != -1) {
194 if (write_cryptpacket(inconnection, buffer1, read1)) {
195 printf("Wrote data1.\n");
196 read1 = fread(buffer1, 1, 128, file1);
197 }
198
199 read2 = read_cryptpacket(inconnection, buffer2);
200
201 if (read2 != 0) {
202 printf("Received data1.\n");
203
204 if (!fwrite(buffer2, read2, 1, file2)) {
205 printf("file write error1\n");
206 }
207
208 if (read2 < 128) {
209 printf("Closed file1 %u\n", read2);
210 fclose(file2);
211 }
212 }
213 /* if buffer is empty and the connection timed out. */
214 else if (is_cryptoconnected(inconnection) == 4) {
215 crypto_kill(inconnection);
216 }
217 }
218
219 /* if we are connected to a friend send him data from the file.
220 * also put what he sends us in a file. */
221 if (is_cryptoconnected(connection) >= 3) {
222 if (write_cryptpacket(0, buffer1, read1)) {
223 printf("Wrote data2.\n");
224 read1 = fread(buffer1, 1, 128, file1);
225 }
226
227 read2 = read_cryptpacket(0, buffer2);
228
229 if (read2 != 0) {
230 printf("Received data2.\n");
231
232 if (!fwrite(buffer2, read2, 1, file2)) {
233 printf("file write error2\n");
234 }
235
236 if (read2 < 128) {
237 printf("Closed file2 %u\n", read2);
238 fclose(file2);
239 }
240 }
241 /* if buffer is empty and the connection timed out. */
242 else if (is_cryptoconnected(connection) == 4) {
243 crypto_kill(connection);
244 }
245 }
246
247 doDHT();
248 doLossless_UDP();
249 doNetCrypto();
250 /*print_clientlist();
251 *print_friendlist();
252 *c_sleep(300); */
253 c_sleep(1);
254 }
255
256 shutdown_networking();
257 return 0;
258}
diff --git a/testing/DHT_sendfiletest.c b/testing/DHT_sendfiletest.c
deleted file mode 100644
index f839be57..00000000
--- a/testing/DHT_sendfiletest.c
+++ /dev/null
@@ -1,196 +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
57void 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],
60 ntohs(ip_port.port));
61}
62
63int main(int argc, char *argv[])
64{
65 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
66
67 if (argc < 6) {
68 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]);
69 exit(0);
70 }
71
72 DHT_addfriend((uint8_t *)argv[3]);
73 IP_Port friend_ip;
74 int connection = -1;
75 int inconnection = -1;
76
77 //initialize networking
78 //bind to ip 0.0.0.0:PORT
79 IP ip;
80 ip.i = 0;
81 init_networking(ip, PORT);
82
83 memcpy(self_client_id, argv[5], 32);
84
85
86 perror("Initialization");
87 IP_Port bootstrap_ip_port;
88 bootstrap_ip_port.port = htons(atoi(argv[2]));
89 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
90 DHT_bootstrap(bootstrap_ip_port);
91
92 IP_Port ip_port;
93 uint8_t data[MAX_UDP_PACKET_SIZE];
94 uint32_t length;
95
96 uint8_t buffer1[128];
97 int read1 = 0;
98 uint8_t buffer2[128];
99 int read2 = 0;
100 FILE *file1 = fopen(argv[4], "rb");
101
102 if (file1 == NULL) {
103 printf("Error opening file.\n");
104 return 1;
105 }
106
107 FILE *file2 = fopen("received.txt", "wb");
108
109 if (file2 == NULL)
110 return 1;
111
112 read1 = fread(buffer1, 1, 128, file1);
113
114 while (1) {
115 while (receivepacket(&ip_port, data, &length) != -1) {
116 if (rand() % 3 != 1) { /* simulate packet loss */
117 if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
118 printf("Received unhandled packet with length: %u\n", length); /* if packet is not recognized */
119 else
120 printf("Received handled packet with length: %u\n", length);
121 }
122 }
123
124 friend_ip = DHT_getfriendip((uint8_t *)argv[3]);
125
126 if (friend_ip.ip.i != 0) {
127 if (connection == -1) {
128 printf("Started connecting to friend:");
129 printip(friend_ip);
130 connection = new_connection(friend_ip);
131 }
132 }
133
134 if (inconnection == -1) {
135 inconnection = incoming_connection();
136
137 if (inconnection != -1) {
138 printf("Someone connected to us:");
139 printip(connection_ip(inconnection));
140 }
141 }
142
143 /* if someone connected to us write what he sends to a file */
144 /* also send him our file. */
145 if (inconnection != -1) {
146 if (write_packet(inconnection, buffer1, read1)) {
147 printf("Wrote data.\n");
148 read1 = fread(buffer1, 1, 128, file1);
149 }
150
151 read2 = read_packet(inconnection, buffer2);
152
153 if (read2 != 0) {
154 printf("Received data.\n");
155
156 if (!fwrite(buffer2, read2, 1, file2))
157 printf("file write error\n");
158
159 if (read2 < 128) {
160 fclose(file2);
161 }
162 }
163 }
164
165 /* if we are connected to a friend send him data from the file.
166 * also put what he sends us in a file. */
167 if (is_connected(connection) == 3) {
168 if (write_packet(0, buffer1, read1)) {
169 printf("Wrote data.\n");
170 read1 = fread(buffer1, 1, 128, file1);
171 }
172
173 read2 = read_packet(0, buffer2);
174
175 if (read2 != 0) {
176 printf("Received data.\n");
177
178 if (!fwrite(buffer2, read2, 1, file2))
179 printf("file write error\n");
180
181 if (read2 < 128)
182 fclose(file2);
183 }
184 }
185
186 doDHT();
187 doLossless_UDP();
188 /* print_clientlist();
189 * print_friendlist();
190 * c_sleep(300); */
191 c_sleep(1);
192 }
193
194 shutdown_networking();
195 return 0;
196} \ No newline at end of file
diff --git a/testing/cmake/DHT_cryptosendfiletest.cmake b/testing/cmake/DHT_cryptosendfiletest.cmake
deleted file mode 100644
index 5470d02a..00000000
--- a/testing/cmake/DHT_cryptosendfiletest.cmake
+++ /dev/null
@@ -1,10 +0,0 @@
1cmake_minimum_required(VERSION 2.6.0)
2project(DHT_cryptosendfiletest C)
3
4set(exe_name DHT_cryptosendfiletest)
5
6add_executable(${exe_name}
7 DHT_cryptosendfiletest.c
8 misc_tools.c)
9
10linkCoreLibraries(${exe_name})
diff --git a/testing/cmake/DHT_sendfiletest.cmake b/testing/cmake/DHT_sendfiletest.cmake
deleted file mode 100644
index 298db46c..00000000
--- a/testing/cmake/DHT_sendfiletest.cmake
+++ /dev/null
@@ -1,9 +0,0 @@
1cmake_minimum_required(VERSION 2.6.0)
2project(DHT_sendfiletest C)
3
4set(exe_name DHT_sendfiletest)
5
6add_executable(${exe_name}
7 DHT_sendfiletest.c)
8
9linkCoreLibraries(${exe_name})