From 5817c2c888ec930b8adfca78cd4fd5b026a1ccfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Malte=20Gr=C3=A4fje?= Date: Sun, 4 Aug 2013 01:46:54 +0200 Subject: [PATCH 01/13] fix for #288 nTox will now display a message if you try to accept a not yet received or already accepted friend request --- testing/nTox.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 15e209a9..f76c6c2a 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -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) @@ -229,15 +234,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(); } @@ -330,7 +341,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(); } From 0259cb0194901c7d85ea7cd7749fdeed5a6d3761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Malte=20Gr=C3=A4fje?= Date: Sun, 4 Aug 2013 13:01:20 +0200 Subject: [PATCH 02/13] added fix in nTox_win32.c --- testing/nTox.c | 2 +- testing/nTox_win32.c | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index f76c6c2a..eabb3f28 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -234,7 +234,7 @@ void line_eval(char *line) else if (inpt_command == 'a') { uint8_t numf = atoi(line + 3); char numchar[100]; - if(numf >= num_requests || pending_requests[numf].accepted) { + 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 { diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 5501ecf5..f3c7a188 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -26,7 +26,12 @@ #include -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) From 8680cf76bfee0fe21529d6f4747801d246be177f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 23:01:11 +0200 Subject: [PATCH 03/13] Make private functions in core/net_crypto.c static --- core/net_crypto.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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, } /* 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) { @@ -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) { From 2a9fedc08f4ebaa210f94041a99eb6d11c0ce45c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:47:16 +0200 Subject: [PATCH 04/13] Make private functions in core/Lossless_UDP.c static --- core/Lossless_UDP.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) 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]; * * 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; @@ -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() { uint32_t i; uint64_t temp_time = current_time(); @@ -817,7 +817,7 @@ void doNew() } } -void doSYNC() +static void doSYNC() { uint32_t i; uint64_t temp_time = current_time(); @@ -830,7 +830,7 @@ void doSYNC() } } -void doData() +static void doData() { uint32_t i; uint64_t j; @@ -851,7 +851,7 @@ void doData() * * TODO: flow control. */ -void adjustRates() +static void adjustRates() { uint32_t i; uint64_t temp_time = current_time(); From c387de52b2a711f05ae2c9c8652e441038289c3d Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:38:46 +0200 Subject: [PATCH 05/13] Make private functions in core/LAN_discovery.c static --- core/LAN_discovery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 @@ /* 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() { 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; From 7567e0a1c4a73731856639f3133d9ffa8a771bc0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:31:26 +0200 Subject: [PATCH 06/13] Make private functions in core/DHT.c static --- core/DHT.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) 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]; * 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; @@ -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) From f03dc44e97e993024e42b3a0915de6401d9cecb0 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 4 Aug 2013 21:20:48 -0400 Subject: [PATCH 07/13] Fixed Windows build --- CMakeLists.txt | 4 ++-- cmake/FindSODIUM.cmake | 4 +++- core/CMakeLists.txt | 4 ++++ testing/CMakeLists.txt | 5 ++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07098391..f2657fc5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,11 +25,11 @@ 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}) + find_package(SODIUM REQUIRED) + set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY}) endif() macro(linkCoreLibraries exe_name) diff --git a/cmake/FindSODIUM.cmake b/cmake/FindSODIUM.cmake index fd6206ff..ff9bc27b 100644 --- a/cmake/FindSODIUM.cmake +++ b/cmake/FindSODIUM.cmake @@ -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 @@ -48,6 +49,7 @@ find_path(SODIUM_INCLUDE_DIR find_library(SODIUM_LIBRARY NAMES sodium + libsodium.a PATHS ${SODIUM_ROOT_DIR}/lib ) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 5bd496cb..c7016a49 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,3 +18,7 @@ set(core_sources add_library(toxcore SHARED ${core_sources}) target_link_libraries(toxcore ${SODIUM_LIBRARY}) + +if(WIN32) + target_link_libraries(toxcore ws2_32) +endif() 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) 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() From 03a2bac3190b7044e8cbd66339c6f9d76bfc48ef Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 4 Aug 2013 21:38:12 -0400 Subject: [PATCH 08/13] Improved cmake --- CMakeLists.txt | 36 ++++++++++++++++++------------------ cmake/FindSODIUM.cmake | 8 +++++++- core/CMakeLists.txt | 15 +++++++-------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2657fc5..f56cd67a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -27,23 +37,13 @@ if(NOT WIN32) endif() endif() -if(NOT USE_NACL) - find_package(SODIUM REQUIRED) - 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() diff --git a/cmake/FindSODIUM.cmake b/cmake/FindSODIUM.cmake index ff9bc27b..2db0f667 100644 --- a/cmake/FindSODIUM.cmake +++ b/cmake/FindSODIUM.cmake @@ -46,10 +46,16 @@ 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 - libsodium.a PATHS ${SODIUM_ROOT_DIR}/lib ) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c7016a49..eacb772c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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,8 +10,13 @@ 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) From ca3380ba2f50a8b793c795d5bbc815179b10375e Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 4 Aug 2013 22:29:09 -0400 Subject: [PATCH 09/13] Added cmake options into INSTALL --- INSTALL.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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 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: From 5617bf0bf1827733a9118a0f3ca866cf5353b1e0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 5 Aug 2013 15:57:17 +0200 Subject: [PATCH 10/13] Use void for functions with no parameters --- core/DHT.c | 12 ++++++------ core/DHT.h | 4 ++-- core/LAN_discovery.c | 2 +- core/Lossless_UDP.c | 14 +++++++------- core/Lossless_UDP.h | 4 ++-- core/Messenger.c | 12 ++++++------ core/Messenger.h | 6 +++--- core/net_crypto.c | 12 ++++++------ core/net_crypto.h | 6 +++--- core/network.c | 6 +++--- core/network.h | 6 +++--- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/core/DHT.c b/core/DHT.c index 68ec95d7..6375b86b 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -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(); @@ -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(); diff --git a/core/DHT.h b/core/DHT.h index 36670ed5..0edaebf3 100644 --- a/core/DHT.h +++ b/core/DHT.h @@ -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); diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c index 67cbfe9a..55953685 100644 --- a/core/LAN_discovery.c +++ b/core/LAN_discovery.c @@ -76,7 +76,7 @@ static uint32_t get_broadcast(void) #endif /* Return the broadcast ip */ -static IP broadcast_ip() +static IP broadcast_ip(void) { IP ip; #ifdef __linux diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 8538f76c..3a289735 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c @@ -284,7 +284,7 @@ static 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) @@ -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 */ -static void doNew() +static void doNew(void) { uint32_t i; uint64_t temp_time = current_time(); @@ -817,7 +817,7 @@ static void doNew() } } -static void doSYNC() +static void doSYNC(void) { uint32_t i; uint64_t temp_time = current_time(); @@ -830,7 +830,7 @@ static void doSYNC() } } -static void doData() +static void doData(void) { uint32_t i; uint64_t j; @@ -851,7 +851,7 @@ static void doData() * * TODO: flow control. */ -static void adjustRates() +static void adjustRates(void) { uint32_t i; uint64_t temp_time = current_time(); @@ -871,7 +871,7 @@ static void adjustRates() } /* Call this function a couple times per second It's the main loop. */ -void doLossless_UDP() +void doLossless_UDP(void) { doNew(); 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); * 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. 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)) #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; 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)); /* 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); diff --git a/core/net_crypto.c b/core/net_crypto.c index 4ce173c5..1c56b95a 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -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); } @@ -479,7 +479,7 @@ static 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 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); /* 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 } 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 @@ #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); 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 { } 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(): From d1f84efdd776aab2f2278755b3014835e58ed912 Mon Sep 17 00:00:00 2001 From: Luke Champine Date: Mon, 5 Aug 2013 11:22:47 -0400 Subject: [PATCH 11/13] temporary fix to prevent m_addfriend from segfaulting --- core/Messenger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index dee6eefc..57d485bb 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -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; From 39545a92dab828d2342c5e4160f30da320d81748 Mon Sep 17 00:00:00 2001 From: Nominate Date: Mon, 5 Aug 2013 18:33:16 +0100 Subject: [PATCH 12/13] Added a 'clear' function to the prompt --- testing/toxic/prompt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 463b9352..c28980c4 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -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"); From 42c79dfcbb871163228495a544b72bdcc916cd53 Mon Sep 17 00:00:00 2001 From: Nominate Date: Mon, 5 Aug 2013 18:52:28 +0100 Subject: [PATCH 13/13] Grammar/aesthetic amendment --- testing/toxic/prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index c28980c4..e5dc5086 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -318,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"); + 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");