diff options
-rwxr-xr-x | CMakeLists.txt | 36 | ||||
-rw-r--r-- | INSTALL.md | 8 | ||||
-rw-r--r-- | cmake/FindSODIUM.cmake | 10 | ||||
-rw-r--r-- | core/CMakeLists.txt | 19 | ||||
-rw-r--r-- | core/DHT.c | 56 | ||||
-rw-r--r-- | core/DHT.h | 4 | ||||
-rw-r--r-- | core/LAN_discovery.c | 8 | ||||
-rw-r--r-- | core/Lossless_UDP.c | 44 | ||||
-rw-r--r-- | core/Lossless_UDP.h | 4 | ||||
-rw-r--r-- | core/Messenger.c | 12 | ||||
-rw-r--r-- | core/Messenger.h | 6 | ||||
-rw-r--r-- | core/net_crypto.c | 22 | ||||
-rw-r--r-- | core/net_crypto.h | 6 | ||||
-rw-r--r-- | core/network.c | 6 | ||||
-rw-r--r-- | core/network.h | 6 | ||||
-rw-r--r-- | testing/CMakeLists.txt | 5 | ||||
-rw-r--r-- | testing/misc_tools.c | 1 | ||||
-rw-r--r-- | testing/nTox.c | 62 | ||||
-rw-r--r-- | testing/toxic/chat.c | 97 | ||||
-rw-r--r-- | testing/toxic/main.c | 12 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 19 |
21 files changed, 274 insertions, 169 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 07098391..f56cd67a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 2.6.0) | |||
2 | 2 | ||
3 | set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | 3 | set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
4 | 4 | ||
5 | if(UNIX) | 5 | option(SHARED_TOXCORE "Build Core as a shared library") |
6 | find_package(Curses REQUIRED) | ||
7 | endif() | ||
8 | 6 | ||
9 | if(NOT WIN32) | 7 | if(WIN32) |
8 | option(SHARED_LIBSODIUM "Links libsodium as a shared library") | ||
9 | else() | ||
10 | option(USE_NACL "Use NaCl library instead of libsodium") | 10 | option(USE_NACL "Use NaCl library instead of libsodium") |
11 | endif() | 11 | endif() |
12 | 12 | ||
13 | if(UNIX) | ||
14 | find_package(Curses REQUIRED) | ||
15 | endif() | ||
16 | |||
13 | if(USE_NACL) | 17 | if(USE_NACL) |
14 | find_package(NaCl REQUIRED) | 18 | find_package(NaCl REQUIRED) |
15 | 19 | ||
@@ -17,6 +21,12 @@ if(USE_NACL) | |||
17 | add_definitions(-DVANILLA_NACL) | 21 | add_definitions(-DVANILLA_NACL) |
18 | 22 | ||
19 | set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES}) | 23 | set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES}) |
24 | else() | ||
25 | find_package(SODIUM REQUIRED) | ||
26 | |||
27 | include_directories(${SODIUM_INCLUDE_DIR}) | ||
28 | |||
29 | set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY}) | ||
20 | endif() | 30 | endif() |
21 | 31 | ||
22 | #MinGW prints more warnings for -Wall than gcc does, thus causing build to fail | 32 | #MinGW prints more warnings for -Wall than gcc does, thus causing build to fail |
@@ -25,25 +35,15 @@ if(NOT WIN32) | |||
25 | message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====") | 35 | message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====") |
26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") | 36 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") |
27 | endif() | 37 | endif() |
28 | find_package(SODIUM REQUIRED) | ||
29 | endif() | ||
30 | |||
31 | if(NOT USE_NACL) | ||
32 | set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY}) | ||
33 | endif() | 38 | endif() |
34 | 39 | ||
35 | macro(linkCoreLibraries exe_name) | 40 | macro(linkCoreLibraries exe_name) |
36 | add_dependencies(${exe_name} toxcore) | 41 | add_dependencies(${exe_name} toxcore) |
37 | if(WIN32) | 42 | target_link_libraries(${exe_name} toxcore |
38 | include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) | 43 | ${LINK_CRYPTO_LIBRARY}) |
39 | target_link_libraries(${exe_name} toxcore | ||
40 | ${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a | ||
41 | ws2_32) | ||
42 | else() | ||
43 | include_directories(${SODIUM_INCLUDE_DIR}) | ||
44 | target_link_libraries(${exe_name} toxcore | ||
45 | ${LINK_CRYPTO_LIBRARY}) | ||
46 | 44 | ||
45 | if(WIN32) | ||
46 | target_link_libraries(${exe_name} ws2_32) | ||
47 | endif() | 47 | endif() |
48 | endmacro() | 48 | endmacro() |
49 | 49 | ||
@@ -60,6 +60,10 @@ cd ProjectTox-Core | |||
60 | mkdir build && cd build | 60 | mkdir build && cd build |
61 | cmake .. | 61 | cmake .. |
62 | ``` | 62 | ``` |
63 | Advance cmake options: | ||
64 | - `-DSHARED_TOXCORE=ON` (default `OFF`) — Build Core as a shared library. | ||
65 | - `-DUSE_NACL=ON` (default `OFF`) — Use NaCl library instead of libsodium. | ||
66 | |||
63 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. | 67 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. |
64 | 68 | ||
65 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: | 69 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: |
@@ -143,6 +147,10 @@ Navigate in `cmd` to this repo and run: | |||
143 | mkdir build && cd build | 147 | mkdir build && cd build |
144 | cmake -G "MinGW Makefiles" .. | 148 | cmake -G "MinGW Makefiles" .. |
145 | ``` | 149 | ``` |
150 | Advance cmake options: | ||
151 | - `-DSHARED_TOXCORE=ON` (default OFF) — Build Core as a shared library. | ||
152 | - `-DSHARED_LIBSODIUM=ON` (default OFF) — Link libsodium as a shared library. | ||
153 | |||
146 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. | 154 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. |
147 | 155 | ||
148 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: | 156 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: |
diff --git a/cmake/FindSODIUM.cmake b/cmake/FindSODIUM.cmake index fd6206ff..2db0f667 100644 --- a/cmake/FindSODIUM.cmake +++ b/cmake/FindSODIUM.cmake | |||
@@ -26,11 +26,12 @@ set(_SODIUM_ROOT_HINTS | |||
26 | 26 | ||
27 | set(_SODIUM_ROOT_PATHS | 27 | set(_SODIUM_ROOT_PATHS |
28 | "$ENV{PROGRAMFILES}/sodium" | 28 | "$ENV{PROGRAMFILES}/sodium" |
29 | "${CMAKE_SOURCE_DIR}/sodium" | ||
29 | ) | 30 | ) |
30 | 31 | ||
31 | find_path(SODIUM_ROOT_DIR | 32 | find_path(SODIUM_ROOT_DIR |
32 | NAMES | 33 | NAMES |
33 | include/cmocka.h | 34 | include/sodium.h |
34 | HINTS | 35 | HINTS |
35 | ${_SODIUM_ROOT_HINTS} | 36 | ${_SODIUM_ROOT_HINTS} |
36 | PATHS | 37 | PATHS |
@@ -45,8 +46,15 @@ find_path(SODIUM_INCLUDE_DIR | |||
45 | ${SODIUM_ROOT_DIR}/include | 46 | ${SODIUM_ROOT_DIR}/include |
46 | ) | 47 | ) |
47 | 48 | ||
49 | if(SHARED_LIBSODIUM) | ||
50 | set(WIN32_LIBSODIUM_FILENAME libsodium.dll.a) | ||
51 | else() | ||
52 | set(WIN32_LIBSODIUM_FILENAME libsodium.a) | ||
53 | endif() | ||
54 | |||
48 | find_library(SODIUM_LIBRARY | 55 | find_library(SODIUM_LIBRARY |
49 | NAMES | 56 | NAMES |
57 | ${WIN32_LIBSODIUM_FILENAME} | ||
50 | sodium | 58 | sodium |
51 | PATHS | 59 | PATHS |
52 | ${SODIUM_ROOT_DIR}/lib | 60 | ${SODIUM_ROOT_DIR}/lib |
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 5bd496cb..eacb772c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt | |||
@@ -1,12 +1,6 @@ | |||
1 | cmake_minimum_required(VERSION 2.6.0) | 1 | cmake_minimum_required(VERSION 2.6.0) |
2 | project(toxcore C) | 2 | project(toxcore C) |
3 | 3 | ||
4 | if(WIN32) | ||
5 | include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) | ||
6 | else(WIN32) | ||
7 | include_directories(${SODIUM_INCLUDE_DIR}) | ||
8 | endif() | ||
9 | |||
10 | set(core_sources | 4 | set(core_sources |
11 | DHT.c | 5 | DHT.c |
12 | network.c | 6 | network.c |
@@ -16,5 +10,14 @@ set(core_sources | |||
16 | LAN_discovery.c | 10 | LAN_discovery.c |
17 | Messenger.c) | 11 | Messenger.c) |
18 | 12 | ||
19 | add_library(toxcore SHARED ${core_sources}) | 13 | if(SHARED_TOXCORE) |
20 | target_link_libraries(toxcore ${SODIUM_LIBRARY}) | 14 | add_library(toxcore SHARED ${core_sources}) |
15 | else() | ||
16 | add_library(toxcore ${core_sources}) | ||
17 | endif() | ||
18 | |||
19 | target_link_libraries(toxcore ${LINK_CRYPTO_LIBRARY}) | ||
20 | |||
21 | if(WIN32) | ||
22 | target_link_libraries(toxcore ws2_32) | ||
23 | endif() | ||
@@ -119,7 +119,7 @@ static Pinged send_nodes[LSEND_NODES_ARRAY]; | |||
119 | * return 1 if client_id1 is closer | 119 | * return 1 if client_id1 is closer |
120 | * return 2 if client_id2 is closer | 120 | * return 2 if client_id2 is closer |
121 | */ | 121 | */ |
122 | int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) | 122 | static int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) |
123 | { | 123 | { |
124 | size_t i; | 124 | size_t i; |
125 | uint8_t distance1, distance2; | 125 | uint8_t distance1, distance2; |
@@ -137,17 +137,17 @@ int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) | |||
137 | return 0; | 137 | return 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | int ipport_equal(IP_Port a, IP_Port b) | 140 | static int ipport_equal(IP_Port a, IP_Port b) |
141 | { | 141 | { |
142 | return (a.ip.i == b.ip.i) && (a.port == b.port); | 142 | return (a.ip.i == b.ip.i) && (a.port == b.port); |
143 | } | 143 | } |
144 | 144 | ||
145 | int id_equal(uint8_t* a, uint8_t* b) | 145 | static int id_equal(uint8_t* a, uint8_t* b) |
146 | { | 146 | { |
147 | return memcmp(a, b, CLIENT_ID_SIZE) == 0; | 147 | return memcmp(a, b, CLIENT_ID_SIZE) == 0; |
148 | } | 148 | } |
149 | 149 | ||
150 | int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) | 150 | static int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) |
151 | { | 151 | { |
152 | return timestamp + timeout <= time_now; | 152 | return timestamp + timeout <= time_now; |
153 | } | 153 | } |
@@ -159,7 +159,7 @@ int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) | |||
159 | * | 159 | * |
160 | * TODO: maybe optimize this. | 160 | * TODO: maybe optimize this. |
161 | */ | 161 | */ |
162 | int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port) | 162 | static int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port) |
163 | { | 163 | { |
164 | uint32_t i; | 164 | uint32_t i; |
165 | uint64_t temp_time = unix_time(); | 165 | uint64_t temp_time = unix_time(); |
@@ -184,7 +184,7 @@ int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_ | |||
184 | /* check if client with client_id is already in node format list of length length. | 184 | /* check if client with client_id is already in node format list of length length. |
185 | * return True(1) or False(0) | 185 | * return True(1) or False(0) |
186 | */ | 186 | */ |
187 | int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) | 187 | static int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) |
188 | { | 188 | { |
189 | uint32_t i; | 189 | uint32_t i; |
190 | 190 | ||
@@ -215,7 +215,7 @@ static int friend_number(uint8_t * client_id) | |||
215 | * | 215 | * |
216 | * TODO: For the love of based Allah make this function cleaner and much more efficient. | 216 | * TODO: For the love of based Allah make this function cleaner and much more efficient. |
217 | */ | 217 | */ |
218 | int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) | 218 | static int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) |
219 | { | 219 | { |
220 | uint32_t i, j, k; | 220 | uint32_t i, j, k; |
221 | uint64_t temp_time = unix_time(); | 221 | uint64_t temp_time = unix_time(); |
@@ -301,7 +301,7 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) | |||
301 | * return 0 if successful | 301 | * return 0 if successful |
302 | * return 1 if not (list contains no bad nodes) | 302 | * return 1 if not (list contains no bad nodes) |
303 | */ | 303 | */ |
304 | int replace_bad( Client_data * list, | 304 | static int replace_bad( Client_data * list, |
305 | uint32_t length, | 305 | uint32_t length, |
306 | uint8_t * client_id, | 306 | uint8_t * client_id, |
307 | IP_Port ip_port ) | 307 | IP_Port ip_port ) |
@@ -325,7 +325,7 @@ int replace_bad( Client_data * list, | |||
325 | } | 325 | } |
326 | 326 | ||
327 | /* replace the first good node that is further to the comp_client_id than that of the client_id in the list */ | 327 | /* replace the first good node that is further to the comp_client_id than that of the client_id in the list */ |
328 | int replace_good( Client_data * list, | 328 | static int replace_good( Client_data * list, |
329 | uint32_t length, | 329 | uint32_t length, |
330 | uint8_t * client_id, | 330 | uint8_t * client_id, |
331 | IP_Port ip_port, | 331 | IP_Port ip_port, |
@@ -351,7 +351,7 @@ int replace_good( Client_data * list, | |||
351 | /* Attempt to add client with ip_port and client_id to the friends client list | 351 | /* Attempt to add client with ip_port and client_id to the friends client list |
352 | * and close_clientlist | 352 | * and close_clientlist |
353 | */ | 353 | */ |
354 | void addto_lists(IP_Port ip_port, uint8_t * client_id) | 354 | static void addto_lists(IP_Port ip_port, uint8_t * client_id) |
355 | { | 355 | { |
356 | uint32_t i; | 356 | uint32_t i; |
357 | 357 | ||
@@ -393,7 +393,7 @@ void addto_lists(IP_Port ip_port, uint8_t * client_id) | |||
393 | /* If client_id is a friend or us, update ret_ip_port | 393 | /* If client_id is a friend or us, update ret_ip_port |
394 | * nodeclient_id is the id of the node that sent us this info | 394 | * nodeclient_id is the id of the node that sent us this info |
395 | */ | 395 | */ |
396 | void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id) | 396 | static void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id) |
397 | { | 397 | { |
398 | uint32_t i, j; | 398 | uint32_t i, j; |
399 | uint64_t temp_time = unix_time(); | 399 | uint64_t temp_time = unix_time(); |
@@ -431,7 +431,7 @@ void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient | |||
431 | * | 431 | * |
432 | * TODO: optimize this | 432 | * TODO: optimize this |
433 | */ | 433 | */ |
434 | int is_pinging(IP_Port ip_port, uint64_t ping_id) | 434 | static int is_pinging(IP_Port ip_port, uint64_t ping_id) |
435 | { | 435 | { |
436 | uint32_t i; | 436 | uint32_t i; |
437 | uint8_t pinging; | 437 | uint8_t pinging; |
@@ -456,7 +456,7 @@ int is_pinging(IP_Port ip_port, uint64_t ping_id) | |||
456 | } | 456 | } |
457 | 457 | ||
458 | /* Same as last function but for get_node requests. */ | 458 | /* Same as last function but for get_node requests. */ |
459 | int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) | 459 | static int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) |
460 | { | 460 | { |
461 | uint32_t i; | 461 | uint32_t i; |
462 | uint8_t pinging; | 462 | uint8_t pinging; |
@@ -486,7 +486,7 @@ int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) | |||
486 | * | 486 | * |
487 | * TODO: optimize this | 487 | * TODO: optimize this |
488 | */ | 488 | */ |
489 | uint64_t add_pinging(IP_Port ip_port) | 489 | static uint64_t add_pinging(IP_Port ip_port) |
490 | { | 490 | { |
491 | uint32_t i, j; | 491 | uint32_t i, j; |
492 | uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); | 492 | uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); |
@@ -507,7 +507,7 @@ uint64_t add_pinging(IP_Port ip_port) | |||
507 | } | 507 | } |
508 | 508 | ||
509 | /* Same but for get node requests */ | 509 | /* Same but for get node requests */ |
510 | uint64_t add_gettingnodes(IP_Port ip_port) | 510 | static uint64_t add_gettingnodes(IP_Port ip_port) |
511 | { | 511 | { |
512 | uint32_t i, j; | 512 | uint32_t i, j; |
513 | uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); | 513 | uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); |
@@ -676,7 +676,7 @@ static int sendnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id, | |||
676 | /* Packet handling functions, one to handle each types of packets we receive | 676 | /* Packet handling functions, one to handle each types of packets we receive |
677 | * Returns 0 if handled correctly, 1 if packet is bad. | 677 | * Returns 0 if handled correctly, 1 if packet is bad. |
678 | */ | 678 | */ |
679 | int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) | 679 | static int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) |
680 | { | 680 | { |
681 | uint64_t ping_id; | 681 | uint64_t ping_id; |
682 | if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) | 682 | if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) |
@@ -702,7 +702,7 @@ int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) | |||
702 | return 0; | 702 | return 0; |
703 | } | 703 | } |
704 | 704 | ||
705 | int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) | 705 | static int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) |
706 | { | 706 | { |
707 | uint64_t ping_id; | 707 | uint64_t ping_id; |
708 | if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) | 708 | if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) |
@@ -729,7 +729,7 @@ int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) | |||
729 | return 1; | 729 | return 1; |
730 | } | 730 | } |
731 | 731 | ||
732 | int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) | 732 | static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) |
733 | { | 733 | { |
734 | uint64_t ping_id; | 734 | uint64_t ping_id; |
735 | 735 | ||
@@ -761,7 +761,7 @@ int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) | |||
761 | return 0; | 761 | return 0; |
762 | } | 762 | } |
763 | 763 | ||
764 | int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) | 764 | static int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) |
765 | { | 765 | { |
766 | uint64_t ping_id; | 766 | uint64_t ping_id; |
767 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; | 767 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; |
@@ -873,7 +873,7 @@ IP_Port DHT_getfriendip(uint8_t * client_id) | |||
873 | /* Ping each client in the "friends" list every 60 seconds. Send a get nodes request | 873 | /* Ping each client in the "friends" list every 60 seconds. Send a get nodes request |
874 | * every 20 seconds to a random good node for each "friend" in our "friends" list. | 874 | * every 20 seconds to a random good node for each "friend" in our "friends" list. |
875 | */ | 875 | */ |
876 | void doDHTFriends() | 876 | static void doDHTFriends(void) |
877 | { | 877 | { |
878 | uint32_t i, j; | 878 | uint32_t i, j; |
879 | uint64_t temp_time = unix_time(); | 879 | uint64_t temp_time = unix_time(); |
@@ -912,7 +912,7 @@ static uint64_t close_lastgetnodes; | |||
912 | /* Ping each client in the close nodes list every 60 seconds. | 912 | /* Ping each client in the close nodes list every 60 seconds. |
913 | * Send a get nodes request every 20 seconds to a random good node in the list. | 913 | * Send a get nodes request every 20 seconds to a random good node in the list. |
914 | */ | 914 | */ |
915 | void doClose() | 915 | static void doClose(void) |
916 | { | 916 | { |
917 | uint32_t i; | 917 | uint32_t i; |
918 | uint64_t temp_time = unix_time(); | 918 | uint64_t temp_time = unix_time(); |
@@ -1029,7 +1029,7 @@ int route_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) | |||
1029 | /* Send the following packet to one random person who tells us they are connected to friend_id | 1029 | /* Send the following packet to one random person who tells us they are connected to friend_id |
1030 | * returns the number of nodes it sent the packet to | 1030 | * returns the number of nodes it sent the packet to |
1031 | */ | 1031 | */ |
1032 | int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) | 1032 | static int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) |
1033 | { | 1033 | { |
1034 | int num = friend_number(friend_id); | 1034 | int num = friend_number(friend_id); |
1035 | if (num == -1) | 1035 | if (num == -1) |
@@ -1079,7 +1079,7 @@ int friend_ips(IP_Port * ip_portlist, uint8_t * friend_id) | |||
1079 | /*----------------------------------------------------------------------------------*/ | 1079 | /*----------------------------------------------------------------------------------*/ |
1080 | /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ | 1080 | /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ |
1081 | 1081 | ||
1082 | int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) | 1082 | static int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) |
1083 | { | 1083 | { |
1084 | uint8_t data[sizeof(uint64_t) + 1]; | 1084 | uint8_t data[sizeof(uint64_t) + 1]; |
1085 | uint8_t packet[MAX_DATA_SIZE]; | 1085 | uint8_t packet[MAX_DATA_SIZE]; |
@@ -1105,7 +1105,7 @@ int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) | |||
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | /* Handle a recieved ping request for */ | 1107 | /* Handle a recieved ping request for */ |
1108 | int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) | 1108 | static int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) |
1109 | { | 1109 | { |
1110 | if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING | 1110 | if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING |
1111 | && length > MAX_DATA_SIZE + ENCRYPTION_PADDING) | 1111 | && length > MAX_DATA_SIZE + ENCRYPTION_PADDING) |
@@ -1211,7 +1211,7 @@ static void punch_holes(IP ip, uint16_t * port_list, uint16_t numports, uint16_t | |||
1211 | friends_list[friend_num].punching_index = i; | 1211 | friends_list[friend_num].punching_index = i; |
1212 | } | 1212 | } |
1213 | 1213 | ||
1214 | static void doNAT() | 1214 | static void doNAT(void) |
1215 | { | 1215 | { |
1216 | uint32_t i; | 1216 | uint32_t i; |
1217 | uint64_t temp_time = unix_time(); | 1217 | uint64_t temp_time = unix_time(); |
@@ -1275,7 +1275,7 @@ int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) | |||
1275 | return 0; | 1275 | return 0; |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | void doDHT() | 1278 | void doDHT(void) |
1279 | { | 1279 | { |
1280 | doClose(); | 1280 | doClose(); |
1281 | doDHTFriends(); | 1281 | doDHTFriends(); |
@@ -1283,7 +1283,7 @@ void doDHT() | |||
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | /* get the size of the DHT (for saving) */ | 1285 | /* get the size of the DHT (for saving) */ |
1286 | uint32_t DHT_size() | 1286 | uint32_t DHT_size(void) |
1287 | { | 1287 | { |
1288 | return sizeof(close_clientlist) + sizeof(Friend) * num_friends; | 1288 | return sizeof(close_clientlist) + sizeof(Friend) * num_friends; |
1289 | } | 1289 | } |
@@ -1341,7 +1341,7 @@ int DHT_load(uint8_t * data, uint32_t size) | |||
1341 | /* returns 0 if we are not connected to the DHT | 1341 | /* returns 0 if we are not connected to the DHT |
1342 | * returns 1 if we are | 1342 | * returns 1 if we are |
1343 | */ | 1343 | */ |
1344 | int DHT_isconnected() | 1344 | int DHT_isconnected(void) |
1345 | { | 1345 | { |
1346 | uint32_t i; | 1346 | uint32_t i; |
1347 | uint64_t temp_time = unix_time(); | 1347 | uint64_t temp_time = unix_time(); |
@@ -58,7 +58,7 @@ int DHT_delfriend(uint8_t *client_id); | |||
58 | IP_Port DHT_getfriendip(uint8_t *client_id); | 58 | IP_Port DHT_getfriendip(uint8_t *client_id); |
59 | 59 | ||
60 | /* Run this function at least a couple times per second (It's the main loop) */ | 60 | /* Run this function at least a couple times per second (It's the main loop) */ |
61 | void doDHT(); | 61 | void doDHT(void); |
62 | 62 | ||
63 | /* if we receive a DHT packet we call this function so it can be handled. | 63 | /* if we receive a DHT packet we call this function so it can be handled. |
64 | return 0 if packet is handled correctly. | 64 | return 0 if packet is handled correctly. |
@@ -90,7 +90,7 @@ int friend_ips(IP_Port *ip_portlist, uint8_t *friend_id); | |||
90 | /* SAVE/LOAD functions */ | 90 | /* SAVE/LOAD functions */ |
91 | 91 | ||
92 | /* get the size of the DHT (for saving) */ | 92 | /* get the size of the DHT (for saving) */ |
93 | uint32_t DHT_size(); | 93 | uint32_t DHT_size(void); |
94 | 94 | ||
95 | /* save the DHT in data where data is an array of size DHT_size() */ | 95 | /* save the DHT in data where data is an array of size DHT_size() */ |
96 | void DHT_save(uint8_t *data); | 96 | void DHT_save(uint8_t *data); |
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c index 72e00d32..55953685 100644 --- a/core/LAN_discovery.c +++ b/core/LAN_discovery.c | |||
@@ -29,7 +29,7 @@ | |||
29 | /* get the first working broadcast address that's not from "lo" | 29 | /* get the first working broadcast address that's not from "lo" |
30 | * returns higher than 0 on success | 30 | * returns higher than 0 on success |
31 | * returns 0 on error */ | 31 | * returns 0 on error */ |
32 | uint32_t get_broadcast(void) | 32 | static uint32_t get_broadcast(void) |
33 | { | 33 | { |
34 | /* not sure how many platforms this will | 34 | /* not sure how many platforms this will |
35 | * run on, so it's wrapped in __linux for now */ | 35 | * run on, so it's wrapped in __linux for now */ |
@@ -76,7 +76,7 @@ uint32_t get_broadcast(void) | |||
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | /* Return the broadcast ip */ | 78 | /* Return the broadcast ip */ |
79 | IP broadcast_ip() | 79 | static IP broadcast_ip(void) |
80 | { | 80 | { |
81 | IP ip; | 81 | IP ip; |
82 | #ifdef __linux | 82 | #ifdef __linux |
@@ -92,7 +92,7 @@ IP broadcast_ip() | |||
92 | 92 | ||
93 | /*return 0 if ip is a LAN ip | 93 | /*return 0 if ip is a LAN ip |
94 | return -1 if it is not */ | 94 | return -1 if it is not */ |
95 | int LAN_ip(IP ip) | 95 | static int LAN_ip(IP ip) |
96 | { | 96 | { |
97 | if (ip.c[0] == 127)/* Loopback */ | 97 | if (ip.c[0] == 127)/* Loopback */ |
98 | return 0; | 98 | return 0; |
@@ -107,7 +107,7 @@ int LAN_ip(IP ip) | |||
107 | return -1; | 107 | return -1; |
108 | } | 108 | } |
109 | 109 | ||
110 | int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source) | 110 | static int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source) |
111 | { | 111 | { |
112 | if (LAN_ip(source.ip) == -1) | 112 | if (LAN_ip(source.ip) == -1) |
113 | return 1; | 113 | return 1; |
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index a753e5ff..3a289735 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c | |||
@@ -149,7 +149,7 @@ static uint32_t randtable[6][256]; | |||
149 | * | 149 | * |
150 | * TODO: make this better | 150 | * TODO: make this better |
151 | */ | 151 | */ |
152 | uint32_t handshake_id(IP_Port source) | 152 | static uint32_t handshake_id(IP_Port source) |
153 | { | 153 | { |
154 | uint32_t id = 0, i; | 154 | uint32_t id = 0, i; |
155 | for (i = 0; i < 6; ++i) { | 155 | for (i = 0; i < 6; ++i) { |
@@ -168,7 +168,7 @@ uint32_t handshake_id(IP_Port source) | |||
168 | * | 168 | * |
169 | * TODO: make this better | 169 | * TODO: make this better |
170 | */ | 170 | */ |
171 | void change_handshake(IP_Port source) | 171 | static void change_handshake(IP_Port source) |
172 | { | 172 | { |
173 | uint8_t rand = random_int() % 4; | 173 | uint8_t rand = random_int() % 4; |
174 | randtable[rand][((uint8_t *)&source)[rand]] = random_int(); | 174 | randtable[rand][((uint8_t *)&source)[rand]] = random_int(); |
@@ -234,7 +234,7 @@ int new_connection(IP_Port ip_port) | |||
234 | * Returns an integer corresponding to the connection id. | 234 | * Returns an integer corresponding to the connection id. |
235 | * Return -1 if it could not initialize the connection. | 235 | * Return -1 if it could not initialize the connection. |
236 | */ | 236 | */ |
237 | int new_inconnection(IP_Port ip_port) | 237 | static int new_inconnection(IP_Port ip_port) |
238 | { | 238 | { |
239 | if (getconnection_id(ip_port) != -1) | 239 | if (getconnection_id(ip_port) != -1) |
240 | return -1; | 240 | return -1; |
@@ -284,7 +284,7 @@ int new_inconnection(IP_Port ip_port) | |||
284 | * Returns an integer corresponding to the next connection in our incoming connection list. | 284 | * Returns an integer corresponding to the next connection in our incoming connection list. |
285 | * Return -1 if there are no new incoming connections in the list. | 285 | * Return -1 if there are no new incoming connections in the list. |
286 | */ | 286 | */ |
287 | int incoming_connection() | 287 | int incoming_connection(void) |
288 | { | 288 | { |
289 | uint32_t i; | 289 | uint32_t i; |
290 | for (i = 0; i < MAX_CONNECTIONS; ++i) { | 290 | for (i = 0; i < MAX_CONNECTIONS; ++i) { |
@@ -298,7 +298,7 @@ int incoming_connection() | |||
298 | } | 298 | } |
299 | 299 | ||
300 | /* Try to free some memory from the connections array. */ | 300 | /* Try to free some memory from the connections array. */ |
301 | static void free_connections() | 301 | static void free_connections(void) |
302 | { | 302 | { |
303 | uint32_t i; | 303 | uint32_t i; |
304 | for(i = connections_length; i != 0; --i) | 304 | for(i = connections_length; i != 0; --i) |
@@ -470,7 +470,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested) | |||
470 | * see http://wiki.tox.im/index.php/Lossless_UDP for more information. | 470 | * see http://wiki.tox.im/index.php/Lossless_UDP for more information. |
471 | */ | 471 | */ |
472 | 472 | ||
473 | int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) | 473 | static int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) |
474 | { | 474 | { |
475 | uint8_t packet[1 + 4 + 4]; | 475 | uint8_t packet[1 + 4 + 4]; |
476 | uint32_t temp; | 476 | uint32_t temp; |
@@ -484,7 +484,7 @@ int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_i | |||
484 | return sendpacket(ip_port, packet, sizeof(packet)); | 484 | return sendpacket(ip_port, packet, sizeof(packet)); |
485 | } | 485 | } |
486 | 486 | ||
487 | int send_SYNC(uint32_t connection_id) | 487 | static int send_SYNC(uint32_t connection_id) |
488 | { | 488 | { |
489 | uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)]; | 489 | uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)]; |
490 | uint16_t index = 0; | 490 | uint16_t index = 0; |
@@ -511,7 +511,7 @@ int send_SYNC(uint32_t connection_id) | |||
511 | 511 | ||
512 | } | 512 | } |
513 | 513 | ||
514 | int send_data_packet(uint32_t connection_id, uint32_t packet_num) | 514 | static int send_data_packet(uint32_t connection_id, uint32_t packet_num) |
515 | { | 515 | { |
516 | uint32_t index = packet_num % MAX_QUEUE_NUM; | 516 | uint32_t index = packet_num % MAX_QUEUE_NUM; |
517 | uint32_t temp; | 517 | uint32_t temp; |
@@ -526,7 +526,7 @@ int send_data_packet(uint32_t connection_id, uint32_t packet_num) | |||
526 | } | 526 | } |
527 | 527 | ||
528 | /* sends 1 data packet */ | 528 | /* sends 1 data packet */ |
529 | int send_DATA(uint32_t connection_id) | 529 | static int send_DATA(uint32_t connection_id) |
530 | { | 530 | { |
531 | int ret; | 531 | int ret; |
532 | uint32_t buffer[BUFFER_PACKET_NUM]; | 532 | uint32_t buffer[BUFFER_PACKET_NUM]; |
@@ -555,7 +555,7 @@ int send_DATA(uint32_t connection_id) | |||
555 | 555 | ||
556 | 556 | ||
557 | /* Return 0 if handled correctly, 1 if packet is bad. */ | 557 | /* Return 0 if handled correctly, 1 if packet is bad. */ |
558 | int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) | 558 | static int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) |
559 | { | 559 | { |
560 | if (length != (1 + 4 + 4)) | 560 | if (length != (1 + 4 + 4)) |
561 | return 1; | 561 | return 1; |
@@ -591,7 +591,7 @@ int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) | |||
591 | } | 591 | } |
592 | 592 | ||
593 | /* returns 1 if sync packet is valid 0 if not. */ | 593 | /* returns 1 if sync packet is valid 0 if not. */ |
594 | int SYNC_valid(uint32_t length) | 594 | static int SYNC_valid(uint32_t length) |
595 | { | 595 | { |
596 | if (length < 4 + 4 + 2) | 596 | if (length < 4 + 4 + 2) |
597 | return 0; | 597 | return 0; |
@@ -602,7 +602,7 @@ int SYNC_valid(uint32_t length) | |||
602 | } | 602 | } |
603 | 603 | ||
604 | /* case 1 in handle_SYNC: */ | 604 | /* case 1 in handle_SYNC: */ |
605 | int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) | 605 | static int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) |
606 | { | 606 | { |
607 | if (handshake_id(source) == recv_packetnum) { | 607 | if (handshake_id(source) == recv_packetnum) { |
608 | int x = new_inconnection(source); | 608 | int x = new_inconnection(source); |
@@ -622,7 +622,7 @@ int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnu | |||
622 | } | 622 | } |
623 | 623 | ||
624 | /* case 2 in handle_SYNC: */ | 624 | /* case 2 in handle_SYNC: */ |
625 | int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) | 625 | static int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) |
626 | { | 626 | { |
627 | if (recv_packetnum == connections[connection_id].orecv_packetnum) { | 627 | if (recv_packetnum == connections[connection_id].orecv_packetnum) { |
628 | /* && sent_packetnum == connections[connection_id].osent_packetnum) */ | 628 | /* && sent_packetnum == connections[connection_id].osent_packetnum) */ |
@@ -635,7 +635,7 @@ int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui | |||
635 | return 1; | 635 | return 1; |
636 | } | 636 | } |
637 | /* case 3 in handle_SYNC: */ | 637 | /* case 3 in handle_SYNC: */ |
638 | int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, | 638 | static int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, |
639 | uint16_t number) | 639 | uint16_t number) |
640 | { | 640 | { |
641 | uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); | 641 | uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); |
@@ -669,7 +669,7 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui | |||
669 | return 1; | 669 | return 1; |
670 | } | 670 | } |
671 | 671 | ||
672 | int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) | 672 | static int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) |
673 | { | 673 | { |
674 | 674 | ||
675 | if (!SYNC_valid(length)) | 675 | if (!SYNC_valid(length)) |
@@ -708,7 +708,7 @@ int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) | |||
708 | * Add a packet to the received buffer and set the recv_packetnum of the | 708 | * Add a packet to the received buffer and set the recv_packetnum of the |
709 | * connection to its proper value. Return 1 if data was too big, 0 if not. | 709 | * connection to its proper value. Return 1 if data was too big, 0 if not. |
710 | */ | 710 | */ |
711 | int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) | 711 | static int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) |
712 | { | 712 | { |
713 | if (size > MAX_DATA_SIZE) | 713 | if (size > MAX_DATA_SIZE) |
714 | return 1; | 714 | return 1; |
@@ -742,7 +742,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) | |||
742 | return 0; | 742 | return 0; |
743 | } | 743 | } |
744 | 744 | ||
745 | int handle_data(uint8_t *packet, uint32_t length, IP_Port source) | 745 | static int handle_data(uint8_t *packet, uint32_t length, IP_Port source) |
746 | { | 746 | { |
747 | int connection = getconnection_id(source); | 747 | int connection = getconnection_id(source); |
748 | 748 | ||
@@ -793,7 +793,7 @@ int LosslessUDP_handlepacket(uint8_t *packet, uint32_t length, IP_Port source) | |||
793 | * Send handshake requests | 793 | * Send handshake requests |
794 | * handshake packets are sent at the same rate as SYNC packets | 794 | * handshake packets are sent at the same rate as SYNC packets |
795 | */ | 795 | */ |
796 | void doNew() | 796 | static void doNew(void) |
797 | { | 797 | { |
798 | uint32_t i; | 798 | uint32_t i; |
799 | uint64_t temp_time = current_time(); | 799 | uint64_t temp_time = current_time(); |
@@ -817,7 +817,7 @@ void doNew() | |||
817 | } | 817 | } |
818 | } | 818 | } |
819 | 819 | ||
820 | void doSYNC() | 820 | static void doSYNC(void) |
821 | { | 821 | { |
822 | uint32_t i; | 822 | uint32_t i; |
823 | uint64_t temp_time = current_time(); | 823 | uint64_t temp_time = current_time(); |
@@ -830,7 +830,7 @@ void doSYNC() | |||
830 | } | 830 | } |
831 | } | 831 | } |
832 | 832 | ||
833 | void doData() | 833 | static void doData(void) |
834 | { | 834 | { |
835 | uint32_t i; | 835 | uint32_t i; |
836 | uint64_t j; | 836 | uint64_t j; |
@@ -851,7 +851,7 @@ void doData() | |||
851 | * | 851 | * |
852 | * TODO: flow control. | 852 | * TODO: flow control. |
853 | */ | 853 | */ |
854 | void adjustRates() | 854 | static void adjustRates(void) |
855 | { | 855 | { |
856 | uint32_t i; | 856 | uint32_t i; |
857 | uint64_t temp_time = current_time(); | 857 | uint64_t temp_time = current_time(); |
@@ -871,7 +871,7 @@ void adjustRates() | |||
871 | } | 871 | } |
872 | 872 | ||
873 | /* Call this function a couple times per second It's the main loop. */ | 873 | /* Call this function a couple times per second It's the main loop. */ |
874 | void doLossless_UDP() | 874 | void doLossless_UDP(void) |
875 | { | 875 | { |
876 | doNew(); | 876 | doNew(); |
877 | doSYNC(); | 877 | doSYNC(); |
diff --git a/core/Lossless_UDP.h b/core/Lossless_UDP.h index 75ef273e..b4cb186a 100644 --- a/core/Lossless_UDP.h +++ b/core/Lossless_UDP.h | |||
@@ -52,7 +52,7 @@ int getconnection_id(IP_Port ip_port); | |||
52 | * Returns an int corresponding to the next connection in our imcoming connection list | 52 | * Returns an int corresponding to the next connection in our imcoming connection list |
53 | * Return -1 if there are no new incoming connections in the list. | 53 | * Return -1 if there are no new incoming connections in the list. |
54 | */ | 54 | */ |
55 | int incoming_connection(); | 55 | int incoming_connection(void); |
56 | 56 | ||
57 | /* | 57 | /* |
58 | * Return -1 if it could not kill the connection. | 58 | * Return -1 if it could not kill the connection. |
@@ -110,7 +110,7 @@ uint32_t recvqueue(int connection_id); | |||
110 | int is_connected(int connection_id); | 110 | int is_connected(int connection_id); |
111 | 111 | ||
112 | /* Call this function a couple times per second It's the main loop. */ | 112 | /* Call this function a couple times per second It's the main loop. */ |
113 | void doLossless_UDP(); | 113 | void doLossless_UDP(void); |
114 | 114 | ||
115 | /* | 115 | /* |
116 | * If we receive a Lossless_UDP packet, call this function so it can be handled. | 116 | * If we receive a Lossless_UDP packet, call this function so it can be handled. |
diff --git a/core/Messenger.c b/core/Messenger.c index c768633e..dee6eefc 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -363,7 +363,7 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)) | |||
363 | 363 | ||
364 | #define PORT 33445 | 364 | #define PORT 33445 |
365 | /* run this at startup */ | 365 | /* run this at startup */ |
366 | int initMessenger() | 366 | int initMessenger(void) |
367 | { | 367 | { |
368 | new_keys(); | 368 | new_keys(); |
369 | m_set_userstatus((uint8_t*)"Online", sizeof("Online")); | 369 | m_set_userstatus((uint8_t*)"Online", sizeof("Online")); |
@@ -378,7 +378,7 @@ int initMessenger() | |||
378 | } | 378 | } |
379 | 379 | ||
380 | //TODO: make this function not suck. | 380 | //TODO: make this function not suck. |
381 | static void doFriends() | 381 | static void doFriends(void) |
382 | { | 382 | { |
383 | /* TODO: add incoming connections and some other stuff. */ | 383 | /* TODO: add incoming connections and some other stuff. */ |
384 | uint32_t i; | 384 | uint32_t i; |
@@ -464,7 +464,7 @@ static void doFriends() | |||
464 | } | 464 | } |
465 | } | 465 | } |
466 | 466 | ||
467 | static void doInbound() | 467 | static void doInbound(void) |
468 | { | 468 | { |
469 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; | 469 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; |
470 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 470 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
@@ -488,7 +488,7 @@ static void doInbound() | |||
488 | static uint64_t last_LANdiscovery; | 488 | static uint64_t last_LANdiscovery; |
489 | 489 | ||
490 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ | 490 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ |
491 | static void LANdiscovery() | 491 | static void LANdiscovery(void) |
492 | { | 492 | { |
493 | if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { | 493 | if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { |
494 | send_LANdiscovery(htons(PORT)); | 494 | send_LANdiscovery(htons(PORT)); |
@@ -498,7 +498,7 @@ static void LANdiscovery() | |||
498 | 498 | ||
499 | 499 | ||
500 | /* the main loop that needs to be run at least 200 times per second. */ | 500 | /* the main loop that needs to be run at least 200 times per second. */ |
501 | void doMessenger() | 501 | void doMessenger(void) |
502 | { | 502 | { |
503 | IP_Port ip_port; | 503 | IP_Port ip_port; |
504 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 504 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
@@ -532,7 +532,7 @@ void doMessenger() | |||
532 | } | 532 | } |
533 | 533 | ||
534 | /* returns the size of the messenger data (for saving) */ | 534 | /* returns the size of the messenger data (for saving) */ |
535 | uint32_t Messenger_size() | 535 | uint32_t Messenger_size(void) |
536 | { | 536 | { |
537 | return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES | 537 | return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES |
538 | + sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends; | 538 | + sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends; |
diff --git a/core/Messenger.h b/core/Messenger.h index acf62a32..20b38caa 100644 --- a/core/Messenger.h +++ b/core/Messenger.h | |||
@@ -160,15 +160,15 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)); | |||
160 | /* run this at startup | 160 | /* run this at startup |
161 | returns 0 if no connection problems | 161 | returns 0 if no connection problems |
162 | returns -1 if there are problems */ | 162 | returns -1 if there are problems */ |
163 | int initMessenger(); | 163 | int initMessenger(void); |
164 | 164 | ||
165 | /* the main loop that needs to be run at least 200 times per second */ | 165 | /* the main loop that needs to be run at least 200 times per second */ |
166 | void doMessenger(); | 166 | void doMessenger(void); |
167 | 167 | ||
168 | /* SAVING AND LOADING FUNCTIONS: */ | 168 | /* SAVING AND LOADING FUNCTIONS: */ |
169 | 169 | ||
170 | /* returns the size of the messenger data (for saving) */ | 170 | /* returns the size of the messenger data (for saving) */ |
171 | uint32_t Messenger_size(); | 171 | uint32_t Messenger_size(void); |
172 | 172 | ||
173 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ | 173 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ |
174 | void Messenger_save(uint8_t *data); | 174 | void Messenger_save(uint8_t *data); |
diff --git a/core/net_crypto.c b/core/net_crypto.c index 561ba866..1c56b95a 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -126,7 +126,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | |||
126 | } | 126 | } |
127 | 127 | ||
128 | /* increment the given nonce by 1 */ | 128 | /* increment the given nonce by 1 */ |
129 | void increment_nonce(uint8_t *nonce) | 129 | static void increment_nonce(uint8_t *nonce) |
130 | { | 130 | { |
131 | uint32_t i; | 131 | uint32_t i; |
132 | for (i = 0; i < crypto_box_NONCEBYTES; ++i) { | 132 | for (i = 0; i < crypto_box_NONCEBYTES; ++i) { |
@@ -243,7 +243,7 @@ int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t | |||
243 | /* Send a crypto handshake packet containing an encrypted secret nonce and session public key | 243 | /* Send a crypto handshake packet containing an encrypted secret nonce and session public key |
244 | to peer with connection_id and public_key | 244 | to peer with connection_id and public_key |
245 | the packet is encrypted with a random nonce which is sent in plain text with the packet */ | 245 | the packet is encrypted with a random nonce which is sent in plain text with the packet */ |
246 | int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) | 246 | static int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) |
247 | { | 247 | { |
248 | uint8_t temp_data[MAX_DATA_SIZE]; | 248 | uint8_t temp_data[MAX_DATA_SIZE]; |
249 | uint8_t temp[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES]; | 249 | uint8_t temp[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES]; |
@@ -266,7 +266,7 @@ int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret | |||
266 | /* Extract secret nonce, session public key and public_key from a packet(data) with length length | 266 | /* Extract secret nonce, session public key and public_key from a packet(data) with length length |
267 | return 1 if successful | 267 | return 1 if successful |
268 | return 0 if failure */ | 268 | return 0 if failure */ |
269 | int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, | 269 | static int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, |
270 | uint8_t *session_key, uint8_t *data, uint16_t length) | 270 | uint8_t *session_key, uint8_t *data, uint16_t length) |
271 | { | 271 | { |
272 | int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); | 272 | int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); |
@@ -295,7 +295,7 @@ int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, | |||
295 | /* get crypto connection id from public key of peer | 295 | /* get crypto connection id from public key of peer |
296 | return -1 if there are no connections like we are looking for | 296 | return -1 if there are no connections like we are looking for |
297 | return id if it found it */ | 297 | return id if it found it */ |
298 | int getcryptconnection_id(uint8_t *public_key) | 298 | static int getcryptconnection_id(uint8_t *public_key) |
299 | { | 299 | { |
300 | uint32_t i; | 300 | uint32_t i; |
301 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { | 301 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { |
@@ -440,7 +440,7 @@ int is_cryptoconnected(int crypt_connection_id) | |||
440 | 440 | ||
441 | /* Generate our public and private keys | 441 | /* Generate our public and private keys |
442 | Only call this function the first time the program starts. */ | 442 | Only call this function the first time the program starts. */ |
443 | void new_keys() | 443 | void new_keys(void) |
444 | { | 444 | { |
445 | crypto_box_keypair(self_public_key,self_secret_key); | 445 | crypto_box_keypair(self_public_key,self_secret_key); |
446 | } | 446 | } |
@@ -465,7 +465,7 @@ void load_keys(uint8_t *keys) | |||
465 | adds an incoming connection to the incoming_connection list. | 465 | adds an incoming connection to the incoming_connection list. |
466 | returns 0 if successful | 466 | returns 0 if successful |
467 | returns 1 if failure */ | 467 | returns 1 if failure */ |
468 | int new_incoming(int id) | 468 | static int new_incoming(int id) |
469 | { | 469 | { |
470 | uint32_t i; | 470 | uint32_t i; |
471 | for (i = 0; i < MAX_INCOMING; ++i) { | 471 | for (i = 0; i < MAX_INCOMING; ++i) { |
@@ -479,7 +479,7 @@ int new_incoming(int id) | |||
479 | 479 | ||
480 | /* TODO: optimize this | 480 | /* TODO: optimize this |
481 | handle all new incoming connections. */ | 481 | handle all new incoming connections. */ |
482 | static void handle_incomings() | 482 | static void handle_incomings(void) |
483 | { | 483 | { |
484 | int income; | 484 | int income; |
485 | while (1) { | 485 | while (1) { |
@@ -490,7 +490,7 @@ static void handle_incomings() | |||
490 | } | 490 | } |
491 | 491 | ||
492 | /* handle received packets for not yet established crypto connections. */ | 492 | /* handle received packets for not yet established crypto connections. */ |
493 | static void receive_crypto() | 493 | static void receive_crypto(void) |
494 | { | 494 | { |
495 | uint32_t i; | 495 | uint32_t i; |
496 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { | 496 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { |
@@ -547,7 +547,7 @@ static void receive_crypto() | |||
547 | 547 | ||
548 | /* run this to (re)initialize net_crypto | 548 | /* run this to (re)initialize net_crypto |
549 | sets all the global connection variables to their default values. */ | 549 | sets all the global connection variables to their default values. */ |
550 | void initNetCrypto() | 550 | void initNetCrypto(void) |
551 | { | 551 | { |
552 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); | 552 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); |
553 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); | 553 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); |
@@ -556,7 +556,7 @@ void initNetCrypto() | |||
556 | crypto_connections[i].number = ~0; | 556 | crypto_connections[i].number = ~0; |
557 | } | 557 | } |
558 | 558 | ||
559 | static void killTimedout() | 559 | static void killTimedout(void) |
560 | { | 560 | { |
561 | uint32_t i; | 561 | uint32_t i; |
562 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { | 562 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { |
@@ -570,7 +570,7 @@ static void killTimedout() | |||
570 | } | 570 | } |
571 | 571 | ||
572 | /* main loop */ | 572 | /* main loop */ |
573 | void doNetCrypto() | 573 | void doNetCrypto(void) |
574 | { | 574 | { |
575 | /* TODO:check if friend requests were sent correctly | 575 | /* TODO:check if friend requests were sent correctly |
576 | handle new incoming connections | 576 | handle new incoming connections |
diff --git a/core/net_crypto.h b/core/net_crypto.h index 0e7284c9..66634d45 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h | |||
@@ -110,7 +110,7 @@ int is_cryptoconnected(int crypt_connection_id); | |||
110 | 110 | ||
111 | /* Generate our public and private keys | 111 | /* Generate our public and private keys |
112 | Only call this function the first time the program starts. */ | 112 | Only call this function the first time the program starts. */ |
113 | void new_keys(); | 113 | void new_keys(void); |
114 | 114 | ||
115 | /* save the public and private keys to the keys array | 115 | /* save the public and private keys to the keys array |
116 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ | 116 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ |
@@ -122,10 +122,10 @@ void load_keys(uint8_t * keys); | |||
122 | 122 | ||
123 | /* run this to (re)initialize net_crypto | 123 | /* run this to (re)initialize net_crypto |
124 | sets all the global connection variables to their default values. */ | 124 | sets all the global connection variables to their default values. */ |
125 | void initNetCrypto(); | 125 | void initNetCrypto(void); |
126 | 126 | ||
127 | /* main loop */ | 127 | /* main loop */ |
128 | void doNetCrypto(); | 128 | void doNetCrypto(void); |
129 | 129 | ||
130 | #ifdef __cplusplus | 130 | #ifdef __cplusplus |
131 | } | 131 | } |
diff --git a/core/network.c b/core/network.c index c58549bf..8c6fa7b6 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "network.h" | 24 | #include "network.h" |
25 | 25 | ||
26 | /* returns current UNIX time in microseconds (us). */ | 26 | /* returns current UNIX time in microseconds (us). */ |
27 | uint64_t current_time() | 27 | uint64_t current_time(void) |
28 | { | 28 | { |
29 | uint64_t time; | 29 | uint64_t time; |
30 | #ifdef WIN32 | 30 | #ifdef WIN32 |
@@ -46,7 +46,7 @@ uint64_t current_time() | |||
46 | 46 | ||
47 | /* return a random number | 47 | /* return a random number |
48 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ | 48 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ |
49 | uint32_t random_int() | 49 | uint32_t random_int(void) |
50 | { | 50 | { |
51 | #ifndef VANILLA_NACL | 51 | #ifndef VANILLA_NACL |
52 | //NOTE: this function comes from libsodium | 52 | //NOTE: this function comes from libsodium |
@@ -153,7 +153,7 @@ int init_networking(IP ip, uint16_t port) | |||
153 | } | 153 | } |
154 | 154 | ||
155 | /* function to cleanup networking stuff */ | 155 | /* function to cleanup networking stuff */ |
156 | void shutdown_networking() | 156 | void shutdown_networking(void) |
157 | { | 157 | { |
158 | #ifdef WIN32 | 158 | #ifdef WIN32 |
159 | closesocket(sock); | 159 | closesocket(sock); |
diff --git a/core/network.h b/core/network.h index a7559ebe..d246a9d1 100644 --- a/core/network.h +++ b/core/network.h | |||
@@ -90,11 +90,11 @@ typedef struct { | |||
90 | } ADDR; | 90 | } ADDR; |
91 | 91 | ||
92 | /* returns current time in milleseconds since the epoch. */ | 92 | /* returns current time in milleseconds since the epoch. */ |
93 | uint64_t current_time(); | 93 | uint64_t current_time(void); |
94 | 94 | ||
95 | /* return a random number | 95 | /* return a random number |
96 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ | 96 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ |
97 | uint32_t random_int(); | 97 | uint32_t random_int(void); |
98 | 98 | ||
99 | /* Basic network functions: */ | 99 | /* Basic network functions: */ |
100 | 100 | ||
@@ -115,7 +115,7 @@ int receivepacket(IP_Port *ip_port, uint8_t *data, uint32_t *length); | |||
115 | int init_networking(IP ip, uint16_t port); | 115 | int init_networking(IP ip, uint16_t port); |
116 | 116 | ||
117 | /* function to cleanup networking stuff(doesn't do much right now) */ | 117 | /* function to cleanup networking stuff(doesn't do much right now) */ |
118 | void shutdown_networking(); | 118 | void shutdown_networking(void); |
119 | 119 | ||
120 | /* | 120 | /* |
121 | resolve_addr(): | 121 | resolve_addr(): |
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index abbc278e..f2a2e95e 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt | |||
@@ -8,11 +8,10 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake) | |||
8 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake) | 8 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake) |
9 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) | 9 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) |
10 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) | 10 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) |
11 | |||
11 | if(WIN32) | 12 | if(WIN32) |
12 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) | 13 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) |
13 | endif() | 14 | else() |
14 | |||
15 | if(NOT WIN32) | ||
16 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) | 15 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) |
17 | add_subdirectory(toxic) | 16 | add_subdirectory(toxic) |
18 | endif() | 17 | endif() |
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index dbaa8b3b..aa546a88 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -36,5 +36,6 @@ unsigned char * hex_string_to_bin(char hex_string[]) | |||
36 | int i; | 36 | int i; |
37 | for(i = 0; i < len; ++i, pos+=2) | 37 | for(i = 0; i < len; ++i, pos+=2) |
38 | sscanf(pos,"%2hhx",&val[i]); | 38 | sscanf(pos,"%2hhx",&val[i]); |
39 | |||
39 | return val; | 40 | return val; |
40 | } | 41 | } |
diff --git a/testing/nTox.c b/testing/nTox.c index eabb3f28..fe91b1fa 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -147,22 +147,24 @@ void line_eval(char *line) | |||
147 | for (i = 0; i < 128; i++) | 147 | for (i = 0; i < 128; i++) |
148 | temp_id[i] = line[i+prompt_offset]; | 148 | temp_id[i] = line[i+prompt_offset]; |
149 | 149 | ||
150 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 150 | unsigned char *bin_string = hex_string_to_bin(temp_id); |
151 | int num = m_addfriend(bin_string, (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | ||
152 | free(bin_string); | ||
151 | char numstring[100]; | 153 | char numstring[100]; |
152 | switch (num) { | 154 | switch (num) { |
153 | case -1: | 155 | case FAERR_TOOLONG: |
154 | sprintf(numstring, "[i] Message is too long."); | 156 | sprintf(numstring, "[i] Message is too long."); |
155 | break; | 157 | break; |
156 | case -2: | 158 | case FAERR_NOMESSAGE: |
157 | sprintf(numstring, "[i] Please add a message to your request."); | 159 | sprintf(numstring, "[i] Please add a message to your request."); |
158 | break; | 160 | break; |
159 | case -3: | 161 | case FAERR_OWNKEY: |
160 | sprintf(numstring, "[i] That appears to be your own ID."); | 162 | sprintf(numstring, "[i] That appears to be your own ID."); |
161 | break; | 163 | break; |
162 | case -4: | 164 | case FAERR_ALREADYSENT: |
163 | sprintf(numstring, "[i] Friend request already sent."); | 165 | sprintf(numstring, "[i] Friend request already sent."); |
164 | break; | 166 | break; |
165 | case -5: | 167 | case FAERR_UNKNOWN: |
166 | sprintf(numstring, "[i] Undefined error when adding friend."); | 168 | sprintf(numstring, "[i] Undefined error when adding friend."); |
167 | break; | 169 | break; |
168 | default: | 170 | default: |
@@ -355,34 +357,38 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
355 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | 357 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) |
356 | { | 358 | { |
357 | char name[MAX_NAME_LENGTH]; | 359 | char name[MAX_NAME_LENGTH]; |
358 | getname(friendnumber, (uint8_t*)name); | 360 | if(getname(friendnumber, (uint8_t*)name) != -1) { |
359 | char msg[100+length]; | 361 | char msg[100+length]; |
360 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); | 362 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); |
361 | new_lines(msg); | 363 | new_lines(msg); |
364 | } | ||
362 | } | 365 | } |
363 | 366 | ||
364 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | 367 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
365 | { | 368 | { |
366 | char name[MAX_NAME_LENGTH]; | 369 | char name[MAX_NAME_LENGTH]; |
367 | getname(friendnumber, (uint8_t*)name); | 370 | if(getname(friendnumber, (uint8_t*)name) != -1) { |
368 | char msg[100+length+strlen(name)+1]; | 371 | char msg[100+length+strlen(name)+1]; |
369 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); | 372 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); |
370 | new_lines(msg); | 373 | new_lines(msg); |
374 | } | ||
371 | } | 375 | } |
372 | 376 | ||
373 | void load_key(char *path) | 377 | void load_key(char *path) |
374 | { | 378 | { |
375 | FILE *data_file = fopen(path, "r"); | 379 | FILE *data_file = fopen(path, "r"); |
380 | int size = 0; | ||
376 | 381 | ||
377 | if (data_file) { | 382 | if (data_file) { |
378 | //load keys | 383 | //load keys |
379 | fseek(data_file, 0, SEEK_END); | 384 | fseek(data_file, 0, SEEK_END); |
380 | int size = ftell(data_file); | 385 | size = ftell(data_file); |
381 | fseek(data_file, 0, SEEK_SET); | 386 | rewind(data_file); |
387 | |||
382 | uint8_t data[size]; | 388 | uint8_t data[size]; |
383 | if (fread(data, sizeof(uint8_t), size, data_file) != size){ | 389 | if (fread(data, sizeof(uint8_t), size, data_file) != size){ |
384 | printf("[i] could not read data file\n[i] exiting\n"); | 390 | fputs("[!] could not read data file! exiting...\n", stderr); |
385 | exit(1); | 391 | goto FILE_ERROR; |
386 | } | 392 | } |
387 | Messenger_load(data, size); | 393 | Messenger_load(data, size); |
388 | 394 | ||
@@ -399,11 +405,17 @@ void load_key(char *path) | |||
399 | } | 405 | } |
400 | 406 | ||
401 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ | 407 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ |
402 | puts("[i] could not write data file! exiting..."); | 408 | fputs("[!] could not write data file! exiting...", stderr); |
403 | exit(1); | 409 | goto FILE_ERROR; |
404 | } | 410 | } |
405 | } | 411 | } |
406 | fclose(data_file); | 412 | |
413 | return; | ||
414 | |||
415 | FILE_ERROR: | ||
416 | if(fclose(data_file) < 0) | ||
417 | perror("[!] fclose failed"); | ||
418 | exit(1); | ||
407 | } | 419 | } |
408 | 420 | ||
409 | void print_help(void) | 421 | void print_help(void) |
@@ -428,7 +440,9 @@ int main(int argc, char *argv[]) | |||
428 | } | 440 | } |
429 | 441 | ||
430 | for(i = 0; i < argc; i++) { | 442 | for(i = 0; i < argc; i++) { |
431 | if(argv[i][0] == '-') { | 443 | if (argv[i] == NULL){ |
444 | break; | ||
445 | } else if(argv[i][0] == '-') { | ||
432 | if(argv[i][1] == 'h') { | 446 | if(argv[i][1] == 'h') { |
433 | print_help(); | 447 | print_help(); |
434 | exit(0); | 448 | exit(0); |
@@ -468,7 +482,9 @@ int main(int argc, char *argv[]) | |||
468 | else | 482 | else |
469 | exit(1); | 483 | exit(1); |
470 | 484 | ||
471 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 485 | unsigned char *binary_string = hex_string_to_bin(argv[3]); |
486 | DHT_bootstrap(bootstrap_ip_port, binary_string); | ||
487 | free(binary_string); | ||
472 | nodelay(stdscr, TRUE); | 488 | nodelay(stdscr, TRUE); |
473 | while(true) { | 489 | while(true) { |
474 | if (on == 0 && DHT_isconnected()) { | 490 | if (on == 0 && DHT_isconnected()) { |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index a90bb2aa..ff7a1667 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -26,6 +26,8 @@ typedef struct { | |||
26 | } ChatContext; | 26 | } ChatContext; |
27 | 27 | ||
28 | extern void fix_name(uint8_t* name); | 28 | extern void fix_name(uint8_t* name); |
29 | void print_help(ChatContext* self); | ||
30 | void execute(ToxWindow* self, ChatContext* ctx, char* cmd); | ||
29 | 31 | ||
30 | static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { | 32 | static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { |
31 | ChatContext* ctx = (ChatContext*) self->x; | 33 | ChatContext* ctx = (ChatContext*) self->x; |
@@ -49,6 +51,7 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) | |||
49 | 51 | ||
50 | wattron(ctx->history, COLOR_PAIR(2)); | 52 | wattron(ctx->history, COLOR_PAIR(2)); |
51 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | 53 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
54 | wattroff(ctx->history, COLOR_PAIR(2)); | ||
52 | wattron(ctx->history, COLOR_PAIR(4)); | 55 | wattron(ctx->history, COLOR_PAIR(4)); |
53 | wprintw(ctx->history, "%s: ", nick); | 56 | wprintw(ctx->history, "%s: ", nick); |
54 | wattroff(ctx->history, COLOR_PAIR(4)); | 57 | wattroff(ctx->history, COLOR_PAIR(4)); |
@@ -97,41 +100,93 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
97 | struct tm * timeinfo; | 100 | struct tm * timeinfo; |
98 | timeinfo = localtime(&now); | 101 | timeinfo = localtime(&now); |
99 | 102 | ||
103 | /* PRINTABLE characters: Add to line */ | ||
100 | if(isprint(key)) { | 104 | if(isprint(key)) { |
101 | |||
102 | if(ctx->pos != sizeof(ctx->line)-1) { | 105 | if(ctx->pos != sizeof(ctx->line)-1) { |
103 | ctx->line[ctx->pos++] = key; | 106 | ctx->line[ctx->pos++] = key; |
104 | ctx->line[ctx->pos] = '\0'; | 107 | ctx->line[ctx->pos] = '\0'; |
105 | } | 108 | } |
106 | } | 109 | } |
107 | 110 | ||
111 | /* RETURN key: Execute command or print line */ | ||
108 | else if(key == '\n') { | 112 | else if(key == '\n') { |
109 | if(!string_is_empty(ctx->line)) { | 113 | if (ctx->line[0] == '/') |
110 | /* make sure the string has at least non-space character */ | 114 | execute(self, ctx, ctx->line); |
111 | wattron(ctx->history, COLOR_PAIR(2)); | 115 | else { |
112 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | 116 | if(!string_is_empty(ctx->line)) { |
113 | wattron(ctx->history, COLOR_PAIR(1)); | 117 | /* make sure the string has at least non-space character */ |
114 | wprintw(ctx->history, "you: ", ctx->line); | 118 | wattron(ctx->history, COLOR_PAIR(2)); |
115 | wattroff(ctx->history, COLOR_PAIR(1)); | 119 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
116 | wprintw(ctx->history, "%s\n", ctx->line); | 120 | wattroff(ctx->history, COLOR_PAIR(2)); |
117 | 121 | wattron(ctx->history, COLOR_PAIR(1)); | |
122 | wprintw(ctx->history, "you: ", ctx->line); | ||
123 | wattroff(ctx->history, COLOR_PAIR(1)); | ||
124 | wprintw(ctx->history, "%s\n", ctx->line); | ||
125 | } | ||
118 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { | 126 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { |
119 | wattron(ctx->history, COLOR_PAIR(3)); | 127 | wattron(ctx->history, COLOR_PAIR(3)); |
120 | wprintw(ctx->history, " * Failed to send message.\n"); | 128 | wprintw(ctx->history, " * Failed to send message.\n"); |
121 | wattroff(ctx->history, COLOR_PAIR(3)); | 129 | wattroff(ctx->history, COLOR_PAIR(3)); |
122 | } | 130 | } |
123 | |||
124 | ctx->line[0] = '\0'; | ||
125 | ctx->pos = 0; | ||
126 | } | 131 | } |
132 | ctx->line[0] = '\0'; | ||
133 | ctx->pos = 0; | ||
127 | } | 134 | } |
128 | 135 | ||
136 | /* BACKSPACE key: Remove one character from line */ | ||
129 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { | 137 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { |
130 | if(ctx->pos != 0) { | 138 | if(ctx->pos != 0) { |
131 | ctx->line[--ctx->pos] = '\0'; | 139 | ctx->line[--ctx->pos] = '\0'; |
132 | } | 140 | } |
133 | } | 141 | } |
142 | } | ||
134 | 143 | ||
144 | void execute(ToxWindow* self, ChatContext* ctx, char* cmd) | ||
145 | { | ||
146 | if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { | ||
147 | wclear(self->window); | ||
148 | wclear(ctx->history); | ||
149 | } | ||
150 | else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h")) | ||
151 | print_help(ctx); | ||
152 | else if (!strcmp(cmd, "/quit") || !strcmp(cmd, "/exit") || !strcmp(cmd, "/q")) { | ||
153 | endwin(); | ||
154 | exit(0); | ||
155 | } | ||
156 | else if (!strncmp(cmd, "/status ", strlen("/status "))) { | ||
157 | char* msg; | ||
158 | msg = strchr(cmd, ' '); | ||
159 | if(msg == NULL) { | ||
160 | wprintw(ctx->history, "Invalid syntax.\n"); | ||
161 | return; | ||
162 | } | ||
163 | msg++; | ||
164 | m_set_userstatus((uint8_t*) msg, strlen(msg)+1); | ||
165 | wprintw(ctx->history, "Status set to: %s\n", msg); | ||
166 | } | ||
167 | else if (!strncmp(cmd, "/nick ", strlen("/nick "))) { | ||
168 | char* nick; | ||
169 | nick = strchr(cmd, ' '); | ||
170 | if(nick == NULL) { | ||
171 | wprintw(ctx->history, "Invalid syntax.\n"); | ||
172 | return; | ||
173 | } | ||
174 | nick++; | ||
175 | setname((uint8_t*) nick, strlen(nick)+1); | ||
176 | wprintw(ctx->history, "Nickname set to: %s\n", nick); | ||
177 | } | ||
178 | else if(!strcmp(cmd, "/myid")) { | ||
179 | char id[32*2 + 1] = {0}; | ||
180 | int i; | ||
181 | for (i = 0; i < 32; i++) { | ||
182 | char xx[3]; | ||
183 | snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); | ||
184 | strcat(id, xx); | ||
185 | } | ||
186 | wprintw(ctx->history, "Your ID: %s\n", id); | ||
187 | } | ||
188 | else | ||
189 | wprintw(ctx->history, "Invalid command.\n"); | ||
135 | } | 190 | } |
136 | 191 | ||
137 | static void chat_onDraw(ToxWindow* self) { | 192 | static void chat_onDraw(ToxWindow* self) { |
@@ -164,6 +219,21 @@ static void chat_onInit(ToxWindow* self) { | |||
164 | ctx->linewin = subwin(self->window, 2, x, y - 3, 0); | 219 | ctx->linewin = subwin(self->window, 2, x, y - 3, 0); |
165 | } | 220 | } |
166 | 221 | ||
222 | void print_help(ChatContext* self) { | ||
223 | wattron(self->history, COLOR_PAIR(2) | A_BOLD); | ||
224 | wprintw(self->history, "\nCommands:\n"); | ||
225 | wattroff(self->history, A_BOLD); | ||
226 | |||
227 | wprintw(self->history, " /status <message> : Set your status\n"); | ||
228 | wprintw(self->history, " /nick <nickname> : Set your nickname\n"); | ||
229 | wprintw(self->history, " /myid : Print your ID\n"); | ||
230 | wprintw(self->history, " /clear : Clear the screen\n"); | ||
231 | wprintw(self->history, " /quit or /exit : Exit program\n"); | ||
232 | wprintw(self->history, " /help : Print this message again\n\n"); | ||
233 | |||
234 | wattroff(self->history, COLOR_PAIR(2)); | ||
235 | } | ||
236 | |||
167 | ToxWindow new_chat(int friendnum) { | 237 | ToxWindow new_chat(int friendnum) { |
168 | ToxWindow ret; | 238 | ToxWindow ret; |
169 | 239 | ||
@@ -186,6 +256,5 @@ ToxWindow new_chat(int friendnum) { | |||
186 | x->friendnum = friendnum; | 256 | x->friendnum = friendnum; |
187 | 257 | ||
188 | ret.x = (void*) x; | 258 | ret.x = (void*) x; |
189 | |||
190 | return ret; | 259 | return ret; |
191 | } | 260 | } |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 3b45a89f..45760b1c 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -91,7 +91,7 @@ static void init_term() { | |||
91 | cbreak(); | 91 | cbreak(); |
92 | keypad(stdscr, 1); | 92 | keypad(stdscr, 1); |
93 | noecho(); | 93 | noecho(); |
94 | timeout(2000); | 94 | timeout(100); |
95 | 95 | ||
96 | if(has_colors()) { | 96 | if(has_colors()) { |
97 | start_color(); | 97 | start_color(); |
@@ -255,15 +255,15 @@ static void draw_bar() { | |||
255 | attron(A_BOLD); | 255 | attron(A_BOLD); |
256 | } | 256 | } |
257 | 257 | ||
258 | odd = (odd+1) % 2; | 258 | odd = (odd+1) % 10; |
259 | 259 | ||
260 | if(windows[i].blink && odd) { | 260 | if(windows[i].blink && (odd < 5)) { |
261 | attron(COLOR_PAIR(3)); | 261 | attron(COLOR_PAIR(3)); |
262 | } | 262 | } |
263 | 263 | ||
264 | printw(" %s", windows[i].title); | 264 | printw(" %s", windows[i].title); |
265 | 265 | ||
266 | if(windows[i].blink && odd) { | 266 | if(windows[i].blink && (odd < 5)) { |
267 | attron(COLOR_PAIR(3)); | 267 | attron(COLOR_PAIR(3)); |
268 | } | 268 | } |
269 | 269 | ||
@@ -288,7 +288,9 @@ int main(int argc, char* argv[]) { | |||
288 | ToxWindow* a; | 288 | ToxWindow* a; |
289 | 289 | ||
290 | for(i = 0; i < argc; i++) { | 290 | for(i = 0; i < argc; i++) { |
291 | if(argv[i][0] == '-') { | 291 | if (argv[i] == NULL){ |
292 | break; | ||
293 | } else if(argv[i][0] == '-') { | ||
292 | if(argv[i][1] == 'f') { | 294 | if(argv[i][1] == 'f') { |
293 | if(argv[i + 1] != NULL) | 295 | if(argv[i + 1] != NULL) |
294 | filename = argv[i + 1]; | 296 | filename = argv[i + 1]; |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 1db60883..463b9352 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -89,7 +89,9 @@ static void execute(ToxWindow* self, char* cmd) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | dht.ip.i = resolved_address; | 91 | dht.ip.i = resolved_address; |
92 | DHT_bootstrap(dht, hex_string_to_bin(key)); | 92 | unsigned char *binary_string = hex_string_to_bin(key); |
93 | DHT_bootstrap(dht, binary_string); | ||
94 | free(binary_string); | ||
93 | } | 95 | } |
94 | else if(!strncmp(cmd, "add ", strlen("add "))) { | 96 | else if(!strncmp(cmd, "add ", strlen("add "))) { |
95 | uint8_t id_bin[32]; | 97 | uint8_t id_bin[32]; |
@@ -148,7 +150,7 @@ static void execute(ToxWindow* self, char* cmd) { | |||
148 | wprintw(self->window, "Friend request already sent.\n"); | 150 | wprintw(self->window, "Friend request already sent.\n"); |
149 | break; | 151 | break; |
150 | case -5: | 152 | case -5: |
151 | wprintw(self->window, "[i] Undefined error when adding friend.\n"); | 153 | wprintw(self->window, "Undefined error when adding friend.\n"); |
152 | break; | 154 | break; |
153 | default: | 155 | default: |
154 | wprintw(self->window, "Friend added as %d.\n", num); | 156 | wprintw(self->window, "Friend added as %d.\n", num); |
@@ -178,12 +180,13 @@ static void execute(ToxWindow* self, char* cmd) { | |||
178 | 180 | ||
179 | nick = strchr(cmd, ' '); | 181 | nick = strchr(cmd, ' '); |
180 | if(nick == NULL) { | 182 | if(nick == NULL) { |
183 | wprintw(self->window, "Invalid syntax.\n"); | ||
181 | return; | 184 | return; |
182 | } | 185 | } |
183 | nick++; | 186 | nick++; |
184 | 187 | ||
185 | setname((uint8_t*) nick, strlen(nick)+1); | 188 | setname((uint8_t*) nick, strlen(nick)+1); |
186 | wprintw(self->window, "Nickname set to: %s.\n", nick); | 189 | wprintw(self->window, "Nickname set to: %s\n", nick); |
187 | } | 190 | } |
188 | else if(!strcmp(cmd, "myid")) { | 191 | else if(!strcmp(cmd, "myid")) { |
189 | char id[32*2 + 1] = {0}; | 192 | char id[32*2 + 1] = {0}; |
@@ -195,7 +198,7 @@ static void execute(ToxWindow* self, char* cmd) { | |||
195 | strcat(id, xx); | 198 | strcat(id, xx); |
196 | } | 199 | } |
197 | 200 | ||
198 | wprintw(self->window, "%s\n", id); | 201 | wprintw(self->window, "Your ID: %s\n", id); |
199 | } | 202 | } |
200 | else if(!strncmp(cmd, "accept ", strlen("accept "))) { | 203 | else if(!strncmp(cmd, "accept ", strlen("accept "))) { |
201 | char* id; | 204 | char* id; |
@@ -251,20 +254,18 @@ static void execute(ToxWindow* self, char* cmd) { | |||
251 | wprintw(self->window, "Message successfully sent.\n"); | 254 | wprintw(self->window, "Message successfully sent.\n"); |
252 | } | 255 | } |
253 | } | 256 | } |
257 | |||
254 | else { | 258 | else { |
255 | wprintw(self->window, "Invalid syntax.\n"); | 259 | wprintw(self->window, "Invalid command.\n"); |
256 | } | 260 | } |
257 | } | 261 | } |
258 | 262 | ||
259 | static void prompt_onKey(ToxWindow* self, int key) { | 263 | static void prompt_onKey(ToxWindow* self, int key) { |
260 | |||
261 | // PRINTABLE characters: Add to line. | 264 | // PRINTABLE characters: Add to line. |
262 | if(isprint(key)) { | 265 | if(isprint(key)) { |
263 | |||
264 | if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { | 266 | if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { |
265 | return; | 267 | return; |
266 | } | 268 | } |
267 | |||
268 | prompt_buf[prompt_buf_pos++] = key; | 269 | prompt_buf[prompt_buf_pos++] = key; |
269 | prompt_buf[prompt_buf_pos] = 0; | 270 | prompt_buf[prompt_buf_pos] = 0; |
270 | } | 271 | } |
@@ -273,14 +274,12 @@ static void prompt_onKey(ToxWindow* self, int key) { | |||
273 | else if(key == '\n') { | 274 | else if(key == '\n') { |
274 | wprintw(self->window, "\n"); | 275 | wprintw(self->window, "\n"); |
275 | execute(self, prompt_buf); | 276 | execute(self, prompt_buf); |
276 | |||
277 | prompt_buf_pos = 0; | 277 | prompt_buf_pos = 0; |
278 | prompt_buf[0] = 0; | 278 | prompt_buf[0] = 0; |
279 | } | 279 | } |
280 | 280 | ||
281 | // BACKSPACE key: Remove one character from line. | 281 | // BACKSPACE key: Remove one character from line. |
282 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { | 282 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { |
283 | |||
284 | if(prompt_buf_pos != 0) { | 283 | if(prompt_buf_pos != 0) { |
285 | prompt_buf[--prompt_buf_pos] = 0; | 284 | prompt_buf[--prompt_buf_pos] = 0; |
286 | } | 285 | } |