summaryrefslogtreecommitdiff
path: root/testing/DHT_sendfiletest.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/DHT_sendfiletest.c')
-rw-r--r--testing/DHT_sendfiletest.c60
1 files changed, 23 insertions, 37 deletions
diff --git a/testing/DHT_sendfiletest.c b/testing/DHT_sendfiletest.c
index c9865843..5b5d6c9f 100644
--- a/testing/DHT_sendfiletest.c
+++ b/testing/DHT_sendfiletest.c
@@ -33,6 +33,7 @@
33 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 33 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
34 * 34 *
35 */ 35 */
36
36#include "../core/network.h" 37#include "../core/network.h"
37#include "../core/DHT.h" 38#include "../core/DHT.h"
38#include "../core/Lossless_UDP.h" 39#include "../core/Lossless_UDP.h"
@@ -100,68 +101,53 @@ int main(int argc, char *argv[])
100 if ( file2==NULL ){return 1;} 101 if ( file2==NULL ){return 1;}
101 read1 = fread(buffer1, 1, 128, file1); 102 read1 = fread(buffer1, 1, 128, file1);
102 103
103 while(1) 104 while(1) {
104 {
105 105
106 while(receivepacket(&ip_port, data, &length) != -1) 106 while(receivepacket(&ip_port, data, &length) != -1) {
107 { 107 if(rand() % 3 != 1) { /* simulate packet loss */
108 if(rand() % 3 != 1)//simulate packet loss 108 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) {
109 { 109 /* if packet is not recognized */
110 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
111 {
112 //if packet is not recognized
113 printf("Received unhandled packet with length: %u\n", length); 110 printf("Received unhandled packet with length: %u\n", length);
114 } 111 } else {
115 else
116 {
117 printf("Received handled packet with length: %u\n", length); 112 printf("Received handled packet with length: %u\n", length);
118 } 113 }
119 } 114 }
120 } 115 }
121 friend_ip = DHT_getfriendip((uint8_t *)argv[3]); 116 friend_ip = DHT_getfriendip((uint8_t *)argv[3]);
122 if(friend_ip.ip.i != 0) 117 if(friend_ip.ip.i != 0) {
123 { 118 if(connection == -1) {
124 if(connection == -1)
125 {
126 printf("Started connecting to friend:"); 119 printf("Started connecting to friend:");
127 printip(friend_ip); 120 printip(friend_ip);
128 connection = new_connection(friend_ip); 121 connection = new_connection(friend_ip);
129 } 122 }
130 } 123 }
131 if(inconnection == -1) 124 if(inconnection == -1) {
132 {
133 inconnection = incoming_connection(); 125 inconnection = incoming_connection();
134 if(inconnection != -1) 126 if(inconnection != -1) {
135 {
136 printf("Someone connected to us:"); 127 printf("Someone connected to us:");
137 printip(connection_ip(inconnection)); 128 printip(connection_ip(inconnection));
138 } 129 }
139 } 130 }
140 //if someone connected to us write what he sends to a file 131 /* if someone connected to us write what he sends to a file */
141 //also send him our file. 132 /* also send him our file. */
142 if(inconnection != -1) 133 if(inconnection != -1) {
143 { 134 if(write_packet(inconnection, buffer1, read1)) {
144 if(write_packet(inconnection, buffer1, read1))
145 {
146 printf("Wrote data.\n"); 135 printf("Wrote data.\n");
147 read1 = fread(buffer1, 1, 128, file1); 136 read1 = fread(buffer1, 1, 128, file1);
148 } 137 }
149 read2 = read_packet(inconnection, buffer2); 138 read2 = read_packet(inconnection, buffer2);
150 if(read2 != 0) 139 if(read2 != 0) {
151 {
152 printf("Received data.\n"); 140 printf("Received data.\n");
153 if(!fwrite(buffer2, read2, 1, file2)) 141 if(!fwrite(buffer2, read2, 1, file2)) {
154 {
155 printf("file write error\n"); 142 printf("file write error\n");
156 } 143 }
157 if(read2 < 128) 144 if(read2 < 128) {
158 {
159 fclose(file2); 145 fclose(file2);
160 } 146 }
161 } 147 }
162 } 148 }
163 //if we are connected to a friend send him data from the file. 149 /* if we are connected to a friend send him data from the file.
164 //also put what he sends us in a file. 150 * also put what he sends us in a file. */
165 if(is_connected(connection) == 3) 151 if(is_connected(connection) == 3)
166 { 152 {
167 if(write_packet(0, buffer1, read1)) 153 if(write_packet(0, buffer1, read1))
@@ -185,9 +171,9 @@ int main(int argc, char *argv[])
185 } 171 }
186 doDHT(); 172 doDHT();
187 doLossless_UDP(); 173 doLossless_UDP();
188 //print_clientlist(); 174 /* print_clientlist();
189 //print_friendlist(); 175 * print_friendlist();
190 //c_sleep(300); 176 * c_sleep(300); */
191 c_sleep(1); 177 c_sleep(1);
192 } 178 }
193 179