summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-26 05:38:35 -0700
committerirungentoo <irungentoo@gmail.com>2013-07-26 05:38:35 -0700
commit8c70b7c11d6d5acc08e234554f187b18876fd5d3 (patch)
tree8ef350879553acd22c20887016f4249815ab1d0f /testing
parent63375b68b63d33c8437f313b2041b559c32c945b (diff)
parent1577a1eb61b6e2839aec962025d78e8703be3661 (diff)
Merge pull request #103 from SilentSand/master
Licensing
Diffstat (limited to 'testing')
-rw-r--r--testing/DHT_cryptosendfiletest.c138
-rw-r--r--testing/DHT_sendfiletest.c78
-rw-r--r--testing/DHT_test.c72
-rw-r--r--testing/Lossless_UDP_testclient.c90
-rw-r--r--testing/Lossless_UDP_testserver.c66
-rw-r--r--testing/Messenger_test.c38
-rw-r--r--testing/nTox.c36
-rw-r--r--testing/nTox.h23
8 files changed, 302 insertions, 239 deletions
diff --git a/testing/DHT_cryptosendfiletest.c b/testing/DHT_cryptosendfiletest.c
index 39a928d2..b06ddea5 100644
--- a/testing/DHT_cryptosendfiletest.c
+++ b/testing/DHT_cryptosendfiletest.c
@@ -15,14 +15,33 @@
15 * Saves all received data to: received.txt 15 * Saves all received data to: received.txt
16 * 16 *
17 * EX: ./test 127.0.0.1 33445 filename.txt 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 *
18 */ 36 */
37
19#include "../core/network.h" 38#include "../core/network.h"
20#include "../core/DHT.h" 39#include "../core/DHT.h"
21#include "../core/net_crypto.h" 40#include "../core/net_crypto.h"
22 41
23#include <string.h> 42#include <string.h>
24 43
25//Sleep function (x = milliseconds) 44/* Sleep function (x = milliseconds) */
26#ifdef WIN32 45#ifdef WIN32
27 46
28#define c_sleep(x) Sleep(1*x) 47#define c_sleep(x) Sleep(1*x)
@@ -41,16 +60,14 @@ void printip(IP_Port ip_port)
41 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],ntohs(ip_port.port)); 60 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],ntohs(ip_port.port));
42} 61}
43 62
44 63/* horrible function from one of my first C programs.
45//horrible function from one of my first C programs. 64 *only here because I was too lazy to write a proper one. */
46//only here because I was too lazy to write a proper one.
47unsigned char * hex_string_to_bin(char hex_string[]) 65unsigned char * hex_string_to_bin(char hex_string[])
48{ 66{
49 unsigned char * val = malloc(strlen(hex_string)); 67 unsigned char * val = malloc(strlen(hex_string));
50 char * pos = hex_string; 68 char * pos = hex_string;
51 int i=0; 69 int i=0;
52 while(i < strlen(hex_string)) 70 while(i < strlen(hex_string)) {
53 {
54 sscanf(pos,"%2hhx",&val[i]); 71 sscanf(pos,"%2hhx",&val[i]);
55 pos+=2; 72 pos+=2;
56 i++; 73 i++;
@@ -69,8 +86,7 @@ int main(int argc, char *argv[])
69 new_keys(); 86 new_keys();
70 printf("OUR ID: "); 87 printf("OUR ID: ");
71 uint32_t i; 88 uint32_t i;
72 for(i = 0; i < 32; i++) 89 for(i = 0; i < 32; i++) {
73 {
74 if(self_public_key[i] < 16) 90 if(self_public_key[i] < 16)
75 printf("0"); 91 printf("0");
76 printf("%hhX",self_public_key[i]); 92 printf("%hhX",self_public_key[i]);
@@ -86,8 +102,7 @@ int main(int argc, char *argv[])
86 uint8_t friend_id[32]; 102 uint8_t friend_id[32];
87 memcpy(friend_id, hex_string_to_bin(temp_id), 32); 103 memcpy(friend_id, hex_string_to_bin(temp_id), 32);
88 104
89 105 /* memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); */
90 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
91 106
92 107
93 DHT_addfriend(friend_id); 108 DHT_addfriend(friend_id);
@@ -99,15 +114,13 @@ int main(int argc, char *argv[])
99 int friendrequest = -1; 114 int friendrequest = -1;
100 uint8_t request_data[512]; 115 uint8_t request_data[512];
101 116
102 //initialize networking 117 /* initialize networking
103 //bind to ip 0.0.0.0:PORT 118 * bind to ip 0.0.0.0:PORT */
104 IP ip; 119 IP ip;
105 ip.i = 0; 120 ip.i = 0;
106 init_networking(ip, PORT); 121 init_networking(ip, PORT);
107 initNetCrypto(); 122 initNetCrypto();
108 123
109
110
111 perror("Initialization"); 124 perror("Initialization");
112 IP_Port bootstrap_ip_port; 125 IP_Port bootstrap_ip_port;
113 bootstrap_ip_port.port = htons(atoi(argv[2])); 126 bootstrap_ip_port.port = htons(atoi(argv[2]));
@@ -128,122 +141,99 @@ int main(int argc, char *argv[])
128 if ( file2==NULL ){return 1;} 141 if ( file2==NULL ){return 1;}
129 read1 = fread(buffer1, 1, 128, file1); 142 read1 = fread(buffer1, 1, 128, file1);
130 143
131 while(1) 144 while(1) {
132 { 145 while(receivepacket(&ip_port, data, &length) != -1) {
133 146 if(rand() % 3 != 1) { /* simulate packet loss */
134 while(receivepacket(&ip_port, data, &length) != -1) 147 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) {
135 { 148 /* if packet is not recognized */
136 if(rand() % 3 != 1)//simulate packet loss
137 {
138 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
139 {
140 //if packet is not recognized
141 printf("Received unhandled packet with length: %u\n", length); 149 printf("Received unhandled packet with length: %u\n", length);
142 } 150 } else {
143 else
144 {
145 printf("Received handled packet with length: %u\n", length); 151 printf("Received handled packet with length: %u\n", length);
146 } 152 }
147 } 153 }
148 } 154 }
149 friend_ip = DHT_getfriendip(friend_id); 155 friend_ip = DHT_getfriendip(friend_id);
150 if(friend_ip.ip.i != 0) 156 if(friend_ip.ip.i != 0) {
151 { 157 if(connection == -1 && friendrequest == -1) {
152 if(connection == -1 && friendrequest == -1)
153 {
154 printf("Sending friend request to peer:"); 158 printf("Sending friend request to peer:");
155 printip(friend_ip); 159 printip(friend_ip);
156 friendrequest = send_friendrequest(friend_id, friend_ip,(uint8_t *) "Hello World", 12); 160 friendrequest = send_friendrequest(friend_id, friend_ip,(uint8_t *) "Hello World", 12);
157 //connection = crypto_connect((uint8_t *)friend_id, friend_ip); 161 /* connection = crypto_connect((uint8_t *)friend_id, friend_ip); */
158 //connection = new_connection(friend_ip); 162 /* connection = new_connection(friend_ip); */
159 } 163 }
160 if(check_friendrequest(friendrequest) == 1) 164 if(check_friendrequest(friendrequest) == 1) {
161 {
162 printf("Started connecting to friend:"); 165 printf("Started connecting to friend:");
163 connection = crypto_connect(friend_id, friend_ip); 166 connection = crypto_connect(friend_id, friend_ip);
164 } 167 }
165 } 168 }
166 if(inconnection == -1) 169 if(inconnection == -1) {
167 {
168 uint8_t secret_nonce[crypto_box_NONCEBYTES]; 170 uint8_t secret_nonce[crypto_box_NONCEBYTES];
169 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 171 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
170 uint8_t session_key[crypto_box_PUBLICKEYBYTES]; 172 uint8_t session_key[crypto_box_PUBLICKEYBYTES];
171 inconnection = crypto_inbound(public_key, secret_nonce, session_key); 173 inconnection = crypto_inbound(public_key, secret_nonce, session_key);
172 inconnection = accept_crypto_inbound(inconnection, acceptedfriend_public_key, secret_nonce, session_key); 174 inconnection = accept_crypto_inbound(inconnection, acceptedfriend_public_key, secret_nonce, session_key);
173 //inconnection = incoming_connection(); 175 /* inconnection = incoming_connection(); */
174 if(inconnection != -1) 176 if(inconnection != -1) {
175 {
176 printf("Someone connected to us:\n"); 177 printf("Someone connected to us:\n");
177 // printip(connection_ip(inconnection)); 178 /* printip(connection_ip(inconnection)); */
178 } 179 }
179 } 180 }
180 if(handle_friendrequest(acceptedfriend_public_key, request_data) > 1) 181 if(handle_friendrequest(acceptedfriend_public_key, request_data) > 1) {
181 {
182 printf("RECIEVED FRIEND REQUEST: %s\n", request_data); 182 printf("RECIEVED FRIEND REQUEST: %s\n", request_data);
183 } 183 }
184 184
185 //if someone connected to us write what he sends to a file 185 /* if someone connected to us write what he sends to a file
186 //also send him our file. 186 * also send him our file. */
187 if(inconnection != -1) 187 if(inconnection != -1) {
188 { 188 if(write_cryptpacket(inconnection, buffer1, read1)) {
189 if(write_cryptpacket(inconnection, buffer1, read1))
190 {
191 printf("Wrote data1.\n"); 189 printf("Wrote data1.\n");
192 read1 = fread(buffer1, 1, 128, file1); 190 read1 = fread(buffer1, 1, 128, file1);
193 } 191 }
194 read2 = read_cryptpacket(inconnection, buffer2); 192 read2 = read_cryptpacket(inconnection, buffer2);
195 if(read2 != 0) 193 if(read2 != 0) {
196 {
197 printf("Received data1.\n"); 194 printf("Received data1.\n");
198 if(!fwrite(buffer2, read2, 1, file2)) 195 if(!fwrite(buffer2, read2, 1, file2)) {
199 {
200 printf("file write error1\n"); 196 printf("file write error1\n");
201 } 197 }
202 if(read2 < 128) 198 if(read2 < 128) {
203 {
204 printf("Closed file1 %u\n", read2); 199 printf("Closed file1 %u\n", read2);
205 fclose(file2); 200 fclose(file2);
206 } 201 }
207 } 202 }
208 else if(is_cryptoconnected(inconnection) == 4)//if buffer is empty and the connection timed out. 203 /* if buffer is empty and the connection timed out. */
209 { 204 else if(is_cryptoconnected(inconnection) == 4) {
210 crypto_kill(inconnection); 205 crypto_kill(inconnection);
211 } 206 }
212 } 207 }
213 //if we are connected to a friend send him data from the file. 208 /* if we are connected to a friend send him data from the file.
214 //also put what he sends us in a file. 209 * also put what he sends us in a file. */
215 if(is_cryptoconnected(connection) >= 3) 210 if(is_cryptoconnected(connection) >= 3) {
216 { 211 if(write_cryptpacket(0, buffer1, read1)) {
217 if(write_cryptpacket(0, buffer1, read1))
218 {
219 printf("Wrote data2.\n"); 212 printf("Wrote data2.\n");
220 read1 = fread(buffer1, 1, 128, file1); 213 read1 = fread(buffer1, 1, 128, file1);
221 } 214 }
222 read2 = read_cryptpacket(0, buffer2); 215 read2 = read_cryptpacket(0, buffer2);
223 if(read2 != 0) 216 if(read2 != 0) {
224 {
225 printf("Received data2.\n"); 217 printf("Received data2.\n");
226 if(!fwrite(buffer2, read2, 1, file2)) 218 if(!fwrite(buffer2, read2, 1, file2)) {
227 {
228 printf("file write error2\n"); 219 printf("file write error2\n");
229 } 220 }
230 if(read2 < 128) 221 if(read2 < 128) {
231 {
232 printf("Closed file2 %u\n", read2); 222 printf("Closed file2 %u\n", read2);
233 fclose(file2); 223 fclose(file2);
234 } 224 }
235 } 225 }
236 else if(is_cryptoconnected(connection) == 4)//if buffer is empty and the connection timed out. 226 /* if buffer is empty and the connection timed out. */
237 { 227 else if(is_cryptoconnected(connection) == 4) {
238 crypto_kill(connection); 228 crypto_kill(connection);
239 } 229 }
240 } 230 }
241 doDHT(); 231 doDHT();
242 doLossless_UDP(); 232 doLossless_UDP();
243 doNetCrypto(); 233 doNetCrypto();
244 //print_clientlist(); 234 /*print_clientlist();
245 //print_friendlist(); 235 *print_friendlist();
246 //c_sleep(300); 236 *c_sleep(300); */
247 c_sleep(1); 237 c_sleep(1);
248 } 238 }
249 239
diff --git a/testing/DHT_sendfiletest.c b/testing/DHT_sendfiletest.c
index 52ee7400..5b5d6c9f 100644
--- a/testing/DHT_sendfiletest.c
+++ b/testing/DHT_sendfiletest.c
@@ -14,7 +14,26 @@
14 * Saves all received data to: received.txt 14 * Saves all received data to: received.txt
15 * 15 *
16 * EX: ./test 127.0.0.1 33445 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef filename.txt ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeg 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 *
17 */ 35 */
36
18#include "../core/network.h" 37#include "../core/network.h"
19#include "../core/DHT.h" 38#include "../core/DHT.h"
20#include "../core/Lossless_UDP.h" 39#include "../core/Lossless_UDP.h"
@@ -82,68 +101,53 @@ int main(int argc, char *argv[])
82 if ( file2==NULL ){return 1;} 101 if ( file2==NULL ){return 1;}
83 read1 = fread(buffer1, 1, 128, file1); 102 read1 = fread(buffer1, 1, 128, file1);
84 103
85 while(1) 104 while(1) {
86 {
87 105
88 while(receivepacket(&ip_port, data, &length) != -1) 106 while(receivepacket(&ip_port, data, &length) != -1) {
89 { 107 if(rand() % 3 != 1) { /* simulate packet loss */
90 if(rand() % 3 != 1)//simulate packet loss 108 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) {
91 { 109 /* if packet is not recognized */
92 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
93 {
94 //if packet is not recognized
95 printf("Received unhandled packet with length: %u\n", length); 110 printf("Received unhandled packet with length: %u\n", length);
96 } 111 } else {
97 else
98 {
99 printf("Received handled packet with length: %u\n", length); 112 printf("Received handled packet with length: %u\n", length);
100 } 113 }
101 } 114 }
102 } 115 }
103 friend_ip = DHT_getfriendip((uint8_t *)argv[3]); 116 friend_ip = DHT_getfriendip((uint8_t *)argv[3]);
104 if(friend_ip.ip.i != 0) 117 if(friend_ip.ip.i != 0) {
105 { 118 if(connection == -1) {
106 if(connection == -1)
107 {
108 printf("Started connecting to friend:"); 119 printf("Started connecting to friend:");
109 printip(friend_ip); 120 printip(friend_ip);
110 connection = new_connection(friend_ip); 121 connection = new_connection(friend_ip);
111 } 122 }
112 } 123 }
113 if(inconnection == -1) 124 if(inconnection == -1) {
114 {
115 inconnection = incoming_connection(); 125 inconnection = incoming_connection();
116 if(inconnection != -1) 126 if(inconnection != -1) {
117 {
118 printf("Someone connected to us:"); 127 printf("Someone connected to us:");
119 printip(connection_ip(inconnection)); 128 printip(connection_ip(inconnection));
120 } 129 }
121 } 130 }
122 //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 */
123 //also send him our file. 132 /* also send him our file. */
124 if(inconnection != -1) 133 if(inconnection != -1) {
125 { 134 if(write_packet(inconnection, buffer1, read1)) {
126 if(write_packet(inconnection, buffer1, read1))
127 {
128 printf("Wrote data.\n"); 135 printf("Wrote data.\n");
129 read1 = fread(buffer1, 1, 128, file1); 136 read1 = fread(buffer1, 1, 128, file1);
130 } 137 }
131 read2 = read_packet(inconnection, buffer2); 138 read2 = read_packet(inconnection, buffer2);
132 if(read2 != 0) 139 if(read2 != 0) {
133 {
134 printf("Received data.\n"); 140 printf("Received data.\n");
135 if(!fwrite(buffer2, read2, 1, file2)) 141 if(!fwrite(buffer2, read2, 1, file2)) {
136 {
137 printf("file write error\n"); 142 printf("file write error\n");
138 } 143 }
139 if(read2 < 128) 144 if(read2 < 128) {
140 {
141 fclose(file2); 145 fclose(file2);
142 } 146 }
143 } 147 }
144 } 148 }
145 //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.
146 //also put what he sends us in a file. 150 * also put what he sends us in a file. */
147 if(is_connected(connection) == 3) 151 if(is_connected(connection) == 3)
148 { 152 {
149 if(write_packet(0, buffer1, read1)) 153 if(write_packet(0, buffer1, read1))
@@ -167,9 +171,9 @@ int main(int argc, char *argv[])
167 } 171 }
168 doDHT(); 172 doDHT();
169 doLossless_UDP(); 173 doLossless_UDP();
170 //print_clientlist(); 174 /* print_clientlist();
171 //print_friendlist(); 175 * print_friendlist();
172 //c_sleep(300); 176 * c_sleep(300); */
173 c_sleep(1); 177 c_sleep(1);
174 } 178 }
175 179
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index e194d06b..bb482595 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -7,7 +7,26 @@
7 * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 7 * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8 * 8 *
9 * The test will then ask you for the id (in hex format) of the friend you wish to add 9 * The test will then ask you for the id (in hex format) of the friend you wish to add
10 *
11 * Copyright (C) 2013 Tox project All Rights Reserved.
12 *
13 * This file is part of Tox.
14 *
15 * Tox is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * Tox is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
27 *
10 */ 28 */
29
11//#include "../core/network.h" 30//#include "../core/network.h"
12#include "../core/DHT.c" 31#include "../core/DHT.c"
13#include "../core/friend_requests.c" 32#include "../core/friend_requests.c"
@@ -28,17 +47,14 @@
28 47
29#define PORT 33445 48#define PORT 33445
30 49
31
32void print_clientlist() 50void print_clientlist()
33{ 51{
34 uint32_t i, j; 52 uint32_t i, j;
35 IP_Port p_ip; 53 IP_Port p_ip;
36 printf("___________________CLOSE________________________________\n"); 54 printf("___________________CLOSE________________________________\n");
37 for(i = 0; i < 4; i++) 55 for(i = 0; i < 4; i++) {
38 {
39 printf("ClientID: "); 56 printf("ClientID: ");
40 for(j = 0; j < 32; j++) 57 for(j = 0; j < 32; j++) {
41 {
42 printf("%c", close_clientlist[i].client_id[j]); 58 printf("%c", close_clientlist[i].client_id[j]);
43 } 59 }
44 p_ip = close_clientlist[i].ip_port; 60 p_ip = close_clientlist[i].ip_port;
@@ -56,12 +72,10 @@ void print_friendlist()
56 uint32_t i, j, k; 72 uint32_t i, j, k;
57 IP_Port p_ip; 73 IP_Port p_ip;
58 printf("_________________FRIENDS__________________________________\n"); 74 printf("_________________FRIENDS__________________________________\n");
59 for(k = 0; k < num_friends; k++) 75 for(k = 0; k < num_friends; k++) {
60 {
61 printf("FRIEND %u\n", k); 76 printf("FRIEND %u\n", k);
62 printf("ID: "); 77 printf("ID: ");
63 for(j = 0; j < 32; j++) 78 for(j = 0; j < 32; j++) {
64 {
65 printf("%c", friends_list[k].client_id[j]); 79 printf("%c", friends_list[k].client_id[j]);
66 } 80 }
67 p_ip = DHT_getfriendip(friends_list[k].client_id); 81 p_ip = DHT_getfriendip(friends_list[k].client_id);
@@ -69,11 +83,9 @@ void print_friendlist()
69 83
70 printf("\nCLIENTS IN LIST:\n\n"); 84 printf("\nCLIENTS IN LIST:\n\n");
71 85
72 for(i = 0; i < 4; i++) 86 for(i = 0; i < 4; i++) {
73 {
74 printf("ClientID: "); 87 printf("ClientID: ");
75 for(j = 0; j < 32; j++) 88 for(j = 0; j < 32; j++) {
76 {
77 if(0 <= friends_list[k].client_list[i].client_id[j] && friends_list[k].client_list[i].client_id[j] < 16) 89 if(0 <= friends_list[k].client_list[i].client_id[j] && friends_list[k].client_list[i].client_id[j] < 16)
78 printf("0"); 90 printf("0");
79 printf("%hhX", friends_list[k].client_list[i].client_id[j]); 91 printf("%hhX", friends_list[k].client_list[i].client_id[j]);
@@ -94,8 +106,7 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
94 uint32_t i; 106 uint32_t i;
95 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); 107 printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
96 printf("--------------------BEGIN-----------------------------\n"); 108 printf("--------------------BEGIN-----------------------------\n");
97 for(i = 0; i < length; i++) 109 for(i = 0; i < length; i++) {
98 {
99 if(data[i] < 16) 110 if(data[i] < 16)
100 printf("0"); 111 printf("0");
101 printf("%hhX",data[i]); 112 printf("%hhX",data[i]);
@@ -110,8 +121,7 @@ unsigned char * hex_string_to_bin(char hex_string[])
110 unsigned char * val = malloc(strlen(hex_string)); 121 unsigned char * val = malloc(strlen(hex_string));
111 char * pos = hex_string; 122 char * pos = hex_string;
112 int i=0; 123 int i=0;
113 while(i < strlen(hex_string)) 124 while(i < strlen(hex_string)) {
114 {
115 sscanf(pos,"%2hhx",&val[i]); 125 sscanf(pos,"%2hhx",&val[i]);
116 pos+=2; 126 pos+=2;
117 i++; 127 i++;
@@ -130,8 +140,7 @@ int main(int argc, char *argv[])
130 new_keys(); 140 new_keys();
131 printf("OUR ID: "); 141 printf("OUR ID: ");
132 uint32_t i; 142 uint32_t i;
133 for(i = 0; i < 32; i++) 143 for(i = 0; i < 32; i++) {
134 {
135 if(self_public_key[i] < 16) 144 if(self_public_key[i] < 16)
136 printf("0"); 145 printf("0");
137 printf("%hhX",self_public_key[i]); 146 printf("%hhX",self_public_key[i]);
@@ -142,8 +151,8 @@ int main(int argc, char *argv[])
142 scanf("%s", temp_id); 151 scanf("%s", temp_id);
143 DHT_addfriend(hex_string_to_bin(temp_id)); 152 DHT_addfriend(hex_string_to_bin(temp_id));
144 153
145 //initialize networking 154 /* initialize networking */
146 //bind to ip 0.0.0.0:PORT 155 /* bind to ip 0.0.0.0:PORT */
147 IP ip; 156 IP ip;
148 ip.i = 0; 157 ip.i = 0;
149 init_networking(ip, PORT); 158 init_networking(ip, PORT);
@@ -152,10 +161,10 @@ int main(int argc, char *argv[])
152 perror("Initialization"); 161 perror("Initialization");
153 IP_Port bootstrap_ip_port; 162 IP_Port bootstrap_ip_port;
154 bootstrap_ip_port.port = htons(atoi(argv[2])); 163 bootstrap_ip_port.port = htons(atoi(argv[2]));
155 //bootstrap_ip_port.ip.c[0] = 127; 164 /* bootstrap_ip_port.ip.c[0] = 127;
156 //bootstrap_ip_port.ip.c[1] = 0; 165 * bootstrap_ip_port.ip.c[1] = 0;
157 //bootstrap_ip_port.ip.c[2] = 0; 166 * bootstrap_ip_port.ip.c[2] = 0;
158 //bootstrap_ip_port.ip.c[3] = 1; 167 * bootstrap_ip_port.ip.c[3] = 1; */
159 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 168 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
160 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 169 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
161 170
@@ -163,20 +172,15 @@ int main(int argc, char *argv[])
163 uint8_t data[MAX_UDP_PACKET_SIZE]; 172 uint8_t data[MAX_UDP_PACKET_SIZE];
164 uint32_t length; 173 uint32_t length;
165 174
166 while(1) 175 while(1) {
167 {
168 176
169 doDHT(); 177 doDHT();
170 178
171 while(receivepacket(&ip_port, data, &length) != -1) 179 while(receivepacket(&ip_port, data, &length) != -1) {
172 { 180 if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) {
173 if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port))
174 {
175 //unhandled packet 181 //unhandled packet
176 printpacket(data, length, ip_port); 182 printpacket(data, length, ip_port);
177 } 183 } else {
178 else
179 {
180 printf("Received handled packet with length: %u\n", length); 184 printf("Received handled packet with length: %u\n", length);
181 } 185 }
182 } 186 }
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
30void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) 47void 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(); */
104void Lossless_UDP() 121void 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
131int main(int argc, char *argv[]) 143int 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;
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;
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index f9215b44..19ab4cc3 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -17,7 +17,24 @@
17 * Or the argument can be the path to the save file. 17 * Or the argument can be the path to the save file.
18 * 18 *
19 * EX: ./test Save.bak 19 * EX: ./test Save.bak
20 * 20 *
21 * Copyright (C) 2013 Tox project All Rights Reserved.
22 *
23 * This file is part of Tox.
24 *
25 * Tox is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * Tox is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
37 *
21 */ 38 */
22 39
23#include "../core/Messenger.h" 40#include "../core/Messenger.h"
@@ -87,15 +104,12 @@ int main(int argc, char *argv[])
87 exit(0); 104 exit(0);
88 } 105 }
89 initMessenger(); 106 initMessenger();
90 if(argc > 3) 107 if(argc > 3) {
91 {
92 IP_Port bootstrap_ip_port; 108 IP_Port bootstrap_ip_port;
93 bootstrap_ip_port.port = htons(atoi(argv[2])); 109 bootstrap_ip_port.port = htons(atoi(argv[2]));
94 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 110 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
95 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 111 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
96 } 112 } else {
97 else
98 {
99 FILE *file = fopen(argv[1], "rb"); 113 FILE *file = fopen(argv[1], "rb");
100 if ( file==NULL ){return 1;} 114 if ( file==NULL ){return 1;}
101 int read; 115 int read;
@@ -110,8 +124,7 @@ int main(int argc, char *argv[])
110 124
111 printf("OUR ID: "); 125 printf("OUR ID: ");
112 uint32_t i; 126 uint32_t i;
113 for(i = 0; i < 32; i++) 127 for(i = 0; i < 32; i++) {
114 {
115 if(self_public_key[i] < 16) 128 if(self_public_key[i] < 16)
116 printf("0"); 129 printf("0");
117 printf("%hhX",self_public_key[i]); 130 printf("%hhX",self_public_key[i]);
@@ -121,16 +134,14 @@ int main(int argc, char *argv[])
121 134
122 char temp_id[128]; 135 char temp_id[128];
123 printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); 136 printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n");
124 if(scanf("%s", temp_id) != 1) 137 if(scanf("%s", temp_id) != 1) {
125 {
126 return 1; 138 return 1;
127 } 139 }
128 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 140 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
129 141
130 perror("Initialization"); 142 perror("Initialization");
131 143
132 while(1) 144 while(1) {
133 {
134 uint8_t name[128]; 145 uint8_t name[128];
135 getname(num, name); 146 getname(num, name);
136 printf("%s\n", name); 147 printf("%s\n", name);
@@ -145,6 +156,5 @@ int main(int argc, char *argv[])
145 fwrite(buffer, 1, Messenger_size(), file); 156 fwrite(buffer, 1, Messenger_size(), file);
146 free(buffer); 157 free(buffer);
147 fclose(file); 158 fclose(file);
148 } 159 }
149
150} 160}
diff --git a/testing/nTox.c b/testing/nTox.c
index 097c73af..caa7d45c 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -1,3 +1,26 @@
1/* nTox.c
2 *
3 * Textual frontend for Tox.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
1#include "nTox.h" 24#include "nTox.h"
2#include <stdio.h> 25#include <stdio.h>
3#include <time.h> 26#include <time.h>
@@ -28,8 +51,7 @@ unsigned char * hex_string_to_bin(char hex_string[])
28 unsigned char * val = malloc(strlen(hex_string)); 51 unsigned char * val = malloc(strlen(hex_string));
29 char * pos = hex_string; 52 char * pos = hex_string;
30 int i=0; 53 int i=0;
31 while(i < strlen(hex_string)) 54 while(i < strlen(hex_string)) {
32 {
33 sscanf(pos,"%2hhx",&val[i]); 55 sscanf(pos,"%2hhx",&val[i]);
34 pos+=2; 56 pos+=2;
35 i++; 57 i++;
@@ -167,6 +189,7 @@ void do_refresh()
167 clrtoeol(); 189 clrtoeol();
168 refresh(); 190 refresh();
169} 191}
192
170void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) 193void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
171{ 194{
172 new_lines("[i] received friend request"); 195 new_lines("[i] received friend request");
@@ -182,6 +205,7 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
182 new_lines(numchar); 205 new_lines(numchar);
183 } 206 }
184} 207}
208
185void print_message(int friendnumber, uint8_t * string, uint16_t length) 209void print_message(int friendnumber, uint8_t * string, uint16_t length)
186{ 210{
187 char name[MAX_NAME_LENGTH]; 211 char name[MAX_NAME_LENGTH];
@@ -197,6 +221,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
197 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this 221 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
198 new_lines(msg); 222 new_lines(msg);
199} 223}
224
200void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { 225void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
201 char name[MAX_NAME_LENGTH]; 226 char name[MAX_NAME_LENGTH];
202 getname(friendnumber, (uint8_t*)name); 227 getname(friendnumber, (uint8_t*)name);
@@ -204,6 +229,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
204 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); 229 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
205 new_lines(msg); 230 new_lines(msg);
206} 231}
232
207void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { 233void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
208 char name[MAX_NAME_LENGTH]; 234 char name[MAX_NAME_LENGTH];
209 getname(friendnumber, (uint8_t*)name); 235 getname(friendnumber, (uint8_t*)name);
@@ -211,6 +237,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
211 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); 237 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
212 new_lines(msg); 238 new_lines(msg);
213} 239}
240
214void load_key(){ 241void load_key(){
215 FILE *data_file = NULL; 242 FILE *data_file = NULL;
216 if ((data_file = fopen("data","r"))) { 243 if ((data_file = fopen("data","r"))) {
@@ -237,6 +264,7 @@ void load_key(){
237 } 264 }
238 fclose(data_file); 265 fclose(data_file);
239} 266}
267
240int main(int argc, char *argv[]) 268int main(int argc, char *argv[])
241{ 269{
242 if (argc < 4) { 270 if (argc < 4) {
@@ -294,9 +322,7 @@ int main(int argc, char *argv[])
294 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 322 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
295 nodelay(stdscr, TRUE); 323 nodelay(stdscr, TRUE);
296 while(true) { 324 while(true) {
297 325 if (on == 0 && DHT_isconnected()) {
298 if (on == 0 && DHT_isconnected())
299 {
300 new_lines("[i] connected to DHT\n[i] define username with /n"); 326 new_lines("[i] connected to DHT\n[i] define username with /n");
301 on = 1; 327 on = 1;
302 } 328 }
diff --git a/testing/nTox.h b/testing/nTox.h
index fbc5d5c0..9b69d959 100644
--- a/testing/nTox.h
+++ b/testing/nTox.h
@@ -1,3 +1,26 @@
1/* nTox.h
2 *
3 *Textual frontend for Tox.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
1#ifndef NTOX_H 24#ifndef NTOX_H
2#define NTOX_H 25#define NTOX_H
3 26