summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/CMakeLists.txt1
-rw-r--r--testing/DHT_test.c75
-rw-r--r--testing/Lossless_UDP_testclient.c65
-rw-r--r--testing/Lossless_UDP_testserver.c40
-rw-r--r--testing/Messenger_test.c3
-rw-r--r--testing/cmake/timer_test.cmake9
-rw-r--r--testing/nTox.c4
-rw-r--r--testing/timer_test.c68
-rw-r--r--testing/toxic/chat.c4
-rw-r--r--testing/toxic/dhtstatus.c4
-rw-r--r--testing/toxic/friendlist.c2
-rw-r--r--testing/toxic/main.c18
-rw-r--r--testing/toxic/prompt.c6
-rw-r--r--testing/toxic/windows.c48
-rw-r--r--testing/toxic/windows.h2
15 files changed, 138 insertions, 211 deletions
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index 9e07135c..e3cdc838 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -9,7 +9,6 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
9include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) 9include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
10include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) 10include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
11include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake) 11include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake)
12include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/timer_test.cmake)
13 12
14if(WIN32) 13if(WIN32)
15# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) 14# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 3883f3a7..8ab9157e 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -28,8 +28,8 @@
28 */ 28 */
29 29
30//#include "../core/network.h" 30//#include "../core/network.h"
31#include "../core/DHT.c" 31#include "../core/DHT.h"
32#include "../core/friend_requests.c" 32#include "../core/friend_requests.h"
33#include "misc_tools.h" 33#include "misc_tools.h"
34 34
35#include <string.h> 35#include <string.h>
@@ -48,7 +48,7 @@
48 48
49#define PORT 33445 49#define PORT 33445
50 50
51void print_clientlist() 51void print_clientlist(DHT *dht)
52{ 52{
53 uint32_t i, j; 53 uint32_t i, j;
54 IP_Port p_ip; 54 IP_Port p_ip;
@@ -58,34 +58,34 @@ void print_clientlist()
58 printf("ClientID: "); 58 printf("ClientID: ");
59 59
60 for (j = 0; j < 32; j++) { 60 for (j = 0; j < 32; j++) {
61 printf("%02hhX", close_clientlist[i].client_id[j]); 61 printf("%02hhX", dht->close_clientlist[i].client_id[j]);
62 } 62 }
63 63
64 p_ip = close_clientlist[i].ip_port; 64 p_ip = dht->close_clientlist[i].ip_port;
65 printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); 65 printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
66 printf("\nTimestamp: %llu", (long long unsigned int) close_clientlist[i].timestamp); 66 printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp);
67 printf("\nLast pinged: %llu\n", (long long unsigned int) close_clientlist[i].last_pinged); 67 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged);
68 p_ip = close_clientlist[i].ret_ip_port; 68 p_ip = dht->close_clientlist[i].ret_ip_port;
69 printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); 69 printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
70 printf("Timestamp: %llu\n", (long long unsigned int) close_clientlist[i].ret_timestamp); 70 printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp);
71 } 71 }
72} 72}
73 73
74void print_friendlist() 74void print_friendlist(DHT *dht)
75{ 75{
76 uint32_t i, j, k; 76 uint32_t i, j, k;
77 IP_Port p_ip; 77 IP_Port p_ip;
78 printf("_________________FRIENDS__________________________________\n"); 78 printf("_________________FRIENDS__________________________________\n");
79 79
80 for (k = 0; k < num_friends; k++) { 80 for (k = 0; k < dht->num_friends; k++) {
81 printf("FRIEND %u\n", k); 81 printf("FRIEND %u\n", k);
82 printf("ID: "); 82 printf("ID: ");
83 83
84 for (j = 0; j < 32; j++) { 84 for (j = 0; j < 32; j++) {
85 printf("%c", friends_list[k].client_id[j]); 85 printf("%c", dht->friends_list[k].client_id[j]);
86 } 86 }
87 87
88 p_ip = DHT_getfriendip(friends_list[k].client_id); 88 p_ip = DHT_getfriendip(dht, dht->friends_list[k].client_id);
89 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); 89 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
90 90
91 printf("\nCLIENTS IN LIST:\n\n"); 91 printf("\nCLIENTS IN LIST:\n\n");
@@ -94,19 +94,19 @@ void print_friendlist()
94 printf("ClientID: "); 94 printf("ClientID: ");
95 95
96 for (j = 0; j < 32; j++) { 96 for (j = 0; j < 32; j++) {
97 if (friends_list[k].client_list[i].client_id[j] < 16) 97 if (dht->friends_list[k].client_list[i].client_id[j] < 16)
98 printf("0"); 98 printf("0");
99 99
100 printf("%hhX", friends_list[k].client_list[i].client_id[j]); 100 printf("%hhX", dht->friends_list[k].client_list[i].client_id[j]);
101 } 101 }
102 102
103 p_ip = friends_list[k].client_list[i].ip_port; 103 p_ip = dht->friends_list[k].client_list[i].ip_port;
104 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); 104 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
105 printf("\nTimestamp: %llu", (long long unsigned int) friends_list[k].client_list[i].timestamp); 105 printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp);
106 printf("\nLast pinged: %llu\n", (long long unsigned int) friends_list[k].client_list[i].last_pinged); 106 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged);
107 p_ip = friends_list[k].client_list[i].ret_ip_port; 107 p_ip = dht->friends_list[k].client_list[i].ret_ip_port;
108 printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); 108 printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
109 printf("Timestamp: %llu\n", (long long unsigned int)friends_list[k].client_list[i].ret_timestamp); 109 printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp);
110 } 110 }
111 } 111 }
112} 112}
@@ -130,21 +130,28 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
130int main(int argc, char *argv[]) 130int main(int argc, char *argv[])
131{ 131{
132 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); 132 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
133 /* initialize networking */
134 /* bind to ip 0.0.0.0:PORT */
135 IP ip;
136 ip.i = 0;
137
138 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
139 init_cryptopackets(dht);
133 140
134 if (argc < 4) { 141 if (argc < 4) {
135 printf("usage %s ip port public_key\n", argv[0]); 142 printf("usage %s ip port public_key\n", argv[0]);
136 exit(0); 143 exit(0);
137 } 144 }
138 145
139 new_keys(); 146 new_keys(dht->c);
140 printf("OUR ID: "); 147 printf("OUR ID: ");
141 uint32_t i; 148 uint32_t i;
142 149
143 for (i = 0; i < 32; i++) { 150 for (i = 0; i < 32; i++) {
144 if (self_public_key[i] < 16) 151 if (dht->c->self_public_key[i] < 16)
145 printf("0"); 152 printf("0");
146 153
147 printf("%hhX", self_public_key[i]); 154 printf("%hhX", dht->c->self_public_key[i]);
148 } 155 }
149 156
150 char temp_id[128]; 157 char temp_id[128];
@@ -153,13 +160,7 @@ int main(int argc, char *argv[])
153 if (scanf("%s", temp_id) != 1) 160 if (scanf("%s", temp_id) != 1)
154 exit(0); 161 exit(0);
155 162
156 DHT_addfriend(hex_string_to_bin(temp_id)); 163 DHT_addfriend(dht, hex_string_to_bin(temp_id));
157
158 /* initialize networking */
159 /* bind to ip 0.0.0.0:PORT */
160 IP ip;
161 ip.i = 0;
162 init_networking(ip, PORT);
163 164
164 165
165 perror("Initialization"); 166 perror("Initialization");
@@ -170,7 +171,7 @@ int main(int argc, char *argv[])
170 * bootstrap_ip_port.ip.c[2] = 0; 171 * bootstrap_ip_port.ip.c[2] = 0;
171 * bootstrap_ip_port.ip.c[3] = 1; */ 172 * bootstrap_ip_port.ip.c[3] = 1; */
172 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 173 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
173 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 174 DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
174 175
175 /* 176 /*
176 IP_Port ip_port; 177 IP_Port ip_port;
@@ -178,12 +179,9 @@ int main(int argc, char *argv[])
178 uint32_t length; 179 uint32_t length;
179 */ 180 */
180 181
181 DHT_init();
182 friendreq_init();
183
184 while (1) { 182 while (1) {
185 183
186 doDHT(); 184 do_DHT(dht);
187 185
188 /* slvrTODO: 186 /* slvrTODO:
189 while(receivepacket(&ip_port, data, &length) != -1) { 187 while(receivepacket(&ip_port, data, &length) != -1) {
@@ -195,13 +193,12 @@ int main(int argc, char *argv[])
195 } 193 }
196 } 194 }
197 */ 195 */
198 networking_poll(); 196 networking_poll(dht->c->lossless_udp->net);
199 197
200 print_clientlist(); 198 print_clientlist(dht);
201 print_friendlist(); 199 print_friendlist(dht);
202 c_sleep(300); 200 c_sleep(300);
203 } 201 }
204 202
205 shutdown_networking();
206 return 0; 203 return 0;
207} 204}
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c
index 575be2bd..09e9e0a3 100644
--- a/testing/Lossless_UDP_testclient.c
+++ b/testing/Lossless_UDP_testclient.c
@@ -122,29 +122,29 @@ void printconnection(int connection_id)
122 122
123/*( receive packets and send them to the packethandler */ 123/*( receive packets and send them to the packethandler */
124/*run doLossless_UDP(); */ 124/*run doLossless_UDP(); */
125void Lossless_UDP() 125//void Lossless_UDP()
126{ 126//{
127 /* IP_Port ip_port; 127/* IP_Port ip_port;
128 uint8_t data[MAX_UDP_PACKET_SIZE]; 128 uint8_t data[MAX_UDP_PACKET_SIZE];
129 uint32_t length; 129 uint32_t length;
130 while (receivepacket(&ip_port, data, &length) != -1) { 130 while (receivepacket(&ip_port, data, &length) != -1) {
131 printf("packet with length: %u\n", length); */ 131 printf("packet with length: %u\n", length); */
132 /* if(rand() % 3 != 1)//add packet loss 132/* if(rand() % 3 != 1)//add packet loss
133 { */ 133 { */
134 /* 134/*
135 if (LosslessUDP_handlepacket(data, length, ip_port)) 135 if (LosslessUDP_handlepacket(data, length, ip_port))
136 printpacket(data, length, ip_port); 136 printpacket(data, length, ip_port);
137 else 137 else
138 printf("Received handled packet with length: %u\n", length); //printconnection(0); */ 138 printf("Received handled packet with length: %u\n", length); //printconnection(0); */
139
140 /* } */
141 /* }*/
142
143 networking_poll();
144
145 doLossless_UDP();
146 139
147} 140/* } */
141/* }*/
142
143//networking_poll();
144
145//doLossless_UDP();
146
147//}
148 148
149int main(int argc, char *argv[]) 149int main(int argc, char *argv[])
150{ 150{
@@ -166,25 +166,26 @@ int main(int argc, char *argv[])
166 /* bind to ip 0.0.0.0:PORT */ 166 /* bind to ip 0.0.0.0:PORT */
167 IP ip; 167 IP ip;
168 ip.i = 0; 168 ip.i = 0;
169 init_networking(ip, PORT); 169 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
170 perror("Initialization"); 170 perror("Initialization");
171 IP_Port serverip; 171 IP_Port serverip;
172 serverip.ip.i = inet_addr(argv[1]); 172 serverip.ip.i = inet_addr(argv[1]);
173 serverip.port = htons(atoi(argv[2])); 173 serverip.port = htons(atoi(argv[2]));
174 printip(serverip); 174 printip(serverip);
175 int connection = new_connection(serverip); 175 int connection = new_connection(ludp, serverip);
176 uint64_t timer = current_time(); 176 uint64_t timer = current_time();
177 177
178 while (1) { 178 while (1) {
179 /* printconnection(connection); */ 179 /* printconnection(connection); */
180 Lossless_UDP(); 180 networking_poll(ludp->net);
181 do_lossless_udp(ludp);
181 182
182 if (is_connected(connection) == 3) { 183 if (is_connected(ludp, connection) == 3) {
183 printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); 184 printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer));
184 break; 185 break;
185 } 186 }
186 187
187 if (is_connected(connection) == 0) { 188 if (is_connected(ludp, connection) == 0) {
188 printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); 189 printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer));
189 return 1; 190 return 1;
190 } 191 }
@@ -194,25 +195,25 @@ int main(int argc, char *argv[])
194 195
195 timer = current_time(); 196 timer = current_time();
196 197
197 LosslessUDP_init();
198 198
199 /*read first part of file */ 199 /*read first part of file */
200 read = fread(buffer, 1, 512, file); 200 read = fread(buffer, 1, 512, file);
201 201
202 while (1) { 202 while (1) {
203 /* printconnection(connection); */ 203 /* printconnection(connection); */
204 Lossless_UDP(); 204 networking_poll(ludp->net);
205 do_lossless_udp(ludp);
205 206
206 if (is_connected(connection) == 3) { 207 if (is_connected(ludp, connection) == 3) {
207 208
208 if (write_packet(connection, buffer, read)) { 209 if (write_packet(ludp, connection, buffer, read)) {
209 /* printf("Wrote data.\n"); */ 210 /* printf("Wrote data.\n"); */
210 read = fread(buffer, 1, 512, file); 211 read = fread(buffer, 1, 512, file);
211 212
212 } 213 }
213 214
214 /* printf("%u\n", sendqueue(connection)); */ 215 /* printf("%u\n", sendqueue(connection)); */
215 if (sendqueue(connection) == 0) { 216 if (sendqueue(ludp, connection) == 0) {
216 if (read == 0) { 217 if (read == 0) {
217 printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); 218 printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer));
218 break; 219 break;
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index dec50d7f..a82b787a 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -118,27 +118,27 @@ void printconnection(int connection_id)
118 118
119/* receive packets and send them to the packethandler 119/* receive packets and send them to the packethandler
120 * run doLossless_UDP(); */ 120 * run doLossless_UDP(); */
121void Lossless_UDP() 121//void Lossless_UDP()
122{ 122//{
123// IP_Port ip_port; 123// IP_Port ip_port;
124// uint8_t data[MAX_UDP_PACKET_SIZE]; 124// uint8_t data[MAX_UDP_PACKET_SIZE];
125// uint32_t length; 125// uint32_t length;
126// while (receivepacket(&ip_port, data, &length) != -1) { 126// while (receivepacket(&ip_port, data, &length) != -1) {
127 //if(rand() % 3 != 1)//add packet loss 127//if(rand() % 3 != 1)//add packet loss
128 //{ 128//{
129// if (LosslessUDP_handlepacket(data, length, ip_port)) { 129// if (LosslessUDP_handlepacket(data, length, ip_port)) {
130// printpacket(data, length, ip_port); 130// printpacket(data, length, ip_port);
131// } else { 131// } else {
132 //printconnection(0); 132//printconnection(0);
133// printf("Received handled packet with length: %u\n", length); 133// printf("Received handled packet with length: %u\n", length);
134// } 134// }
135 //} 135//}
136// } 136// }
137 137
138 networking_poll(); 138// networking_poll();
139 139
140 doLossless_UDP(); 140//doLossless_UDP();
141} 141//}
142 142
143 143
144int main(int argc, char *argv[]) 144int main(int argc, char *argv[])
@@ -161,20 +161,19 @@ int main(int argc, char *argv[])
161 //bind to ip 0.0.0.0:PORT 161 //bind to ip 0.0.0.0:PORT
162 IP ip; 162 IP ip;
163 ip.i = 0; 163 ip.i = 0;
164 init_networking(ip, PORT); 164 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
165 perror("Initialization"); 165 perror("Initialization");
166 166
167 int connection; 167 int connection;
168 uint64_t timer = current_time(); 168 uint64_t timer = current_time();
169 169
170 LosslessUDP_init();
171
172 while (1) { 170 while (1) {
173 Lossless_UDP(); 171 networking_poll(ludp->net);
174 connection = incoming_connection(); 172 do_lossless_udp(ludp);
173 connection = incoming_connection(ludp);
175 174
176 if (connection != -1) { 175 if (connection != -1) {
177 if (is_connected(connection) == 2) { 176 if (is_connected(ludp, connection) == 2) {
178 printf("Received the connection.\n"); 177 printf("Received the connection.\n");
179 178
180 } 179 }
@@ -189,11 +188,12 @@ int main(int argc, char *argv[])
189 188
190 while (1) { 189 while (1) {
191 //printconnection(0); 190 //printconnection(0);
192 Lossless_UDP(); 191 networking_poll(ludp->net);
192 do_lossless_udp(ludp);
193 193
194 if (is_connected(connection) >= 2) { 194 if (is_connected(ludp, connection) >= 2) {
195 kill_connection_in(connection, 3000000); 195 kill_connection_in(ludp, connection, 3000000);
196 read = read_packet(connection, buffer); 196 read = read_packet(ludp, connection, buffer);
197 197
198 if (read != 0) { 198 if (read != 0) {
199 // printf("Received data.\n"); 199 // printf("Received data.\n");
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
202 } 202 }
203 } 203 }
204 204
205 if (is_connected(connection) == 4) { 205 if (is_connected(ludp, connection) == 4) {
206 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); 206 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
207 fclose(file); 207 fclose(file);
208 return 1; 208 return 1;
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index f8685b39..c76584d7 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -48,6 +48,7 @@
48#include <unistd.h> 48#include <unistd.h>
49#include <arpa/inet.h> 49#include <arpa/inet.h>
50#define c_sleep(x) usleep(1000*x) 50#define c_sleep(x) usleep(1000*x)
51#define PORT 33445
51 52
52#endif 53#endif
53 54
@@ -106,7 +107,7 @@ int main(int argc, char *argv[])
106 IP_Port bootstrap_ip_port; 107 IP_Port bootstrap_ip_port;
107 bootstrap_ip_port.port = htons(atoi(argv[2])); 108 bootstrap_ip_port.port = htons(atoi(argv[2]));
108 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 109 bootstrap_ip_port.ip.i = inet_addr(argv[1]);
109 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 110 DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
110 } else { 111 } else {
111 FILE *file = fopen(argv[1], "rb"); 112 FILE *file = fopen(argv[1], "rb");
112 113
diff --git a/testing/cmake/timer_test.cmake b/testing/cmake/timer_test.cmake
deleted file mode 100644
index a5f8c5ec..00000000
--- a/testing/cmake/timer_test.cmake
+++ /dev/null
@@ -1,9 +0,0 @@
1cmake_minimum_required(VERSION 2.6.0)
2project(timer_test C)
3
4set(exe_name timer_test)
5
6add_executable(${exe_name}
7 timer_test.c)
8
9linkCoreLibraries(${exe_name})
diff --git a/testing/nTox.c b/testing/nTox.c
index 8813f305..a476cc19 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -521,12 +521,12 @@ int main(int argc, char *argv[])
521 exit(1); 521 exit(1);
522 522
523 unsigned char *binary_string = hex_string_to_bin(argv[3]); 523 unsigned char *binary_string = hex_string_to_bin(argv[3]);
524 DHT_bootstrap(bootstrap_ip_port, binary_string); 524 DHT_bootstrap(m->dht, bootstrap_ip_port, binary_string);
525 free(binary_string); 525 free(binary_string);
526 nodelay(stdscr, TRUE); 526 nodelay(stdscr, TRUE);
527 527
528 while (true) { 528 while (true) {
529 if (on == 0 && DHT_isconnected()) { 529 if (on == 0 && DHT_isconnected(m->dht)) {
530 new_lines("[i] connected to DHT\n[i] define username with /n"); 530 new_lines("[i] connected to DHT\n[i] define username with /n");
531 on = 1; 531 on = 1;
532 } 532 }
diff --git a/testing/timer_test.c b/testing/timer_test.c
deleted file mode 100644
index f47d4878..00000000
--- a/testing/timer_test.c
+++ /dev/null
@@ -1,68 +0,0 @@
1#include "../core/timer.h"
2#include <stdio.h>
3
4#ifdef WINDOWS
5#include <windows.h>
6#else
7#include <unistd.h>
8#endif
9
10void mssleep(int ms)
11{
12#ifdef WINDOWS
13 Sleep(ms);
14#else
15 usleep(ms * 1000);
16#endif
17}
18
19int callback(timer *t, void *arg)
20{
21 printf("%s\n", (char *)arg);
22 return 1;
23}
24
25int repeating(timer *t, void *arg)
26{
27 printf("%s\n", (char *)arg);
28 timer_start(t, 3);
29 return 0;
30}
31
32extern void timer_debug_print();
33
34int main(int argc, char **argv)
35{
36 timer_init();
37 timer_debug_print();
38
39 timer *t = new_timer();
40 timer_setup(t, &callback, "Long setup method, 4 seconds");
41 timer_start(t, 4);
42 timer_debug_print();
43
44 timer_single(&repeating, (void *)"This repeats every 3 seconds", 3);
45 timer_debug_print();
46
47 timer_single(&callback, "Short method, 4 seconds", 4);
48 timer_debug_print();
49
50 timer_single(&callback, "1 second", 1);
51 timer_debug_print();
52
53 timer_single(&callback, "15 seconds", 15);
54 timer_debug_print();
55
56 timer_single(&callback, "10 seconds", 10);
57 timer_debug_print();
58
59 timer_us(&callback, "100000us", 100000);
60 timer_us(&callback, "13s", 13 * US_PER_SECOND);
61
62 while (true) {
63 timer_poll();
64 mssleep(10);
65 }
66
67 return 0;
68}
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 57404a59..c7979843 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -123,7 +123,7 @@ static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint1
123 123
124 status[len - 1] = '\0'; 124 status[len - 1] = '\0';
125 fix_name(status); 125 fix_name(status);
126 126
127 wattron(ctx->history, COLOR_PAIR(3)); 127 wattron(ctx->history, COLOR_PAIR(3));
128 wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); 128 wprintw(ctx->history, "* Your partner changed status to '%s'\n", status);
129 wattroff(ctx->history, COLOR_PAIR(3)); 129 wattroff(ctx->history, COLOR_PAIR(3));
@@ -342,7 +342,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd)
342 wprintw(ctx->history, "Invalid command.\n"); 342 wprintw(ctx->history, "Invalid command.\n");
343} 343}
344 344
345static void chat_onDraw(ToxWindow *self) 345static void chat_onDraw(ToxWindow *self, Messenger *m)
346{ 346{
347 curs_set(1); 347 curs_set(1);
348 int x, y; 348 int x, y;
diff --git a/testing/toxic/dhtstatus.c b/testing/toxic/dhtstatus.c
index a11dc616..6c9f2a80 100644
--- a/testing/toxic/dhtstatus.c
+++ b/testing/toxic/dhtstatus.c
@@ -34,9 +34,9 @@ static void dhtstatus_onKey(ToxWindow *self, Messenger *m, int key)
34 } 34 }
35} 35}
36 36
37static void dhtstatus_onDraw(ToxWindow *self) 37static void dhtstatus_onDraw(ToxWindow *self, Messenger *m)
38{ 38{
39 Client_data *close_clientlist = DHT_get_close_list(); 39 Client_data *close_clientlist = DHT_get_close_list(m->dht);
40 curs_set(0); 40 curs_set(0);
41 werase(self->window); 41 werase(self->window);
42 42
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c
index 0a58bc54..2e46f124 100644
--- a/testing/toxic/friendlist.c
+++ b/testing/toxic/friendlist.c
@@ -102,7 +102,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key)
102 } 102 }
103} 103}
104 104
105static void friendlist_onDraw(ToxWindow *self) 105static void friendlist_onDraw(ToxWindow *self, Messenger *m)
106{ 106{
107 curs_set(0); 107 curs_set(0);
108 werase(self->window); 108 werase(self->window);
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 9abe8de4..e5525e94 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -90,11 +90,11 @@ static Messenger *init_tox()
90#define MAXSERVERS 50 90#define MAXSERVERS 50
91 91
92/* Connects to a random DHT server listed in the DHTservers file */ 92/* Connects to a random DHT server listed in the DHTservers file */
93int init_connection(void) 93int init_connection(Messenger *m)
94{ 94{
95 FILE *fp = NULL; 95 FILE *fp = NULL;
96 96
97 if (DHT_isconnected()) 97 if (DHT_isconnected(m->dht))
98 return 0; 98 return 0;
99 99
100 fp = fopen(SRVLIST_FILE, "r"); 100 fp = fopen(SRVLIST_FILE, "r");
@@ -135,7 +135,7 @@ int init_connection(void)
135 135
136 dht.ip.i = resolved_address; 136 dht.ip.i = resolved_address;
137 unsigned char *binary_string = hex_string_to_bin(key); 137 unsigned char *binary_string = hex_string_to_bin(key);
138 DHT_bootstrap(dht, binary_string); 138 DHT_bootstrap(m->dht, dht, binary_string);
139 free(binary_string); 139 free(binary_string);
140 return 0; 140 return 0;
141} 141}
@@ -146,18 +146,18 @@ static void do_tox(Messenger *m, ToxWindow *prompt)
146 static int conn_err = 0; 146 static int conn_err = 0;
147 static bool dht_on = false; 147 static bool dht_on = false;
148 148
149 if (!dht_on && !DHT_isconnected() && !(conn_try++ % 100)) { 149 if (!dht_on && !DHT_isconnected(m->dht) && !(conn_try++ % 100)) {
150 if (!conn_err) { 150 if (!conn_err) {
151 conn_err = init_connection(); 151 conn_err = init_connection(m);
152 wprintw(prompt->window, "\nEstablishing connection...\n"); 152 wprintw(prompt->window, "\nEstablishing connection...\n");
153 153
154 if (conn_err) 154 if (conn_err)
155 wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err); 155 wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err);
156 } 156 }
157 } else if (!dht_on && DHT_isconnected()) { 157 } else if (!dht_on && DHT_isconnected(m->dht)) {
158 dht_on = true; 158 dht_on = true;
159 wprintw(prompt->window, "\nDHT connected.\n"); 159 wprintw(prompt->window, "\nDHT connected.\n");
160 } else if (dht_on && !DHT_isconnected()) { 160 } else if (dht_on && !DHT_isconnected(m->dht)) {
161 dht_on = false; 161 dht_on = false;
162 wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); 162 wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
163 } 163 }
@@ -297,7 +297,7 @@ int main(int argc, char *argv[])
297 strcpy(DATA_FILE, user_config_dir); 297 strcpy(DATA_FILE, user_config_dir);
298 strcat(DATA_FILE, CONFIGDIR); 298 strcat(DATA_FILE, CONFIGDIR);
299 strcat(DATA_FILE, "data"); 299 strcat(DATA_FILE, "data");
300 300
301 SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); 301 SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
302 strcpy(SRVLIST_FILE, user_config_dir); 302 strcpy(SRVLIST_FILE, user_config_dir);
303 strcat(SRVLIST_FILE, CONFIGDIR); 303 strcat(SRVLIST_FILE, CONFIGDIR);
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 81f00bce..e194a90e 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -204,7 +204,7 @@ void cmd_connect(ToxWindow *self, Messenger *m, char **args)
204 204
205 dht.ip.i = resolved_address; 205 dht.ip.i = resolved_address;
206 unsigned char *binary_string = hex_string_to_bin(key); 206 unsigned char *binary_string = hex_string_to_bin(key);
207 DHT_bootstrap(dht, binary_string); 207 DHT_bootstrap(m->dht, dht, binary_string);
208 free(binary_string); 208 free(binary_string);
209} 209}
210 210
@@ -365,7 +365,9 @@ static void execute(ToxWindow *self, Messenger *m, char *u_cmd)
365 cmd[i] = '\0'; 365 cmd[i] = '\0';
366 366
367 int j = i; 367 int j = i;
368
368 while (++j < MAX_STR_SIZE && isspace(cmd[j])); 369 while (++j < MAX_STR_SIZE && isspace(cmd[j]));
370
369 i = j - 1; 371 i = j - 1;
370 372
371 numargs++; 373 numargs++;
@@ -460,7 +462,7 @@ static void prompt_onKey(ToxWindow *self, Messenger *m, int key)
460 } 462 }
461} 463}
462 464
463static void prompt_onDraw(ToxWindow *self) 465static void prompt_onDraw(ToxWindow *self, Messenger *m)
464{ 466{
465 curs_set(1); 467 curs_set(1);
466 int x, y; 468 int x, y;
diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c
index c0ff3026..8fdf4e19 100644
--- a/testing/toxic/windows.c
+++ b/testing/toxic/windows.c
@@ -88,23 +88,25 @@ int add_window(Messenger *m, ToxWindow w)
88{ 88{
89 if (LINES < 2) 89 if (LINES < 2)
90 return -1; 90 return -1;
91 91
92 int i; 92 int i;
93 for(i = 0; i < MAX_WINDOWS_NUM; i++) { 93
94 if (windows[i].window) 94 for (i = 0; i < MAX_WINDOWS_NUM; i++) {
95 if (windows[i].window)
95 continue; 96 continue;
96 97
97 w.window = newwin(LINES - 2, COLS, 0, 0); 98 w.window = newwin(LINES - 2, COLS, 0, 0);
99
98 if (w.window == NULL) 100 if (w.window == NULL)
99 return -1; 101 return -1;
100 102
101 windows[i] = w; 103 windows[i] = w;
102 w.onInit(&w, m); 104 w.onInit(&w, m);
103 105
104 active_window = windows+i; 106 active_window = windows + i;
105 return i; 107 return i;
106 } 108 }
107 109
108 return -1; 110 return -1;
109} 111}
110 112
@@ -113,8 +115,10 @@ void del_window(ToxWindow *w)
113{ 115{
114 active_window = windows; // Go to prompt screen 116 active_window = windows; // Go to prompt screen
115 delwin(w->window); 117 delwin(w->window);
118
116 if (w->x) 119 if (w->x)
117 free(w->x); 120 free(w->x);
121
118 w->window = NULL; 122 w->window = NULL;
119 memset(w, 0, sizeof(ToxWindow)); 123 memset(w, 0, sizeof(ToxWindow));
120 clear(); 124 clear();
@@ -124,19 +128,19 @@ void del_window(ToxWindow *w)
124/* Shows next window when tab or back-tab is pressed */ 128/* Shows next window when tab or back-tab is pressed */
125void set_next_window(int ch) 129void set_next_window(int ch)
126{ 130{
127 ToxWindow *end = windows+MAX_WINDOWS_NUM-1; 131 ToxWindow *end = windows + MAX_WINDOWS_NUM - 1;
128 ToxWindow *inf = active_window; 132 ToxWindow *inf = active_window;
129 while(true) { 133
134 while (true) {
130 if (ch == '\t') { 135 if (ch == '\t') {
131 if (++active_window > end) 136 if (++active_window > end)
132 active_window = windows; 137 active_window = windows;
133 } else 138 } else if (--active_window < windows)
134 if (--active_window < windows) 139 active_window = end;
135 active_window = end; 140
136
137 if (active_window->window) 141 if (active_window->window)
138 return; 142 return;
139 143
140 if (active_window == inf) { // infinite loop check 144 if (active_window == inf) { // infinite loop check
141 endwin(); 145 endwin();
142 exit(2); 146 exit(2);
@@ -148,14 +152,14 @@ void set_active_window(int index)
148{ 152{
149 if (index < 0 || index >= MAX_WINDOWS_NUM) 153 if (index < 0 || index >= MAX_WINDOWS_NUM)
150 return; 154 return;
151 155
152 active_window = windows+index; 156 active_window = windows + index;
153} 157}
154 158
155ToxWindow *init_windows() 159ToxWindow *init_windows()
156{ 160{
157 int n_prompt = add_window(m, new_prompt()); 161 int n_prompt = add_window(m, new_prompt());
158 162
159 if (n_prompt == -1 163 if (n_prompt == -1
160 || add_window(m, new_friendlist()) == -1 164 || add_window(m, new_friendlist()) == -1
161 || add_window(m, new_dhtstatus()) == -1) { 165 || add_window(m, new_dhtstatus()) == -1) {
@@ -166,7 +170,7 @@ ToxWindow *init_windows()
166 170
167 prompt = &windows[n_prompt]; 171 prompt = &windows[n_prompt];
168 active_window = prompt; 172 active_window = prompt;
169 173
170 return prompt; 174 return prompt;
171} 175}
172 176
@@ -189,7 +193,7 @@ static void draw_bar()
189 193
190 for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { 194 for (i = 0; i < (MAX_WINDOWS_NUM); ++i) {
191 if (windows[i].window) { 195 if (windows[i].window) {
192 if (windows+i == active_window) 196 if (windows + i == active_window)
193 attron(A_BOLD); 197 attron(A_BOLD);
194 198
195 odd = (odd + 1) % blinkrate; 199 odd = (odd + 1) % blinkrate;
@@ -197,13 +201,13 @@ static void draw_bar()
197 if (windows[i].blink && (odd < (blinkrate / 2))) 201 if (windows[i].blink && (odd < (blinkrate / 2)))
198 attron(COLOR_PAIR(3)); 202 attron(COLOR_PAIR(3));
199 203
200 clrtoeol(); 204 clrtoeol();
201 printw(" %s", windows[i].title); 205 printw(" %s", windows[i].title);
202 206
203 if (windows[i].blink && (odd < (blinkrate / 2))) 207 if (windows[i].blink && (odd < (blinkrate / 2)))
204 attroff(COLOR_PAIR(3)); 208 attroff(COLOR_PAIR(3));
205 209
206 if (windows+i == active_window) { 210 if (windows + i == active_window) {
207 attroff(A_BOLD); 211 attroff(A_BOLD);
208 } 212 }
209 } 213 }
@@ -225,7 +229,7 @@ void draw_active_window(Messenger *m)
225 prepare_window(a->window); 229 prepare_window(a->window);
226 a->blink = false; 230 a->blink = false;
227 draw_bar(); 231 draw_bar();
228 a->onDraw(a); 232 a->onDraw(a, m);
229 233
230 /* Handle input */ 234 /* Handle input */
231 int ch = getch(); 235 int ch = getch();
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h
index be5557e9..86917dbe 100644
--- a/testing/toxic/windows.h
+++ b/testing/toxic/windows.h
@@ -24,7 +24,7 @@ typedef struct ToxWindow_ ToxWindow;
24 24
25struct ToxWindow_ { 25struct ToxWindow_ {
26 void(*onKey)(ToxWindow *, Messenger *, int); 26 void(*onKey)(ToxWindow *, Messenger *, int);
27 void(*onDraw)(ToxWindow *); 27 void(*onDraw)(ToxWindow *, Messenger *);
28 void(*onInit)(ToxWindow *, Messenger *); 28 void(*onInit)(ToxWindow *, Messenger *);
29 void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t); 29 void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t);
30 void(*onMessage)(ToxWindow *, Messenger *, int, uint8_t *, uint16_t); 30 void(*onMessage)(ToxWindow *, Messenger *, int, uint8_t *, uint16_t);