diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 0c21867d..8f23528c 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -8,6 +8,24 @@ | |||
8 | * | 8 | * |
9 | * Command line arguments are the ip and port to connect and send the file to. | 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 | 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 | * | ||
11 | */ | 29 | */ |
12 | 30 | ||
13 | #include "../core/network.h" | 31 | #include "../core/network.h" |
@@ -24,7 +42,6 @@ | |||
24 | 42 | ||
25 | #endif | 43 | #endif |
26 | 44 | ||
27 | |||
28 | #define PORT 33446 | 45 | #define PORT 33446 |
29 | 46 | ||
30 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 47 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) |
@@ -32,8 +49,7 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
32 | uint32_t i; | 49 | uint32_t i; |
33 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
34 | printf("--------------------BEGIN-----------------------------\n"); | 51 | printf("--------------------BEGIN-----------------------------\n"); |
35 | for(i = 0; i < length; i++) | 52 | for(i = 0; i < length; i++) { |
36 | { | ||
37 | if(data[i] < 16) | 53 | if(data[i] < 16) |
38 | printf("0"); | 54 | printf("0"); |
39 | printf("%hhX",data[i]); | 55 | printf("%hhX",data[i]); |
@@ -99,39 +115,34 @@ void printconnection(int connection_id) | |||
99 | 115 | ||
100 | } | 116 | } |
101 | */ | 117 | */ |
102 | //recieve packets and send them to the packethandler | 118 | |
103 | //run doLossless_UDP(); | 119 | /*( recieve packets and send them to the packethandler */ |
120 | /*run doLossless_UDP(); */ | ||
104 | void Lossless_UDP() | 121 | void Lossless_UDP() |
105 | { | 122 | { |
106 | IP_Port ip_port; | 123 | IP_Port ip_port; |
107 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 124 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
108 | uint32_t length; | 125 | uint32_t length; |
109 | while(receivepacket(&ip_port, data, &length) != -1) | 126 | while(receivepacket(&ip_port, data, &length) != -1) { |
110 | { | ||
111 | printf("packet with length: %u\n", length); | 127 | printf("packet with length: %u\n", length); |
112 | //if(rand() % 3 != 1)//add packet loss | 128 | /* if(rand() % 3 != 1)//add packet loss |
113 | // { | 129 | { */ |
114 | if(LosslessUDP_handlepacket(data, length, ip_port)) | 130 | if(LosslessUDP_handlepacket(data, length, ip_port)) { |
115 | { | ||
116 | printpacket(data, length, ip_port); | 131 | printpacket(data, length, ip_port); |
117 | } | 132 | } else { |
118 | else | ||
119 | { | ||
120 | //printconnection(0); | 133 | //printconnection(0); |
121 | printf("Received handled packet with length: %u\n", length); | 134 | printf("Received handled packet with length: %u\n", length); |
122 | } | 135 | } |
123 | // } | 136 | /* } */ |
124 | } | 137 | } |
125 | 138 | ||
126 | doLossless_UDP(); | 139 | doLossless_UDP(); |
127 | 140 | ||
128 | } | 141 | } |
129 | 142 | ||
130 | |||
131 | int main(int argc, char *argv[]) | 143 | int main(int argc, char *argv[]) |
132 | { | 144 | { |
133 | if (argc < 4) | 145 | if (argc < 4) { |
134 | { | ||
135 | printf("usage: %s ip port filename\n", argv[0]); | 146 | printf("usage: %s ip port filename\n", argv[0]); |
136 | exit(0); | 147 | exit(0); |
137 | } | 148 | } |
@@ -143,8 +154,8 @@ int main(int argc, char *argv[]) | |||
143 | if ( file==NULL ){return 1;} | 154 | if ( file==NULL ){return 1;} |
144 | 155 | ||
145 | 156 | ||
146 | //initialize networking | 157 | /* initialize networking */ |
147 | //bind to ip 0.0.0.0:PORT | 158 | /* bind to ip 0.0.0.0:PORT */ |
148 | IP ip; | 159 | IP ip; |
149 | ip.i = 0; | 160 | ip.i = 0; |
150 | init_networking(ip, PORT); | 161 | init_networking(ip, PORT); |
@@ -155,17 +166,14 @@ int main(int argc, char *argv[]) | |||
155 | printip(serverip); | 166 | printip(serverip); |
156 | int connection = new_connection(serverip); | 167 | int connection = new_connection(serverip); |
157 | uint64_t timer = current_time(); | 168 | uint64_t timer = current_time(); |
158 | while(1) | 169 | while(1) { |
159 | { | 170 | /* printconnection(connection); */ |
160 | // printconnection(connection); | ||
161 | Lossless_UDP(); | 171 | Lossless_UDP(); |
162 | if(is_connected(connection) == 3) | 172 | if(is_connected(connection) == 3) { |
163 | { | ||
164 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); | 173 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); |
165 | break; | 174 | break; |
166 | } | 175 | } |
167 | if(is_connected(connection) == 0) | 176 | if(is_connected(connection) == 0) { |
168 | { | ||
169 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); | 177 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
170 | return 1; | 178 | return 1; |
171 | } | 179 | } |
@@ -174,38 +182,32 @@ int main(int argc, char *argv[]) | |||
174 | timer = current_time(); | 182 | timer = current_time(); |
175 | 183 | ||
176 | 184 | ||
177 | //read first part of file | 185 | /*read first part of file */ |
178 | read = fread(buffer, 1, 512, file); | 186 | read = fread(buffer, 1, 512, file); |
179 | 187 | ||
180 | while(1) | 188 | while(1) { |
181 | { | 189 | /* printconnection(connection); */ |
182 | //printconnection(connection); | ||
183 | Lossless_UDP(); | 190 | Lossless_UDP(); |
184 | if(is_connected(connection) == 3) | 191 | if(is_connected(connection) == 3) { |
185 | { | ||
186 | 192 | ||
187 | if(write_packet(connection, buffer, read)) | 193 | if(write_packet(connection, buffer, read)) { |
188 | { | 194 | /* printf("Wrote data.\n"); */ |
189 | //printf("Wrote data.\n"); | ||
190 | read = fread(buffer, 1, 512, file); | 195 | read = fread(buffer, 1, 512, file); |
191 | 196 | ||
192 | } | 197 | } |
193 | //printf("%u\n", sendqueue(connection)); | 198 | /* printf("%u\n", sendqueue(connection)); */ |
194 | if(sendqueue(connection) == 0) | 199 | if(sendqueue(connection) == 0) { |
195 | { | 200 | if(read == 0) { |
196 | if(read == 0) | ||
197 | { | ||
198 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); | 201 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); |
199 | break; | 202 | break; |
200 | } | 203 | } |
201 | } | 204 | } |
202 | } | 205 | } |
203 | else | 206 | else { |
204 | { | ||
205 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); | 207 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); |
206 | return 0; | 208 | return 0; |
207 | } | 209 | } |
208 | //c_sleep(1); | 210 | /* c_sleep(1); */ |
209 | } | 211 | } |
210 | 212 | ||
211 | return 0; | 213 | return 0; |