Merge branch 'master' of git://github.com/irungentoo/ProjectTox-Core

This commit is contained in:
charmlesscoin 2013-08-05 16:11:37 -04:00
commit d925505066
19 changed files with 185 additions and 136 deletions

View File

@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 2.6.0)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(UNIX)
find_package(Curses REQUIRED)
option(SHARED_TOXCORE "Build Core as a shared library")
if(WIN32)
option(SHARED_LIBSODIUM "Links libsodium as a shared library")
else()
option(USE_NACL "Use NaCl library instead of libsodium")
endif()
if(NOT WIN32)
option(USE_NACL "Use NaCl library instead of libsodium")
if(UNIX)
find_package(Curses REQUIRED)
endif()
if(USE_NACL)
@ -17,6 +21,12 @@ if(USE_NACL)
add_definitions(-DVANILLA_NACL)
set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES})
else()
find_package(SODIUM REQUIRED)
include_directories(${SODIUM_INCLUDE_DIR})
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
#MinGW prints more warnings for -Wall than gcc does, thus causing build to fail
@ -25,25 +35,15 @@ if(NOT WIN32)
message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
endif()
find_package(SODIUM REQUIRED)
endif()
if(NOT USE_NACL)
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
macro(linkCoreLibraries exe_name)
add_dependencies(${exe_name} toxcore)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
target_link_libraries(${exe_name} toxcore
${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a
ws2_32)
else()
include_directories(${SODIUM_INCLUDE_DIR})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(${exe_name} ws2_32)
endif()
endmacro()

View File

@ -60,6 +60,10 @@ cd ProjectTox-Core
mkdir build && cd build
cmake ..
```
Advance cmake options:
- `-DSHARED_TOXCORE=ON` (default `OFF`) — Build Core as a shared library.
- `-DUSE_NACL=ON` (default `OFF`) — Use NaCl library instead of libsodium.
Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
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:
mkdir build && cd build
cmake -G "MinGW Makefiles" ..
```
Advance cmake options:
- `-DSHARED_TOXCORE=ON` (default OFF) — Build Core as a shared library.
- `-DSHARED_LIBSODIUM=ON` (default OFF) — Link libsodium as a shared library.
Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running:

View File

@ -26,11 +26,12 @@ set(_SODIUM_ROOT_HINTS
set(_SODIUM_ROOT_PATHS
"$ENV{PROGRAMFILES}/sodium"
"${CMAKE_SOURCE_DIR}/sodium"
)
find_path(SODIUM_ROOT_DIR
NAMES
include/cmocka.h
include/sodium.h
HINTS
${_SODIUM_ROOT_HINTS}
PATHS
@ -45,8 +46,15 @@ find_path(SODIUM_INCLUDE_DIR
${SODIUM_ROOT_DIR}/include
)
if(SHARED_LIBSODIUM)
set(WIN32_LIBSODIUM_FILENAME libsodium.dll.a)
else()
set(WIN32_LIBSODIUM_FILENAME libsodium.a)
endif()
find_library(SODIUM_LIBRARY
NAMES
${WIN32_LIBSODIUM_FILENAME}
sodium
PATHS
${SODIUM_ROOT_DIR}/lib

View File

@ -1,12 +1,6 @@
cmake_minimum_required(VERSION 2.6.0)
project(toxcore C)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
else(WIN32)
include_directories(${SODIUM_INCLUDE_DIR})
endif()
set(core_sources
DHT.c
network.c
@ -16,5 +10,14 @@ set(core_sources
LAN_discovery.c
Messenger.c)
add_library(toxcore SHARED ${core_sources})
target_link_libraries(toxcore ${SODIUM_LIBRARY})
if(SHARED_TOXCORE)
add_library(toxcore SHARED ${core_sources})
else()
add_library(toxcore ${core_sources})
endif()
target_link_libraries(toxcore ${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(toxcore ws2_32)
endif()

View File

@ -119,7 +119,7 @@ static Pinged send_nodes[LSEND_NODES_ARRAY];
* return 1 if client_id1 is closer
* return 2 if client_id2 is closer
*/
int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2)
static int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2)
{
size_t i;
uint8_t distance1, distance2;
@ -137,17 +137,17 @@ int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2)
return 0;
}
int ipport_equal(IP_Port a, IP_Port b)
static int ipport_equal(IP_Port a, IP_Port b)
{
return (a.ip.i == b.ip.i) && (a.port == b.port);
}
int id_equal(uint8_t* a, uint8_t* b)
static int id_equal(uint8_t* a, uint8_t* b)
{
return memcmp(a, b, CLIENT_ID_SIZE) == 0;
}
int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout)
static int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout)
{
return timestamp + timeout <= time_now;
}
@ -159,7 +159,7 @@ int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout)
*
* TODO: maybe optimize this.
*/
int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port)
static int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port)
{
uint32_t i;
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_
/* check if client with client_id is already in node format list of length length.
* return True(1) or False(0)
*/
int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id)
static int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id)
{
uint32_t i;
@ -215,7 +215,7 @@ static int friend_number(uint8_t * client_id)
*
* TODO: For the love of based Allah make this function cleaner and much more efficient.
*/
int get_close_nodes(uint8_t * client_id, Node_format * nodes_list)
static int get_close_nodes(uint8_t * client_id, Node_format * nodes_list)
{
uint32_t i, j, k;
uint64_t temp_time = unix_time();
@ -301,7 +301,7 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list)
* return 0 if successful
* return 1 if not (list contains no bad nodes)
*/
int replace_bad( Client_data * list,
static int replace_bad( Client_data * list,
uint32_t length,
uint8_t * client_id,
IP_Port ip_port )
@ -325,7 +325,7 @@ int replace_bad( Client_data * list,
}
/* replace the first good node that is further to the comp_client_id than that of the client_id in the list */
int replace_good( Client_data * list,
static int replace_good( Client_data * list,
uint32_t length,
uint8_t * client_id,
IP_Port ip_port,
@ -351,7 +351,7 @@ int replace_good( Client_data * list,
/* Attempt to add client with ip_port and client_id to the friends client list
* and close_clientlist
*/
void addto_lists(IP_Port ip_port, uint8_t * client_id)
static void addto_lists(IP_Port ip_port, uint8_t * client_id)
{
uint32_t i;
@ -393,7 +393,7 @@ void addto_lists(IP_Port ip_port, uint8_t * client_id)
/* If client_id is a friend or us, update ret_ip_port
* nodeclient_id is the id of the node that sent us this info
*/
void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id)
static void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id)
{
uint32_t i, j;
uint64_t temp_time = unix_time();
@ -431,7 +431,7 @@ void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient
*
* TODO: optimize this
*/
int is_pinging(IP_Port ip_port, uint64_t ping_id)
static int is_pinging(IP_Port ip_port, uint64_t ping_id)
{
uint32_t i;
uint8_t pinging;
@ -456,7 +456,7 @@ int is_pinging(IP_Port ip_port, uint64_t ping_id)
}
/* Same as last function but for get_node requests. */
int is_gettingnodes(IP_Port ip_port, uint64_t ping_id)
static int is_gettingnodes(IP_Port ip_port, uint64_t ping_id)
{
uint32_t i;
uint8_t pinging;
@ -486,7 +486,7 @@ int is_gettingnodes(IP_Port ip_port, uint64_t ping_id)
*
* TODO: optimize this
*/
uint64_t add_pinging(IP_Port ip_port)
static uint64_t add_pinging(IP_Port ip_port)
{
uint32_t i, j;
uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int();
@ -507,7 +507,7 @@ uint64_t add_pinging(IP_Port ip_port)
}
/* Same but for get node requests */
uint64_t add_gettingnodes(IP_Port ip_port)
static uint64_t add_gettingnodes(IP_Port ip_port)
{
uint32_t i, j;
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,
/* Packet handling functions, one to handle each types of packets we receive
* Returns 0 if handled correctly, 1 if packet is bad.
*/
int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source)
{
uint64_t ping_id;
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)
return 0;
}
int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source)
{
uint64_t ping_id;
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)
return 1;
}
int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source)
{
uint64_t ping_id;
@ -761,7 +761,7 @@ int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source)
return 0;
}
int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source)
{
uint64_t ping_id;
uint32_t cid_size = 1 + CLIENT_ID_SIZE;
@ -873,7 +873,7 @@ IP_Port DHT_getfriendip(uint8_t * client_id)
/* Ping each client in the "friends" list every 60 seconds. Send a get nodes request
* every 20 seconds to a random good node for each "friend" in our "friends" list.
*/
void doDHTFriends()
static void doDHTFriends(void)
{
uint32_t i, j;
uint64_t temp_time = unix_time();
@ -912,7 +912,7 @@ static uint64_t close_lastgetnodes;
/* Ping each client in the close nodes list every 60 seconds.
* Send a get nodes request every 20 seconds to a random good node in the list.
*/
void doClose()
static void doClose(void)
{
uint32_t i;
uint64_t temp_time = unix_time();
@ -1029,7 +1029,7 @@ int route_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length)
/* Send the following packet to one random person who tells us they are connected to friend_id
* returns the number of nodes it sent the packet to
*/
int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length)
static int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length)
{
int num = friend_number(friend_id);
if (num == -1)
@ -1079,7 +1079,7 @@ int friend_ips(IP_Port * ip_portlist, uint8_t * friend_id)
/*----------------------------------------------------------------------------------*/
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/
int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type)
static int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type)
{
uint8_t data[sizeof(uint64_t) + 1];
uint8_t packet[MAX_DATA_SIZE];
@ -1105,7 +1105,7 @@ int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type)
}
/* Handle a recieved ping request for */
int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source)
{
if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING
&& 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
friends_list[friend_num].punching_index = i;
}
static void doNAT()
static void doNAT(void)
{
uint32_t i;
uint64_t temp_time = unix_time();
@ -1275,7 +1275,7 @@ int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source)
return 0;
}
void doDHT()
void doDHT(void)
{
doClose();
doDHTFriends();
@ -1283,7 +1283,7 @@ void doDHT()
}
/* get the size of the DHT (for saving) */
uint32_t DHT_size()
uint32_t DHT_size(void)
{
return sizeof(close_clientlist) + sizeof(Friend) * num_friends;
}
@ -1341,7 +1341,7 @@ int DHT_load(uint8_t * data, uint32_t size)
/* returns 0 if we are not connected to the DHT
* returns 1 if we are
*/
int DHT_isconnected()
int DHT_isconnected(void)
{
uint32_t i;
uint64_t temp_time = unix_time();

View File

@ -58,7 +58,7 @@ int DHT_delfriend(uint8_t *client_id);
IP_Port DHT_getfriendip(uint8_t *client_id);
/* Run this function at least a couple times per second (It's the main loop) */
void doDHT();
void doDHT(void);
/* if we receive a DHT packet we call this function so it can be handled.
return 0 if packet is handled correctly.
@ -90,7 +90,7 @@ int friend_ips(IP_Port *ip_portlist, uint8_t *friend_id);
/* SAVE/LOAD functions */
/* get the size of the DHT (for saving) */
uint32_t DHT_size();
uint32_t DHT_size(void);
/* save the DHT in data where data is an array of size DHT_size() */
void DHT_save(uint8_t *data);

View File

@ -29,7 +29,7 @@
/* get the first working broadcast address that's not from "lo"
* returns higher than 0 on success
* returns 0 on error */
uint32_t get_broadcast(void)
static uint32_t get_broadcast(void)
{
/* not sure how many platforms this will
* run on, so it's wrapped in __linux for now */
@ -76,7 +76,7 @@ uint32_t get_broadcast(void)
#endif
/* Return the broadcast ip */
IP broadcast_ip()
static IP broadcast_ip(void)
{
IP ip;
#ifdef __linux
@ -92,7 +92,7 @@ IP broadcast_ip()
/*return 0 if ip is a LAN ip
return -1 if it is not */
int LAN_ip(IP ip)
static int LAN_ip(IP ip)
{
if (ip.c[0] == 127)/* Loopback */
return 0;
@ -107,7 +107,7 @@ int LAN_ip(IP ip)
return -1;
}
int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source)
static int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source)
{
if (LAN_ip(source.ip) == -1)
return 1;

View File

@ -149,7 +149,7 @@ static uint32_t randtable[6][256];
*
* TODO: make this better
*/
uint32_t handshake_id(IP_Port source)
static uint32_t handshake_id(IP_Port source)
{
uint32_t id = 0, i;
for (i = 0; i < 6; ++i) {
@ -168,7 +168,7 @@ uint32_t handshake_id(IP_Port source)
*
* TODO: make this better
*/
void change_handshake(IP_Port source)
static void change_handshake(IP_Port source)
{
uint8_t rand = random_int() % 4;
randtable[rand][((uint8_t *)&source)[rand]] = random_int();
@ -234,7 +234,7 @@ int new_connection(IP_Port ip_port)
* Returns an integer corresponding to the connection id.
* Return -1 if it could not initialize the connection.
*/
int new_inconnection(IP_Port ip_port)
static int new_inconnection(IP_Port ip_port)
{
if (getconnection_id(ip_port) != -1)
return -1;
@ -284,7 +284,7 @@ int new_inconnection(IP_Port ip_port)
* Returns an integer corresponding to the next connection in our incoming connection list.
* Return -1 if there are no new incoming connections in the list.
*/
int incoming_connection()
int incoming_connection(void)
{
uint32_t i;
for (i = 0; i < MAX_CONNECTIONS; ++i) {
@ -298,7 +298,7 @@ int incoming_connection()
}
/* Try to free some memory from the connections array. */
static void free_connections()
static void free_connections(void)
{
uint32_t i;
for(i = connections_length; i != 0; --i)
@ -470,7 +470,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
* see http://wiki.tox.im/index.php/Lossless_UDP for more information.
*/
int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2)
static int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2)
{
uint8_t packet[1 + 4 + 4];
uint32_t temp;
@ -484,7 +484,7 @@ int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_i
return sendpacket(ip_port, packet, sizeof(packet));
}
int send_SYNC(uint32_t connection_id)
static int send_SYNC(uint32_t connection_id)
{
uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)];
uint16_t index = 0;
@ -511,7 +511,7 @@ int send_SYNC(uint32_t connection_id)
}
int send_data_packet(uint32_t connection_id, uint32_t packet_num)
static int send_data_packet(uint32_t connection_id, uint32_t packet_num)
{
uint32_t index = packet_num % MAX_QUEUE_NUM;
uint32_t temp;
@ -526,7 +526,7 @@ int send_data_packet(uint32_t connection_id, uint32_t packet_num)
}
/* sends 1 data packet */
int send_DATA(uint32_t connection_id)
static int send_DATA(uint32_t connection_id)
{
int ret;
uint32_t buffer[BUFFER_PACKET_NUM];
@ -555,7 +555,7 @@ int send_DATA(uint32_t connection_id)
/* Return 0 if handled correctly, 1 if packet is bad. */
int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source)
static int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source)
{
if (length != (1 + 4 + 4))
return 1;
@ -591,7 +591,7 @@ int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source)
}
/* returns 1 if sync packet is valid 0 if not. */
int SYNC_valid(uint32_t length)
static int SYNC_valid(uint32_t length)
{
if (length < 4 + 4 + 2)
return 0;
@ -602,7 +602,7 @@ int SYNC_valid(uint32_t length)
}
/* case 1 in handle_SYNC: */
int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum)
static int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum)
{
if (handshake_id(source) == recv_packetnum) {
int x = new_inconnection(source);
@ -622,7 +622,7 @@ int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnu
}
/* case 2 in handle_SYNC: */
int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum)
static int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum)
{
if (recv_packetnum == connections[connection_id].orecv_packetnum) {
/* && 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
return 1;
}
/* case 3 in handle_SYNC: */
int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets,
static int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets,
uint16_t number)
{
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
return 1;
}
int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source)
static int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source)
{
if (!SYNC_valid(length))
@ -708,7 +708,7 @@ int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source)
* Add a packet to the received buffer and set the recv_packetnum of the
* connection to its proper value. Return 1 if data was too big, 0 if not.
*/
int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size)
static int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size)
{
if (size > MAX_DATA_SIZE)
return 1;
@ -742,7 +742,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size)
return 0;
}
int handle_data(uint8_t *packet, uint32_t length, IP_Port source)
static int handle_data(uint8_t *packet, uint32_t length, IP_Port source)
{
int connection = getconnection_id(source);
@ -793,7 +793,7 @@ int LosslessUDP_handlepacket(uint8_t *packet, uint32_t length, IP_Port source)
* Send handshake requests
* handshake packets are sent at the same rate as SYNC packets
*/
void doNew()
static void doNew(void)
{
uint32_t i;
uint64_t temp_time = current_time();
@ -817,7 +817,7 @@ void doNew()
}
}
void doSYNC()
static void doSYNC(void)
{
uint32_t i;
uint64_t temp_time = current_time();
@ -830,7 +830,7 @@ void doSYNC()
}
}
void doData()
static void doData(void)
{
uint32_t i;
uint64_t j;
@ -851,7 +851,7 @@ void doData()
*
* TODO: flow control.
*/
void adjustRates()
static void adjustRates(void)
{
uint32_t i;
uint64_t temp_time = current_time();
@ -871,7 +871,7 @@ void adjustRates()
}
/* Call this function a couple times per second It's the main loop. */
void doLossless_UDP()
void doLossless_UDP(void)
{
doNew();
doSYNC();

View File

@ -52,7 +52,7 @@ int getconnection_id(IP_Port ip_port);
* Returns an int corresponding to the next connection in our imcoming connection list
* Return -1 if there are no new incoming connections in the list.
*/
int incoming_connection();
int incoming_connection(void);
/*
* Return -1 if it could not kill the connection.
@ -110,7 +110,7 @@ uint32_t recvqueue(int connection_id);
int is_connected(int connection_id);
/* Call this function a couple times per second It's the main loop. */
void doLossless_UDP();
void doLossless_UDP(void);
/*
* If we receive a Lossless_UDP packet, call this function so it can be handled.

View File

@ -114,7 +114,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
return FAERR_ALREADYSENT;
uint32_t i;
for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
if(friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id);
friendlist[i].status = FRIEND_ADDED;
@ -138,7 +138,7 @@ int m_addfriend_norequest(uint8_t * client_id)
if (getfriend_id(client_id) != -1)
return -1;
uint32_t i;
for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
if(friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id);
friendlist[i].status = FRIEND_REQUESTED;
@ -363,7 +363,7 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t))
#define PORT 33445
/* run this at startup */
int initMessenger()
int initMessenger(void)
{
new_keys();
m_set_userstatus((uint8_t*)"Online", sizeof("Online"));
@ -378,7 +378,7 @@ int initMessenger()
}
//TODO: make this function not suck.
static void doFriends()
static void doFriends(void)
{
/* TODO: add incoming connections and some other stuff. */
uint32_t i;
@ -464,7 +464,7 @@ static void doFriends()
}
}
static void doInbound()
static void doInbound(void)
{
uint8_t secret_nonce[crypto_box_NONCEBYTES];
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
@ -488,7 +488,7 @@ static void doInbound()
static uint64_t last_LANdiscovery;
/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/
static void LANdiscovery()
static void LANdiscovery(void)
{
if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
send_LANdiscovery(htons(PORT));
@ -498,7 +498,7 @@ static void LANdiscovery()
/* the main loop that needs to be run at least 200 times per second. */
void doMessenger()
void doMessenger(void)
{
IP_Port ip_port;
uint8_t data[MAX_UDP_PACKET_SIZE];
@ -532,7 +532,7 @@ void doMessenger()
}
/* returns the size of the messenger data (for saving) */
uint32_t Messenger_size()
uint32_t Messenger_size(void)
{
return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
+ sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends;

View File

@ -160,15 +160,15 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t));
/* run this at startup
returns 0 if no connection problems
returns -1 if there are problems */
int initMessenger();
int initMessenger(void);
/* the main loop that needs to be run at least 200 times per second */
void doMessenger();
void doMessenger(void);
/* SAVING AND LOADING FUNCTIONS: */
/* returns the size of the messenger data (for saving) */
uint32_t Messenger_size();
uint32_t Messenger_size(void);
/* save the messenger in data (must be allocated memory of size Messenger_size()) */
void Messenger_save(uint8_t *data);

View File

@ -126,7 +126,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
}
/* increment the given nonce by 1 */
void increment_nonce(uint8_t *nonce)
static void increment_nonce(uint8_t *nonce)
{
uint32_t i;
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
/* Send a crypto handshake packet containing an encrypted secret nonce and session public key
to peer with connection_id and public_key
the packet is encrypted with a random nonce which is sent in plain text with the packet */
int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key)
static int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key)
{
uint8_t temp_data[MAX_DATA_SIZE];
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
/* Extract secret nonce, session public key and public_key from a packet(data) with length length
return 1 if successful
return 0 if failure */
int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce,
static int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce,
uint8_t *session_key, uint8_t *data, uint16_t length)
{
int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES);
@ -295,7 +295,7 @@ int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce,
/* get crypto connection id from public key of peer
return -1 if there are no connections like we are looking for
return id if it found it */
int getcryptconnection_id(uint8_t *public_key)
static int getcryptconnection_id(uint8_t *public_key)
{
uint32_t i;
for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@ -440,7 +440,7 @@ int is_cryptoconnected(int crypt_connection_id)
/* Generate our public and private keys
Only call this function the first time the program starts. */
void new_keys()
void new_keys(void)
{
crypto_box_keypair(self_public_key,self_secret_key);
}
@ -465,7 +465,7 @@ void load_keys(uint8_t *keys)
adds an incoming connection to the incoming_connection list.
returns 0 if successful
returns 1 if failure */
int new_incoming(int id)
static int new_incoming(int id)
{
uint32_t i;
for (i = 0; i < MAX_INCOMING; ++i) {
@ -479,7 +479,7 @@ int new_incoming(int id)
/* TODO: optimize this
handle all new incoming connections. */
static void handle_incomings()
static void handle_incomings(void)
{
int income;
while (1) {
@ -490,7 +490,7 @@ static void handle_incomings()
}
/* handle received packets for not yet established crypto connections. */
static void receive_crypto()
static void receive_crypto(void)
{
uint32_t i;
for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@ -547,7 +547,7 @@ static void receive_crypto()
/* run this to (re)initialize net_crypto
sets all the global connection variables to their default values. */
void initNetCrypto()
void initNetCrypto(void)
{
memset(crypto_connections, 0 ,sizeof(crypto_connections));
memset(incoming_connections, -1 ,sizeof(incoming_connections));
@ -556,7 +556,7 @@ void initNetCrypto()
crypto_connections[i].number = ~0;
}
static void killTimedout()
static void killTimedout(void)
{
uint32_t i;
for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@ -570,7 +570,7 @@ static void killTimedout()
}
/* main loop */
void doNetCrypto()
void doNetCrypto(void)
{
/* TODO:check if friend requests were sent correctly
handle new incoming connections

View File

@ -110,7 +110,7 @@ int is_cryptoconnected(int crypt_connection_id);
/* Generate our public and private keys
Only call this function the first time the program starts. */
void new_keys();
void new_keys(void);
/* save the public and private keys to the keys array
Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */
@ -122,10 +122,10 @@ void load_keys(uint8_t * keys);
/* run this to (re)initialize net_crypto
sets all the global connection variables to their default values. */
void initNetCrypto();
void initNetCrypto(void);
/* main loop */
void doNetCrypto();
void doNetCrypto(void);
#ifdef __cplusplus
}

View File

@ -24,7 +24,7 @@
#include "network.h"
/* returns current UNIX time in microseconds (us). */
uint64_t current_time()
uint64_t current_time(void)
{
uint64_t time;
#ifdef WIN32
@ -46,7 +46,7 @@ uint64_t current_time()
/* return a random number
NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */
uint32_t random_int()
uint32_t random_int(void)
{
#ifndef VANILLA_NACL
//NOTE: this function comes from libsodium
@ -153,7 +153,7 @@ int init_networking(IP ip, uint16_t port)
}
/* function to cleanup networking stuff */
void shutdown_networking()
void shutdown_networking(void)
{
#ifdef WIN32
closesocket(sock);

View File

@ -90,11 +90,11 @@ typedef struct {
} ADDR;
/* returns current time in milleseconds since the epoch. */
uint64_t current_time();
uint64_t current_time(void);
/* return a random number
NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */
uint32_t random_int();
uint32_t random_int(void);
/* Basic network functions: */
@ -115,7 +115,7 @@ int receivepacket(IP_Port *ip_port, uint8_t *data, uint32_t *length);
int init_networking(IP ip, uint16_t port);
/* function to cleanup networking stuff(doesn't do much right now) */
void shutdown_networking();
void shutdown_networking(void);
/*
resolve_addr():

View File

@ -8,11 +8,10 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
if(WIN32)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
endif()
if(NOT WIN32)
else()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
add_subdirectory(toxic)
endif()

View File

@ -42,7 +42,12 @@ char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message "
"name)\n/q (to quit)";
int x, y;
uint8_t pending_requests[256][CLIENT_ID_SIZE];
typedef struct {
uint8_t id[CLIENT_ID_SIZE];
uint8_t accepted;
} Friend_request;
Friend_request pending_requests[256];
uint8_t num_requests = 0;
void get_id(char *data)
@ -231,15 +236,21 @@ void line_eval(char *line)
else if (inpt_command == 'a') {
uint8_t numf = atoi(line + 3);
char numchar[100];
int num = m_addfriend_norequest(pending_requests[numf]);
if (num != -1) {
sprintf(numchar, "[i] friend request %u accepted", numf);
new_lines(numchar);
sprintf(numchar, "[i] added friendnumber %d", num);
if (numf >= num_requests || pending_requests[numf].accepted) {
sprintf(numchar,"[i] you either didn't receive that request or you already accepted it");
new_lines(numchar);
} else {
sprintf(numchar, "[i] failed to add friend");
new_lines(numchar);
int num = m_addfriend_norequest(pending_requests[numf].id);
if (num != -1) {
pending_requests[numf].accepted = 1;
sprintf(numchar, "[i] friend request %u accepted", numf);
new_lines(numchar);
sprintf(numchar, "[i] added friendnumber %d", num);
new_lines(numchar);
} else {
sprintf(numchar, "[i] failed to add friend");
new_lines(numchar);
}
}
do_refresh();
}
@ -332,7 +343,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
char numchar[100];
sprintf(numchar, "[i] accept request with /a %u", num_requests);
new_lines(numchar);
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE);
pending_requests[num_requests].accepted = 0;
++num_requests;
do_refresh();
}

View File

@ -26,7 +26,12 @@
#include <process.h>
uint8_t pending_requests[256][CLIENT_ID_SIZE];
typedef struct {
uint8_t id[CLIENT_ID_SIZE];
uint8_t accepted;
} Friend_request;
Friend_request pending_requests[256];
uint8_t num_requests = 0;
uint32_t maxnumfriends;
@ -51,7 +56,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
char numchar[100];
sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests);
printf(numchar);
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE);
pending_requests[num_requests].accepted = 0;
++num_requests;
}
@ -287,10 +293,21 @@ void accept_friend_request()
friend_request_received = 0;
uint8_t numf = atoi(line + 3);
char numchar[100];
int num = m_addfriend_norequest(pending_requests[numf]);
sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num);
printf(numchar);
++maxnumfriends;
if (numf >= num_requests || pending_requests[numf].accepted) {
sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it");
printf(numchar);
} else {
int num = m_addfriend_norequest(pending_requests[numf].id);
if (num != -1) {
pending_requests[numf].accepted = 1;
sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num);
printf(numchar);
++maxnumfriends;
} else {
sprintf(numchar, "[i] failed to add friend");
printf(numchar);
}
}
}
void line_eval(char* line)

View File

@ -158,7 +158,9 @@ static void execute(ToxWindow* self, char* cmd) {
break;
}
}
else if(!strcmp(cmd, "clear")) {
wclear(self->window);
}
else if(!strcmp(cmd, "help")) {
print_usage(self);
}
@ -316,7 +318,7 @@ static void print_usage(ToxWindow* self) {
wprintw(self->window, " myid : Print your ID\n");
wprintw(self->window, " quit/exit : Exit program\n");
wprintw(self->window, " help : Print this message again\n");
wprintw(self->window, " clear : Clear this window\n");
wattron(self->window, A_BOLD);
wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");