summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJfreegman <Jfreegman@gmail.com>2013-08-05 02:33:15 -0400
committerJfreegman <Jfreegman@gmail.com>2013-08-05 02:33:15 -0400
commit17f121c58eb5acb61140440224629199eb835f98 (patch)
treec375875e00f555641f0671a4652b71cd51fbecff
parente479f338c18abdafae88c5f02b9996659d1fd6a7 (diff)
parent5e43dc7bd8c790a43c22fd6ab47e9dbef9205186 (diff)
Merge branch 'master' of https://github.com/irungentoo/ProjectTox-Core into testing
-rwxr-xr-xCMakeLists.txt36
-rw-r--r--INSTALL.md8
-rw-r--r--cmake/FindSODIUM.cmake10
-rw-r--r--core/CMakeLists.txt19
-rw-r--r--core/DHT.c44
-rw-r--r--core/LAN_discovery.c8
-rw-r--r--core/Lossless_UDP.c38
-rw-r--r--core/net_crypto.c10
-rw-r--r--testing/CMakeLists.txt5
-rw-r--r--testing/nTox.c4
-rw-r--r--testing/toxic/chat.c1
11 files changed, 101 insertions, 82 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
3set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 3set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
4 4
5if(UNIX) 5option(SHARED_TOXCORE "Build Core as a shared library")
6 find_package(Curses REQUIRED)
7endif()
8 6
9if(NOT WIN32) 7if(WIN32)
8 option(SHARED_LIBSODIUM "Links libsodium as a shared library")
9else()
10 option(USE_NACL "Use NaCl library instead of libsodium") 10 option(USE_NACL "Use NaCl library instead of libsodium")
11endif() 11endif()
12 12
13if(UNIX)
14 find_package(Curses REQUIRED)
15endif()
16
13if(USE_NACL) 17if(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})
24else()
25 find_package(SODIUM REQUIRED)
26
27 include_directories(${SODIUM_INCLUDE_DIR})
28
29 set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
20endif() 30endif()
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)
29endif()
30
31if(NOT USE_NACL)
32 set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
33endif() 38endif()
34 39
35macro(linkCoreLibraries exe_name) 40macro(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()
48endmacro() 48endmacro()
49 49
diff --git a/INSTALL.md b/INSTALL.md
index 483928b0..8c7147fa 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -60,6 +60,10 @@ cd ProjectTox-Core
60mkdir build && cd build 60mkdir build && cd build
61cmake .. 61cmake ..
62``` 62```
63Advance 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
63Note 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.
64 68
65Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: 69Then 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:
143mkdir build && cd build 147mkdir build && cd build
144cmake -G "MinGW Makefiles" .. 148cmake -G "MinGW Makefiles" ..
145``` 149```
150Advance 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
146Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. 154Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
147 155
148Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: 156Then 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
27set(_SODIUM_ROOT_PATHS 27set(_SODIUM_ROOT_PATHS
28 "$ENV{PROGRAMFILES}/sodium" 28 "$ENV{PROGRAMFILES}/sodium"
29 "${CMAKE_SOURCE_DIR}/sodium"
29) 30)
30 31
31find_path(SODIUM_ROOT_DIR 32find_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
49if(SHARED_LIBSODIUM)
50 set(WIN32_LIBSODIUM_FILENAME libsodium.dll.a)
51else()
52 set(WIN32_LIBSODIUM_FILENAME libsodium.a)
53endif()
54
48find_library(SODIUM_LIBRARY 55find_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 @@
1cmake_minimum_required(VERSION 2.6.0) 1cmake_minimum_required(VERSION 2.6.0)
2project(toxcore C) 2project(toxcore C)
3 3
4if(WIN32)
5 include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
6else(WIN32)
7 include_directories(${SODIUM_INCLUDE_DIR})
8endif()
9
10set(core_sources 4set(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
19add_library(toxcore SHARED ${core_sources}) 13if(SHARED_TOXCORE)
20target_link_libraries(toxcore ${SODIUM_LIBRARY}) 14 add_library(toxcore SHARED ${core_sources})
15else()
16 add_library(toxcore ${core_sources})
17endif()
18
19target_link_libraries(toxcore ${LINK_CRYPTO_LIBRARY})
20
21if(WIN32)
22 target_link_libraries(toxcore ws2_32)
23endif()
diff --git a/core/DHT.c b/core/DHT.c
index 08b4710e..68ec95d7 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -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 */
122int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) 122static 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
140int ipport_equal(IP_Port a, IP_Port b) 140static 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
145int id_equal(uint8_t* a, uint8_t* b) 145static 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
150int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) 150static 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 */
162int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port) 162static 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 */
187int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) 187static 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 */
218int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) 218static 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 */
304int replace_bad( Client_data * list, 304static 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 */
328int replace_good( Client_data * list, 328static 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 */
354void addto_lists(IP_Port ip_port, uint8_t * client_id) 354static 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 */
396void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id) 396static 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 */
434int is_pinging(IP_Port ip_port, uint64_t ping_id) 434static 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. */
459int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) 459static 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 */
489uint64_t add_pinging(IP_Port ip_port) 489static 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 */
510uint64_t add_gettingnodes(IP_Port ip_port) 510static 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 */
679int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) 679static 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
705int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) 705static 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
732int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) 732static 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
764int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) 764static 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;
@@ -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*/
1032int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) 1032static 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
1082int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) 1082static 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 */
1108int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) 1108static 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)
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c
index 72e00d32..67cbfe9a 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 */
32uint32_t get_broadcast(void) 32static 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 */
79IP broadcast_ip() 79static IP broadcast_ip()
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 */
95int LAN_ip(IP ip) 95static 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
110int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source) 110static 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..8538f76c 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 */
152uint32_t handshake_id(IP_Port source) 152static 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 */
171void change_handshake(IP_Port source) 171static 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 */
237int new_inconnection(IP_Port ip_port) 237static 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;
@@ -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
473int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) 473static 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
487int send_SYNC(uint32_t connection_id) 487static 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
514int send_data_packet(uint32_t connection_id, uint32_t packet_num) 514static 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 */
529int send_DATA(uint32_t connection_id) 529static 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. */
558int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) 558static 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. */
594int SYNC_valid(uint32_t length) 594static 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: */
605int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) 605static 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: */
625int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) 625static 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: */
638int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, 638static 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
672int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) 672static 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 */
711int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) 711static 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
745int handle_data(uint8_t *packet, uint32_t length, IP_Port source) 745static 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 */
796void doNew() 796static void doNew()
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
820void doSYNC() 820static void doSYNC()
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
833void doData() 833static void doData()
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 */
854void adjustRates() 854static void adjustRates()
855{ 855{
856 uint32_t i; 856 uint32_t i;
857 uint64_t temp_time = current_time(); 857 uint64_t temp_time = current_time();
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 561ba866..4ce173c5 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 */
129void increment_nonce(uint8_t *nonce) 129static 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 */
246int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) 246static 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 */
269int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, 269static 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 */
298int getcryptconnection_id(uint8_t *public_key) 298static 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) {
@@ -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 */
468int new_incoming(int id) 468static 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) {
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)
8include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake) 8include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
9include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) 9include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
10include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) 10include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
11
11if(WIN32) 12if(WIN32)
12 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) 13 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
13endif() 14else()
14
15if(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)
18endif() 17endif()
diff --git a/testing/nTox.c b/testing/nTox.c
index 072c17e3..ec597bc3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -428,7 +428,9 @@ int main(int argc, char *argv[])
428 } 428 }
429 429
430 for(i = 0; i < argc; i++) { 430 for(i = 0; i < argc; i++) {
431 if(argv[i][0] == '-') { 431 if (argv[i] == NULL){
432 break;
433 } else if(argv[i][0] == '-') {
432 if(argv[i][1] == 'h') { 434 if(argv[i][1] == 'h') {
433 print_help(); 435 print_help();
434 exit(0); 436 exit(0);
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index eb297f7c..2c1f1072 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -265,6 +265,5 @@ ToxWindow new_chat(int friendnum) {
265 x->friendnum = friendnum; 265 x->friendnum = friendnum;
266 266
267 ret.x = (void*) x; 267 ret.x = (void*) x;
268 free(x);
269 return ret; 268 return ret;
270} 269}