summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/CMakeLists.txt2
-rw-r--r--testing/nTox_win32.c61
-rw-r--r--testing/nTox_win32.h7
-rw-r--r--testing/rect.py44
-rw-r--r--testing/toxic/dhtstatus.c4
5 files changed, 39 insertions, 79 deletions
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index 65ba35c0..9e07135c 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -12,7 +12,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake)
12include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/timer_test.cmake) 12include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/timer_test.cmake)
13 13
14if(WIN32) 14if(WIN32)
15 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) 15# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
16else() 16else()
17 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) 17 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
18 add_subdirectory(toxic) 18 add_subdirectory(toxic)
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index d2642df1..7739c0a6 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -39,6 +39,8 @@ char line[STRING_LENGTH];
39char users_id[200]; 39char users_id[200];
40int friend_request_received; 40int friend_request_received;
41 41
42Messenger *messenger;
43
42void do_header() 44void do_header()
43{ 45{
44 system("cls"); 46 system("cls");
@@ -48,7 +50,7 @@ void do_header()
48 printf("\n---------------------------------"); 50 printf("\n---------------------------------");
49} 51}
50 52
51void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) 53void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
52{ 54{
53 friend_request_received = 1; 55 friend_request_received = 1;
54 printf("\n\n[i] received friend request with message\n"); 56 printf("\n\n[i] received friend request with message\n");
@@ -61,10 +63,10 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
61 ++num_requests; 63 ++num_requests;
62} 64}
63 65
64void print_message(int friendnumber, uint8_t * string, uint16_t length) 66void print_message(Messenger *messenger, int friendnumber, uint8_t * string, uint16_t length, void *userdata)
65{ 67{
66 char name[MAX_NAME_LENGTH]; 68 char name[MAX_NAME_LENGTH];
67 getname(friendnumber, (uint8_t*)name); 69 getname(messenger, friendnumber, (uint8_t*)name);
68 char msg[100+length+strlen(name)+1]; 70 char msg[100+length+strlen(name)+1];
69 time_t rawtime; 71 time_t rawtime;
70 struct tm * timeinfo; 72 struct tm * timeinfo;
@@ -77,19 +79,19 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
77 printf(msg); 79 printf(msg);
78} 80}
79 81
80void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) 82void print_nickchange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
81{ 83{
82 char name[MAX_NAME_LENGTH]; 84 char name[MAX_NAME_LENGTH];
83 getname(friendnumber, (uint8_t*)name); 85 getname(messenger, friendnumber, (uint8_t*)name);
84 char msg[100+length]; 86 char msg[100+length];
85 sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); 87 sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
86 printf(msg); 88 printf(msg);
87} 89}
88 90
89void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) 91void print_statuschange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
90{ 92{
91 char name[MAX_NAME_LENGTH]; 93 char name[MAX_NAME_LENGTH];
92 getname(friendnumber, (uint8_t*)name); 94 getname(messenger, friendnumber, (uint8_t*)name);
93 char msg[100+length+strlen(name)+1]; 95 char msg[100+length+strlen(name)+1];
94 sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string); 96 sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
95 printf(msg); 97 printf(msg);
@@ -109,11 +111,11 @@ void load_key()
109 exit(1); 111 exit(1);
110 } 112 }
111 113
112 Messenger_load(data, size); 114 Messenger_load(messenger, data, size);
113 } else { 115 } else {
114 int size = Messenger_size(); 116 int size = Messenger_size(messenger);
115 uint8_t data[size]; 117 uint8_t data[size];
116 Messenger_save(data); 118 Messenger_save(messenger, data);
117 fclose(data_file); 119 fclose(data_file);
118 data_file = fopen("data", "w"); 120 data_file = fopen("data", "w");
119 121
@@ -133,7 +135,7 @@ void add_friend()
133 for (i = 0; i < 128; i++) 135 for (i = 0; i < 128; i++)
134 temp_id[i] = line[i+3]; 136 temp_id[i] = line[i+3];
135 137
136 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 138 int num = m_addfriend(messenger, hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
137 139
138 if (num >= 0) { 140 if (num >= 0) {
139 char numstring[100]; 141 char numstring[100];
@@ -167,8 +169,8 @@ void list_friends()
167 169
168 for (i = 0; i <= maxnumfriends; i++) { 170 for (i = 0; i <= maxnumfriends; i++) {
169 char name[MAX_NAME_LENGTH]; 171 char name[MAX_NAME_LENGTH];
170 getname(i, (uint8_t*)name); 172 getname(messenger, i, (uint8_t*)name);
171 if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4) 173 if (m_friendstatus(messenger, i) > 0 && m_friendstatus(messenger, i) < 4)
172 printf("[%d] %s\n", i, (uint8_t*)name); 174 printf("[%d] %s\n", i, (uint8_t*)name);
173 } 175 }
174 176
@@ -178,9 +180,9 @@ void list_friends()
178 180
179 for (i = 0; i <= maxnumfriends; i++) { 181 for (i = 0; i <= maxnumfriends; i++) {
180 char name[MAX_NAME_LENGTH]; 182 char name[MAX_NAME_LENGTH];
181 getname(i, (uint8_t*)name); 183 getname(messenger, i, (uint8_t*)name);
182 184
183 if (m_friendstatus(i) == 4) 185 if (m_friendstatus(messenger, i) == 4)
184 printf("[%d] %s\n", i, (uint8_t*)name); 186 printf("[%d] %s\n", i, (uint8_t*)name);
185 } 187 }
186 188
@@ -199,7 +201,7 @@ void delete_friend()
199 } 201 }
200 202
201 int num = atoi(numstring); 203 int num = atoi(numstring);
202 m_delfriend(num); 204 m_delfriend(messenger, num);
203 --maxnumfriends; 205 --maxnumfriends;
204 printf("\n\n"); 206 printf("\n\n");
205} 207}
@@ -228,7 +230,7 @@ void message_friend()
228 230
229 int num = atoi(numstring); 231 int num = atoi(numstring);
230 232
231 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) 233 if(m_sendmessage(messenger, num, (uint8_t*) message, sizeof(message)) != 1)
232 printf("\n[i] could not send message (they may be offline): %s\n", message); 234 printf("\n[i] could not send message (they may be offline): %s\n", message);
233 235
234 else 236 else
@@ -250,7 +252,7 @@ void change_nickname()
250 } 252 }
251 253
252 name[i-3] = 0; 254 name[i-3] = 0;
253 setname(name, i); 255 setname(messenger, name, i);
254 char numstring[100]; 256 char numstring[100];
255 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); 257 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
256 printf(numstring); 258 printf(numstring);
@@ -275,7 +277,7 @@ void change_status(int savetofile)
275 } 277 }
276 278
277 status[i-3] = 0; 279 status[i-3] = 0;
278 m_set_statusmessage(status, strlen((char*)status)); 280 m_set_statusmessage(messenger, status, strlen((char*)status));
279 char numstring[100]; 281 char numstring[100];
280 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); 282 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
281 printf(numstring); 283 printf(numstring);
@@ -297,7 +299,7 @@ void accept_friend_request()
297 sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it"); 299 sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it");
298 printf(numchar); 300 printf(numchar);
299 } else { 301 } else {
300 int num = m_addfriend_norequest(pending_requests[numf].id); 302 int num = m_addfriend_norequest(messenger, pending_requests[numf].id);
301 if (num != -1) { 303 if (num != -1) {
302 pending_requests[numf].accepted = 1; 304 pending_requests[numf].accepted = 1;
303 sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); 305 sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num);
@@ -347,7 +349,7 @@ void line_eval(char* line)
347 349
348 else if (inpt_command == 'a') { 350 else if (inpt_command == 'a') {
349 if (friend_request_received == 1) 351 if (friend_request_received == 1)
350 accept_friend_request(line); 352 accept_friend_request();
351 } 353 }
352 /* EXIT */ 354 /* EXIT */
353 else if (inpt_command == 'q') { 355 else if (inpt_command == 'q') {
@@ -373,7 +375,8 @@ int main(int argc, char *argv[])
373 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); 375 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
374 exit(0); 376 exit(0);
375 } 377 }
376 if (initMessenger() == -1) { 378 messenger = initMessenger();
379 if (messenger == 0) {
377 printf("initMessenger failed"); 380 printf("initMessenger failed");
378 exit(0); 381 exit(0);
379 } 382 }
@@ -394,7 +397,7 @@ int main(int argc, char *argv[])
394 while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) { 397 while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
395 sscanf(line, "%s", (char*)name); 398 sscanf(line, "%s", (char*)name);
396 } 399 }
397 setname(name, strlen((char*)name)+1); 400 setname(messenger, name, strlen((char*)name)+1);
398 nameloaded = 1; 401 nameloaded = 1;
399 printf("%s\n", name); 402 printf("%s\n", name);
400 fclose(name_file); 403 fclose(name_file);
@@ -407,16 +410,16 @@ int main(int argc, char *argv[])
407 while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) { 410 while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) {
408 sscanf(line, "%s", (char*)status); 411 sscanf(line, "%s", (char*)status);
409 } 412 }
410 m_set_statusmessage(status, strlen((char*)status)+1); 413 m_set_statusmessage(messenger, status, strlen((char*)status)+1);
411 statusloaded = 1; 414 statusloaded = 1;
412 printf("%s\n", status); 415 printf("%s\n", status);
413 fclose(status_file); 416 fclose(status_file);
414 } 417 }
415 418
416 m_callback_friendrequest(print_request); 419 m_callback_friendrequest(messenger, print_request, &status_file);
417 m_callback_friendmessage(print_message); 420 m_callback_friendmessage(messenger, print_message, &status_file);
418 m_callback_namechange(print_nickchange); 421 m_callback_namechange(messenger, print_nickchange, &status_file);
419 m_callback_statusmessage(print_statuschange); 422 m_callback_statusmessage(messenger, print_statuschange, &status_file);
420 char idstring1[PUB_KEY_BYTES][5]; 423 char idstring1[PUB_KEY_BYTES][5];
421 char idstring2[PUB_KEY_BYTES][5]; 424 char idstring2[PUB_KEY_BYTES][5];
422 int i; 425 int i;
@@ -474,7 +477,7 @@ int main(int argc, char *argv[])
474 printf("\n---------------------------------\n\n"); 477 printf("\n---------------------------------\n\n");
475 on = 1; 478 on = 1;
476 } 479 }
477 doMessenger(); 480 doMessenger(messenger);
478 Sleep(1); 481 Sleep(1);
479 } 482 }
480 return 0; 483 return 0;
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h
index 03641a5d..5dfe81c3 100644
--- a/testing/nTox_win32.h
+++ b/testing/nTox_win32.h
@@ -30,9 +30,10 @@
30#define PUB_KEY_BYTES 32 30#define PUB_KEY_BYTES 32
31 31
32void do_header(); 32void do_header();
33void print_message(int friendnumber, uint8_t * string, uint16_t length); 33void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata);
34void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); 34void print_message(Messenger *messenger, int friendnumber, uint8_t * string, uint16_t length, void *userdata);
35void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); 35void print_nickchange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
36void print_statuschange(Messenger *messenger, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
36void load_key(); 37void load_key();
37void add_friend(); 38void add_friend();
38void list_friends(); 39void list_friends();
diff --git a/testing/rect.py b/testing/rect.py
deleted file mode 100644
index 05f0abc4..00000000
--- a/testing/rect.py
+++ /dev/null
@@ -1,44 +0,0 @@
1#basic python UDP script
2#for testing only
3import socket
4import random
5
6UDP_IP = "127.0.0.1"
7UDP_PORT = 5004
8
9sock = socket.socket(socket.AF_INET, # Internet
10 socket.SOCK_DGRAM) # UDP
11sock.bind((UDP_IP, UDP_PORT))
12
13#our client_id
14client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32)))
15
16print client_id
17a = 1;
18#send ping request to our DHT on localhost.
19sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445))
20
21#print all packets received and respond to ping requests properly
22while True:
23 data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
24 print "received message:", data.encode('hex'), " From:", addr
25 #if we receive a ping request.
26 print data[0].encode('hex')
27 if data[0] == "00".decode('hex'):
28 print "Sending ping resp"
29 sock.sendto("01".decode('hex') + data[1:5] + client_id, addr)
30
31 #if we receive a get_nodes request.
32 if data[0] == "02".decode('hex'):
33 print "Sending getn resp"
34 #send send nodes packet with a couple 127.0.0.1 ips and ports.
35 #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002
36 sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr)
37
38 if data[0] == "10".decode('hex'):
39 print "Sending handshake resp"
40 sock.sendto("10".decode('hex') + data[1:5] + client_id[:4], addr)
41 if data[0] == "11".decode('hex'):
42 print "Sending SYNC resp"
43 a+=1
44 sock.sendto("11".decode('hex') + chr(a) + data[1:9], addr)
diff --git a/testing/toxic/dhtstatus.c b/testing/toxic/dhtstatus.c
index 66268900..e026a173 100644
--- a/testing/toxic/dhtstatus.c
+++ b/testing/toxic/dhtstatus.c
@@ -43,13 +43,13 @@ static void dhtstatus_onDraw(ToxWindow *self)
43 uint32_t i, j; 43 uint32_t i, j;
44 ipbuf ipbuf; 44 ipbuf ipbuf;
45 wprintw(self->window,"\n%llu ______________________ CLOSE LIST ________________________ ___ IP ADDR ___ _PRT_ LST PNG ____ SELF ____ _PRT_ LST\n\n", now); 45 wprintw(self->window,"\n%llu ______________________ CLOSE LIST ________________________ ___ IP ADDR ___ _PRT_ LST PNG ____ SELF ____ _PRT_ LST\n\n", now);
46 for(i = 0; i < CLIENT_ID_SIZE; i++) { 46 for(i = 0; i < 32; i++) { /*Number of nodes in closelist*/
47 Client_data * client = close_clientlist + i; 47 Client_data * client = close_clientlist + i;
48 if (i == num_selected) wattron(self->window, COLOR_PAIR(3)); 48 if (i == num_selected) wattron(self->window, COLOR_PAIR(3));
49 wprintw(self->window,"[%02i] ", i); 49 wprintw(self->window,"[%02i] ", i);
50 uint16_t port = ntohs(client->ip_port.port); 50 uint16_t port = ntohs(client->ip_port.port);
51 if(port) { 51 if(port) {
52 for(j = 0; j < 32; j++) 52 for(j = 0; j < CLIENT_ID_SIZE; j++)
53 wprintw(self->window, "%02hhx", client->client_id[j]); 53 wprintw(self->window, "%02hhx", client->client_id[j]);
54 54
55 printip(ipbuf, client->ip_port.ip); 55 printip(ipbuf, client->ip_port.ip);