summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL.md10
-rw-r--r--core/DHT.c23
-rw-r--r--core/Messenger.c11
-rw-r--r--core/Messenger.h2
-rw-r--r--other/DHTservers3
-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
10 files changed, 79 insertions, 88 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 1ee1c66f..3d01d562 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -23,7 +23,7 @@ On Fedora:
23 23
24```bash 24```bash
25yum groupinstall "Development Tools" 25yum groupinstall "Development Tools"
26yum install libtool autoconf automake libconfig-devel ncurses-devel cmake check 26yum install libtool autoconf automake libconfig-devel ncurses-devel cmake check check-devel
27``` 27```
28 28
29Note that `libconfig-dev` should be >= 1.4. 29Note that `libconfig-dev` should be >= 1.4.
@@ -61,8 +61,8 @@ mkdir build && cd build
61cmake .. 61cmake ..
62``` 62```
63Advance cmake options: 63Advance cmake options:
64 - `-DSHARED_TOXCORE=ON` (default `OFF`) Build Core as a shared library. 64 - `-DSHARED_TOXCORE=ON` (default `OFF`) � Build Core as a shared library.
65 - `-DUSE_NACL=ON` (default `OFF`) Use NaCl library instead of libsodium. 65 - `-DUSE_NACL=ON` (default `OFF`) � Use NaCl library instead of libsodium.
66 66
67Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. 67Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
68 68
@@ -150,8 +150,8 @@ mkdir build && cd build
150cmake -G "MinGW Makefiles" .. 150cmake -G "MinGW Makefiles" ..
151``` 151```
152Advance cmake options: 152Advance cmake options:
153 - `-DSHARED_TOXCORE=ON` (default OFF) Build Core as a shared library. 153 - `-DSHARED_TOXCORE=ON` (default OFF) � Build Core as a shared library.
154 - `-DSHARED_LIBSODIUM=ON` (default OFF) Link libsodium as a shared library. 154 - `-DSHARED_LIBSODIUM=ON` (default OFF) � Link libsodium as a shared library.
155 155
156Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. 156Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
157 157
diff --git a/core/DHT.c b/core/DHT.c
index 1d13aa73..bcaaf6d8 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -319,6 +319,28 @@ static int replace_bad( Client_data * list,
319 319
320 return 1; 320 return 1;
321} 321}
322/*Sort the list. It will be sorted from furthest to closest.
323 TODO: this is innefficient and needs to be optimized.*/
324static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_id)
325{
326 if(length == 0)
327 return;
328 uint32_t i, count;
329 while(1) {
330 count = 0;
331 for(i = 0; i < (length - 1); ++i) {
332 if(id_closest(comp_client_id, list[i].client_id, list[i + 1].client_id) == 1) {
333 Client_data temp = list[i + 1];
334 list[i + 1] = list[i];
335 list[i] = temp;
336 ++count;
337 }
338 }
339 if(count == 0)
340 return;
341 }
342}
343
322 344
323/* replace the first good node that is further to the comp_client_id than that of the client_id in the list */ 345/* replace the first good node that is further to the comp_client_id than that of the client_id in the list */
324static int replace_good( Client_data * list, 346static int replace_good( Client_data * list,
@@ -329,6 +351,7 @@ static int replace_good( Client_data * list,
329{ 351{
330 uint32_t i; 352 uint32_t i;
331 uint64_t temp_time = unix_time(); 353 uint64_t temp_time = unix_time();
354 sort_list(list, length, comp_client_id);
332 355
333 for(i = 0; i < length; ++i) 356 for(i = 0; i < length; ++i)
334 if(id_closest(comp_client_id, list[i].client_id, client_id) == 2) { 357 if(id_closest(comp_client_id, list[i].client_id, client_id) == 2) {
diff --git a/core/Messenger.c b/core/Messenger.c
index 690a81b1..bed59d4d 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -120,6 +120,7 @@ void getaddress(Messenger *m, uint8_t *address)
120 * return FAERR_BADCHECKSUM if bad checksum in address 120 * return FAERR_BADCHECKSUM if bad checksum in address
121 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different 121 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different
122 * (the nospam for that friend was set to the new one) 122 * (the nospam for that friend was set to the new one)
123 * return FAERR_NOMEM if increasing the friend list size fails
123 */ 124 */
124int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) 125int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
125{ 126{
@@ -148,7 +149,8 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
148 } 149 }
149 150
150 /* resize the friend list if necessary */ 151 /* resize the friend list if necessary */
151 realloc_friendlist(m, m->numfriends + 1); 152 if (realloc_friendlist(m, m->numfriends + 1) != 0)
153 return FAERR_NOMEM;
152 154
153 uint32_t i; 155 uint32_t i;
154 for (i = 0; i <= m->numfriends; ++i) { 156 for (i = 0; i <= m->numfriends; ++i) {
@@ -180,7 +182,8 @@ int m_addfriend_norequest(Messenger *m, uint8_t * client_id)
180 return -1; 182 return -1;
181 183
182 /* resize the friend list if necessary */ 184 /* resize the friend list if necessary */
183 realloc_friendlist(m, m->numfriends + 1); 185 if (realloc_friendlist(m, m->numfriends + 1) != 0)
186 return FAERR_NOMEM;
184 187
185 uint32_t i; 188 uint32_t i;
186 for (i = 0; i <= m->numfriends; ++i) { 189 for (i = 0; i <= m->numfriends; ++i) {
@@ -221,7 +224,9 @@ int m_delfriend(Messenger *m, int friendnumber)
221 break; 224 break;
222 } 225 }
223 m->numfriends = i; 226 m->numfriends = i;
224 realloc_friendlist(m, m->numfriends + 1); 227
228 if (realloc_friendlist(m, m->numfriends + 1) != 0)
229 return FAERR_NOMEM;
225 230
226 return 0; 231 return 0;
227} 232}
diff --git a/core/Messenger.h b/core/Messenger.h
index a2add19d..e12b3fc8 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -63,6 +63,7 @@ extern "C" {
63#define FAERR_UNKNOWN -5 63#define FAERR_UNKNOWN -5
64#define FAERR_BADCHECKSUM -6 64#define FAERR_BADCHECKSUM -6
65#define FAERR_SETNEWNOSPAM -7 65#define FAERR_SETNEWNOSPAM -7
66#define FAERR_NOMEM -8
66 67
67/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased 68/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
68 to an absurdly large number later */ 69 to an absurdly large number later */
@@ -151,6 +152,7 @@ void getaddress(Messenger *m, uint8_t *address);
151 * return -6 if bad checksum in address 152 * return -6 if bad checksum in address
152 * return -7 if the friend was already there but the nospam was different 153 * return -7 if the friend was already there but the nospam was different
153 * (the nospam for that friend was set to the new one) 154 * (the nospam for that friend was set to the new one)
155 * return -8 if increasing the friend list size fails
154 */ 156 */
155int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length); 157int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
156 158
diff --git a/other/DHTservers b/other/DHTservers
index 560c29b5..6efba882 100644
--- a/other/DHTservers
+++ b/other/DHTservers
@@ -3,4 +3,5 @@
3192.184.81.118 33445 5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143 3192.184.81.118 33445 5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143
4192.210.149.121 33445 F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67 4192.210.149.121 33445 F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
581.224.34.47 443 48F0D94C0D54EB1995A2ECEDE7DB6BDD5E05D81704B2F3D1BB9FE43AC97B7269 581.224.34.47 443 48F0D94C0D54EB1995A2ECEDE7DB6BDD5E05D81704B2F3D1BB9FE43AC97B7269
6198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854 \ No newline at end of file 6198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854
795.47.140.214 33445 F4BF7C5A9D0EF4CB684090C38DE937FAE1612021F21FEA4DCBFAC6AAFEF58E68
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);