summaryrefslogtreecommitdiff
path: root/testing/Lossless_UDP_testserver.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/Lossless_UDP_testserver.c')
-rw-r--r--testing/Lossless_UDP_testserver.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index 8043be25..a8097048 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -8,6 +8,24 @@
8 * 8 *
9 * Command line argument is the name of the file to save what we recieve to. 9 * Command line argument is the name of the file to save what we recieve to.
10 * EX: ./testserver filename1.txt 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 *
11 */ 29 */
12 30
13#include "../core/network.h" 31#include "../core/network.h"
@@ -25,7 +43,6 @@
25 43
26#endif 44#endif
27 45
28
29#define PORT 33445 46#define PORT 33445
30 47
31void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) 48void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
@@ -33,14 +50,14 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
33 uint32_t i; 50 uint32_t i;
34 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); 51 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
35 printf("--------------------BEGIN-----------------------------\n"); 52 printf("--------------------BEGIN-----------------------------\n");
36 for(i = 0; i < length; i++) 53 for(i = 0; i < length; i++) {
37 {
38 if(data[i] < 16) 54 if(data[i] < 16)
39 printf("0"); 55 printf("0");
40 printf("%hhX",data[i]); 56 printf("%hhX",data[i]);
41 } 57 }
42 printf("\n--------------------END-----------------------------\n\n\n"); 58 printf("\n--------------------END-----------------------------\n\n\n");
43} 59}
60
44/* 61/*
45void printpackets(Data test) 62void printpackets(Data test)
46{ 63{
@@ -95,23 +112,20 @@ void printconnection(int connection_id)
95 112
96} 113}
97*/ 114*/
98//recieve packets and send them to the packethandler 115
99//run doLossless_UDP(); 116/* recieve packets and send them to the packethandler
117 * run doLossless_UDP(); */
100void Lossless_UDP() 118void Lossless_UDP()
101{ 119{
102 IP_Port ip_port; 120 IP_Port ip_port;
103 uint8_t data[MAX_UDP_PACKET_SIZE]; 121 uint8_t data[MAX_UDP_PACKET_SIZE];
104 uint32_t length; 122 uint32_t length;
105 while(receivepacket(&ip_port, data, &length) != -1) 123 while(receivepacket(&ip_port, data, &length) != -1) {
106 {
107 //if(rand() % 3 != 1)//add packet loss 124 //if(rand() % 3 != 1)//add packet loss
108 //{ 125 //{
109 if(LosslessUDP_handlepacket(data, length, ip_port)) 126 if(LosslessUDP_handlepacket(data, length, ip_port)) {
110 {
111 printpacket(data, length, ip_port); 127 printpacket(data, length, ip_port);
112 } 128 } else {
113 else
114 {
115 //printconnection(0); 129 //printconnection(0);
116 printf("Received handled packet with length: %u\n", length); 130 printf("Received handled packet with length: %u\n", length);
117 } 131 }
@@ -119,14 +133,12 @@ void Lossless_UDP()
119 } 133 }
120 134
121 doLossless_UDP(); 135 doLossless_UDP();
122
123} 136}
124 137
125 138
126int main(int argc, char *argv[]) 139int main(int argc, char *argv[])
127{ 140{
128 if (argc < 2) 141 if (argc < 2) {
129 {
130 printf("usage: %s filename\n", argv[0]); 142 printf("usage: %s filename\n", argv[0]);
131 exit(0); 143 exit(0);
132 } 144 }
@@ -149,14 +161,11 @@ int main(int argc, char *argv[])
149 uint64_t timer = current_time(); 161 uint64_t timer = current_time();
150 162
151 163
152 while(1) 164 while(1) {
153 {
154 Lossless_UDP(); 165 Lossless_UDP();
155 connection = incoming_connection(); 166 connection = incoming_connection();
156 if(connection != -1) 167 if(connection != -1) {
157 { 168 if(is_connected(connection) == 2) {
158 if(is_connected(connection) == 2)
159 {
160 printf("Recieved the connection.\n"); 169 printf("Recieved the connection.\n");
161 170
162 } 171 }
@@ -167,25 +176,20 @@ int main(int argc, char *argv[])
167 176
168 timer = current_time(); 177 timer = current_time();
169 178
170 while(1) 179 while(1) {
171 {
172 //printconnection(0); 180 //printconnection(0);
173 Lossless_UDP(); 181 Lossless_UDP();
174 if(is_connected(connection) >= 2) 182 if(is_connected(connection) >= 2) {
175 {
176 kill_connection_in(connection, 3000000); 183 kill_connection_in(connection, 3000000);
177 read = read_packet(connection, buffer); 184 read = read_packet(connection, buffer);
178 if(read != 0) 185 if(read != 0) {
179 {
180 // printf("Recieved data.\n"); 186 // printf("Recieved data.\n");
181 if(!fwrite(buffer, read, 1, file)) 187 if(!fwrite(buffer, read, 1, file)) {
182 {
183 printf("file write error\n"); 188 printf("file write error\n");
184 } 189 }
185 } 190 }
186 } 191 }
187 if(is_connected(connection) == 4) 192 if(is_connected(connection) == 4) {
188 {
189 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); 193 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
190 fclose(file); 194 fclose(file);
191 return 1; 195 return 1;