summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/Lossless_UDP_testclient.c260
-rw-r--r--testing/Lossless_UDP_testserver.c237
-rw-r--r--testing/Makefile.inc36
3 files changed, 0 insertions, 533 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c
deleted file mode 100644
index 535509e0..00000000
--- a/testing/Lossless_UDP_testclient.c
+++ /dev/null
@@ -1,260 +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 ../toxcore/network.c ../toxcore/Lossless_UDP.c ../toxcore/util.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 --ipv4 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#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include "../toxcore/network.h"
36#include "../toxcore/Lossless_UDP.h"
37#include "../toxcore/util.h"
38#include "misc_tools.c"
39
40#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
41
42#define c_sleep(x) Sleep(1*x)
43
44#else
45#include <unistd.h>
46#include <arpa/inet.h>
47#define c_sleep(x) usleep(1000*x)
48
49#endif
50
51#define PORT 33446
52
53void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
54{
55 uint32_t i;
56 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
57 printf("--------------------BEGIN-----------------------------\n");
58
59 for (i = 0; i < length; i++) {
60 if (data[i] < 16)
61 printf("0");
62
63 printf("%hhX", data[i]);
64 }
65
66 printf("\n--------------------END-----------------------------\n\n\n");
67}
68
69void printip(IP_Port ip_port)
70{
71 printf("\nIP: %s Port: %u", ip_ntoa(&ip_port.ip), ntohs(ip_port.port));
72}
73/*
74void printpackets(Data test)
75{
76 int i;
77 if(test.size == 0)
78 return;
79 printf("SIZE: %u\n", test.size);
80 for(i =0; i < test.size; i++)
81 {
82 printf("%hhX", test.data[i]);
83 }
84 printf("\n");
85}
86
87void printconnection(int connection_id)
88{
89 printf("--------------------BEGIN---------------------\n");
90 IP_Port ip_port = connections[connection_id].ip_port;
91 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));
92 printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
93 connections[connection_id].inbound, connections[connection_id].SYNC_rate);
94 printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
95 connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
96 int i;
97 for(i =0; i < MAX_QUEUE_NUM; i++)
98 {
99 printf(" %u ",i);
100 printpackets(connections[connection_id].sendbuffer[i]);
101 }
102 for(i =0; i < MAX_QUEUE_NUM; i++)
103 {
104 printf(" %u ",i);
105 printpackets(connections[connection_id].recvbuffer[i]);
106 }
107 Data sendbuffer[MAX_QUEUE_NUM];
108 Data recvbuffer[MAX_QUEUE_NUM];
109 printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
110 connections[connection_id].recv_packetnum,
111 connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
112 connections[connection_id].successful_sent,
113 connections[connection_id].successful_read);
114
115 printf("req packets: \n");
116 for(i = 0; i < BUFFER_PACKET_NUM; i++)
117 {
118 printf(" %u ", connections[connection_id].req_packets[i]);
119 }
120 printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
121 connections[connection_id].recv_counter, connections[connection_id].send_counter);
122
123 printf("--------------------END---------------------\n");
124
125}
126*/
127
128/*( receive packets and send them to the packethandler */
129/*run doLossless_UDP(); */
130//void Lossless_UDP()
131//{
132/* IP_Port ip_port;
133 uint8_t data[MAX_UDP_PACKET_SIZE];
134 uint32_t length;
135 while (receivepacket(&ip_port, data, &length) != -1) {
136 printf("packet with length: %u\n", length); */
137/* if(rand() % 3 != 1)//add packet loss
138 { */
139/*
140 if (LosslessUDP_handlepacket(data, length, ip_port))
141 printpacket(data, length, ip_port);
142 else
143 printf("Received handled packet with length: %u\n", length); //printconnection(0); */
144
145/* } */
146/* }*/
147
148//networking_poll();
149
150//doLossless_UDP();
151
152//}
153
154int main(int argc, char *argv[])
155{
156 /* let user override default by cmdline */
157 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
158 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
159
160 if (argvoffset < 0)
161 exit(1);
162
163 if (argc < argvoffset + 4) {
164 printf("Usage: %s [--ipv4|--ipv6] ip port filename\n", argv[0]);
165 exit(0);
166 }
167
168 uint8_t buffer[MAX_DATA_SIZE];
169 int read;
170
171 FILE *file = fopen(argv[argvoffset + 3], "rb");
172
173 if (file == NULL) {
174 printf("Failed to open file \"%s\".\n", argv[argvoffset + 3]);
175 return 1;
176 }
177
178
179 /* initialize networking */
180 /* bind to ip 0.0.0.0:PORT */
181 IP ip;
182 ip_init(&ip, ipv6enabled);
183
184 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
185 perror("Initialization");
186
187 IP_Port serverip;
188 ip_init(&serverip.ip, ipv6enabled);
189
190 if (!addr_resolve(argv[argvoffset + 1], &serverip.ip, NULL)) {
191 printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
192 return 1;
193 }
194
195 serverip.port = htons(atoi(argv[argvoffset + 2]));
196 printip(serverip);
197
198 int connection = new_connection(ludp, serverip);
199 uint64_t timer = current_time();
200
201 while (1) {
202 /* printconnection(connection); */
203 networking_poll(ludp->net);
204 do_lossless_udp(ludp);
205
206 if (is_connected(ludp, connection) == LUDP_ESTABLISHED) {
207 printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer));
208 break;
209 }
210
211 if (is_connected(ludp, connection) == LUDP_NO_CONNECTION) {
212 printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer));
213 return 1;
214 }
215
216 c_sleep(1);
217 }
218
219 timer = current_time();
220 unsigned long long bytes_sent = 0;
221
222 /*read first part of file */
223 read = fread(buffer, 1, MAX_DATA_SIZE, file);
224
225 while (1) {
226 /* printconnection(connection); */
227 networking_poll(ludp->net);
228 do_lossless_udp(ludp);
229
230 if (is_connected(ludp, connection) == LUDP_ESTABLISHED) {
231
232 while (write_packet(ludp, connection, buffer, read)) {
233 bytes_sent += read;
234 /* printf("Wrote data.\n"); */
235 read = fread(buffer, 1, MAX_DATA_SIZE, file);
236
237 }
238
239 /* printf("%u\n", sendqueue(connection)); */
240 if (sendqueue(ludp, connection) == 0) {
241 if (read == 0) {
242 unsigned long long us = (unsigned long long)(current_time() - timer);
243 printf("Sent file successfully in: %llu us = %llu seconds. Average speed: %llu KB/s\n", us, us / 1000000UL,
244 bytes_sent / (us / 1024UL));
245 //printf("Total bytes sent: %llu B, Total data sent: %llu B, overhead: %llu B\n", total_bytes_sent, bytes_sent, total_bytes_sent-bytes_sent);
246 break;
247 }
248 }
249 } else {
250 printf("%u Client Connecting Lost after: %llu us\n", is_connected(ludp, connection),
251 (unsigned long long)(current_time() - timer));
252 return 0;
253 }
254
255 }
256
257 c_sleep(25);
258
259 return 0;
260}
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
deleted file mode 100644
index dd4612f5..00000000
--- a/testing/Lossless_UDP_testserver.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/* Lossless_UDP testserver
2 * A program that waits for a lossless UDP connection and then saves all the data received 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 ../toxcore/network.c ../toxcore/Lossless_UDP.c ../toxcore/util.c Lossless_UDP_testserver.c
8 *
9 * Command line argument is the name of the file to save what we receive 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#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include "../toxcore/network.h"
36#include "../toxcore/Lossless_UDP.h"
37#include "../toxcore/util.h"
38#include "misc_tools.c"
39
40//Sleep function (x = milliseconds)
41#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
42
43#define c_sleep(x) Sleep(1*x)
44
45#else
46#include <unistd.h>
47#include <arpa/inet.h>
48#define c_sleep(x) usleep(1000*x)
49
50#endif
51
52#define PORT 33445
53
54void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
55{
56 uint32_t i;
57 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
58 printf("--------------------BEGIN-----------------------------\n");
59
60 for (i = 0; i < length; i++) {
61 if (data[i] < 16)
62 printf("0");
63
64 printf("%hhX", data[i]);
65 }
66
67 printf("\n--------------------END-----------------------------\n\n\n");
68}
69
70/*
71void printpackets(Data test)
72{
73 int i;
74 if(test.size == 0)
75 return;
76 printf("SIZE: %u\n", test.size);
77 for(i =0; i < test.size; i++)
78 {
79 printf("%hhX", test.data[i]);
80 }
81 printf("\n");
82}
83
84void printconnection(int connection_id)
85{
86 printf("--------------------BEGIN---------------------\n");
87 IP_Port ip_port = connections[connection_id].ip_port;
88 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));
89 printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
90 connections[connection_id].inbound, connections[connection_id].SYNC_rate);
91 printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
92 connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
93 int i;
94 for(i =0; i < MAX_QUEUE_NUM; i++)
95 {
96 printf(" %u ",i);
97 printpackets(connections[connection_id].sendbuffer[i]);
98 }
99 for(i =0; i < MAX_QUEUE_NUM; i++)
100 {
101 printf(" %u ",i);
102 printpackets(connections[connection_id].recvbuffer[i]);
103 }
104 Data sendbuffer[MAX_QUEUE_NUM];
105 Data recvbuffer[MAX_QUEUE_NUM];
106 printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
107 connections[connection_id].recv_packetnum,
108 connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
109 connections[connection_id].successful_sent,
110 connections[connection_id].successful_read);
111
112 printf("req packets: \n");
113 for(i = 0; i < BUFFER_PACKET_NUM; i++)
114 {
115 printf(" %u ", connections[connection_id].req_packets[i]);
116 }
117 printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
118 connections[connection_id].recv_counter, connections[connection_id].send_counter);
119
120 printf("--------------------END---------------------\n");
121
122}
123*/
124
125/* receive packets and send them to the packethandler
126 * run doLossless_UDP(); */
127//void Lossless_UDP()
128//{
129// IP_Port ip_port;
130// uint8_t data[MAX_UDP_PACKET_SIZE];
131// uint32_t length;
132// while (receivepacket(&ip_port, data, &length) != -1) {
133//if(rand() % 3 != 1)//add packet loss
134//{
135// if (LosslessUDP_handlepacket(data, length, ip_port)) {
136// printpacket(data, length, ip_port);
137// } else {
138//printconnection(0);
139// printf("Received handled packet with length: %u\n", length);
140// }
141//}
142// }
143
144// networking_poll();
145
146//doLossless_UDP();
147//}
148
149
150int main(int argc, char *argv[])
151{
152 /* let user override default by cmdline */
153 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
154 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
155
156 if (argvoffset < 0)
157 exit(1);
158
159 if (argc < argvoffset + 2) {
160 printf("Usage: %s [--ipv4|--ipv6] filename\n", argv[0]);
161 exit(0);
162 }
163
164 uint8_t buffer[MAX_DATA_SIZE];
165 int read;
166
167 FILE *file = fopen(argv[argvoffset + 1], "wb");
168
169 if (file == NULL) {
170 printf("Failed to open file \"%s\".\n", argv[argvoffset + 1]);
171 return 1;
172 }
173
174
175 //initialize networking
176 //bind to ip 0.0.0.0:PORT
177 IP ip;
178 ip_init(&ip, ipv6enabled);
179
180 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
181 perror("Initialization");
182
183 int connection;
184 uint64_t timer = current_time();
185
186 while (1) {
187 networking_poll(ludp->net);
188 do_lossless_udp(ludp);
189 connection = incoming_connection(ludp, 0);
190
191 if (connection != -1) {
192 if (is_connected(ludp, connection) == LUDP_NOT_CONFIRMED) {
193 printf("Received the connection.\n");
194
195 }
196
197 break;
198 }
199
200 c_sleep(1);
201 }
202
203 timer = current_time();
204
205 while (1) {
206 //printconnection(0);
207 networking_poll(ludp->net);
208
209 if (is_connected(ludp, connection) >= LUDP_NOT_CONFIRMED) {
210 confirm_connection(ludp, connection);
211
212 while (1) {
213 read = read_packet(ludp, connection, buffer);
214
215 if (read != 0) {
216 // printf("Received data.\n");
217 if (!fwrite(buffer, read, 1, file))
218 printf("file write error\n");
219 } else {
220 break;
221 }
222 }
223 }
224
225 do_lossless_udp(ludp);
226
227 if (is_connected(ludp, connection) == LUDP_TIMED_OUT) {
228 printf("Server Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
229 fclose(file);
230 return 1;
231 }
232
233 c_sleep(25);
234 }
235
236 return 0;
237}
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index 812a5be1..b3912033 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -22,8 +22,6 @@ endif
22if BUILD_TESTING 22if BUILD_TESTING
23 23
24noinst_PROGRAMS += DHT_test \ 24noinst_PROGRAMS += DHT_test \
25 Lossless_UDP_testclient \
26 Lossless_UDP_testserver \
27 Messenger_test \ 25 Messenger_test \
28 crypto_speed_test 26 crypto_speed_test
29 27
@@ -41,40 +39,6 @@ DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \
41 $(WINSOCK2_LIBS) 39 $(WINSOCK2_LIBS)
42 40
43 41
44Lossless_UDP_testclient_SOURCES = \
45 ../testing/Lossless_UDP_testclient.c
46
47Lossless_UDP_testclient_CFLAGS = \
48 $(LIBSODIUM_CFLAGS) \
49 $(NACL_CFLAGS)
50
51Lossless_UDP_testclient_LDADD = \
52 $(LIBSODIUM_LDFLAGS) \
53 $(NACL_LDFLAGS) \
54 libtoxcore.la \
55 $(LIBSODIUM_LIBS) \
56 $(NACL_OBJECTS) \
57 $(NACL_LIBS) \
58 $(WINSOCK2_LIBS)
59
60
61Lossless_UDP_testserver_SOURCES = \
62 ../testing/Lossless_UDP_testserver.c
63
64Lossless_UDP_testserver_CFLAGS = \
65 $(LIBSODIUM_CFLAGS) \
66 $(NACL_CFLAGS)
67
68Lossless_UDP_testserver_LDADD = \
69 $(LIBSODIUM_LDFLAGS) \
70 $(NACL_LDFLAGS) \
71 libtoxcore.la \
72 $(LIBSODIUM_LIBS) \
73 $(NACL_OBJECTS) \
74 $(NACL_LIBS) \
75 $(WINSOCK2_LIBS)
76
77
78Messenger_test_SOURCES = \ 42Messenger_test_SOURCES = \
79 ../testing/Messenger_test.c 43 ../testing/Messenger_test.c
80 44