From a85fce5c034d70c1a4926fd49368d2374320276e Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Sat, 3 Aug 2013 09:17:44 +0400 Subject: [PATCH 01/16] Curses dependence added to CMake --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf709e72..db1a426c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 2.6.0) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +find_package(Curses REQUIRED) + if(NOT WIN32) option(USE_NACL "Use NaCl library instead of libsodium") endif() From 5ea6b58ec4ee9874d7190dc714d505cca48603c0 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Sat, 3 Aug 2013 11:08:21 +0400 Subject: [PATCH 02/16] Curses check is now only on *nix --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db1a426c..ed934c01 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 2.6.0) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -find_package(Curses REQUIRED) +if(UNIX) + find_package(Curses REQUIRED) +endif() if(NOT WIN32) option(USE_NACL "Use NaCl library instead of libsodium") From c1a8bc52f6eddaf075436eb1a57d978a4526dd56 Mon Sep 17 00:00:00 2001 From: Astonex Date: Sat, 3 Aug 2013 11:32:58 +0100 Subject: [PATCH 03/16] Can only accept friend request when one is pending now --- testing/nTox_win32.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 3b6fb043..9c6e0aac 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -32,6 +32,7 @@ uint32_t maxnumfriends; char line[STRING_LENGTH]; char users_id[200]; +int friend_request_received; void do_header() { @@ -44,10 +45,11 @@ void do_header() void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) { + friend_request_received = 1; printf("\n\n[i] received friend request with message\n"); - printf((char *)data); + printf("'%s'",(char *)data); char numchar[100]; - sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests); + 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); ++num_requests; @@ -271,12 +273,11 @@ void change_status() void accept_friend_request() { + friend_request_received = 0; uint8_t numf = atoi(line + 3); char numchar[100]; - sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); - printf(numchar); int num = m_addfriend_norequest(pending_requests[numf]); - sprintf(numchar, "\n[i] added friendnumber %d\n\n", num); + sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); printf(numchar); ++maxnumfriends; } @@ -317,12 +318,14 @@ void line_eval(char* line) } else if (inpt_command == 'a') { - accept_friend_request(line); + if (friend_request_received == 1) + accept_friend_request(line); } /* EXIT */ else if (inpt_command == 'q') { uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline"; m_set_userstatus(status, strlen((char*)status)); + Sleep(10); exit(EXIT_SUCCESS); } } @@ -368,8 +371,7 @@ int main(int argc, char *argv[]) nameloaded = 1; printf("%s\n", name); fclose(name_file); - } - + } FILE* status_file = NULL; status_file = fopen("statusfile.txt", "r"); @@ -383,7 +385,6 @@ int main(int argc, char *argv[]) printf("%s\n", status); fclose(status_file); } - m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); From 4175f73ea8005067cc2570918d708864fa8084b1 Mon Sep 17 00:00:00 2001 From: pb82 Date: Sat, 3 Aug 2013 13:16:52 +0200 Subject: [PATCH 04/16] installation instructions for Fedora (17) --- INSTALL.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index d6a5b3f9..211226da 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,6 +18,14 @@ Build dependencies: ```bash apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake checkinstall ``` + +on Fedora: + +```bash +yum groupinstall "Development Tools" +yum install libtool autoconf automake libconfig-devel ncurses-devel cmake +``` + Note that `libconfig-dev` should be >= 1.4. You should get and install [libsodium](https://github.com/jedisct1/libsodium): @@ -31,6 +39,18 @@ sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc sudo ldconfig ``` +or without checkinstall: +```bash +git clone git://github.com/jedisct1/libsodium.git +cd libsodium +git checkout tags/0.4.2 +./autogen.sh +./configure +make +sudo make install +``` + + Then clone this repo and generate makefile: ```bash git clone git://github.com/irungentoo/ProjectTox-Core.git From e874c5b0f6170c3ec24e6abab68cc0dadeda58f8 Mon Sep 17 00:00:00 2001 From: pb82 Date: Sat, 3 Aug 2013 13:19:39 +0200 Subject: [PATCH 05/16] should be 'make check' --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 211226da..7982d3db 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -46,7 +46,7 @@ cd libsodium git checkout tags/0.4.2 ./autogen.sh ./configure -make +make check sudo make install ``` From d5493bb24f6afe7854ade088f1f4291c3ad58e9b Mon Sep 17 00:00:00 2001 From: Michael Kress Date: Sat, 3 Aug 2013 13:27:52 +0200 Subject: [PATCH 06/16] added backspace to nTox; removed trailing spaces --- testing/nTox.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 24d40ead..13db58d7 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with Tox. If not, see . - * + * */ #include "nTox.h" #include "misc_tools.h" @@ -54,7 +54,7 @@ void get_id(char *data) { if (self_public_key[i] < (PUB_KEY_BYTES / 2)) strcpy(idstring1[i],"0"); - else + else strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } @@ -71,9 +71,9 @@ void get_id(char *data) void new_lines(char *line) { int i = 0; - for (i = HISTORY-1; i > 0; i--) + for (i = HISTORY-1; i > 0; i--) strncpy(lines[i], lines[i-1], STRING_LENGTH - 1); - + strncpy(lines[0], line, STRING_LENGTH - 1); do_refresh(); } @@ -133,7 +133,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) if (inpt_command == 'f') { // add friend command: /f ID int i; char temp_id[128]; - for (i = 0; i < 128; i++) + for (i = 0; i < 128; i++) temp_id[i] = line[i+prompt_offset]; int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); @@ -166,8 +166,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) } else if (inpt_command == 'm') { //message command: /m friendnumber messsage size_t len = strlen(line); - if(len < 3) - return; + if(len < 3) + return; char numstring[len-3]; char message[len-3]; @@ -248,7 +248,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) else if (inpt_command == 'q') { //exit endwin(); exit(EXIT_SUCCESS); - } else { + } else { new_lines("[i] invalid command"); } } else { @@ -335,7 +335,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) new_lines(format_message((char*)string, friendnumber)); } -void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) +void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); @@ -344,7 +344,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) new_lines(msg); } -void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) +void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); @@ -353,7 +353,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) new_lines(msg); } -void load_key() +void load_key() { FILE *data_file = NULL; data_file = fopen("data","r"); @@ -368,7 +368,7 @@ void load_key() exit(1); } Messenger_load(data, size); - } else { + } else { //else save new keys int size = Messenger_size(); uint8_t data[size]; @@ -418,9 +418,9 @@ int main(int argc, char *argv[]) int resolved_address = resolve_addr(argv[1]); if (resolved_address != 0) bootstrap_ip_port.ip.i = resolved_address; - else + else exit(1); - + DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); nodelay(stdscr, TRUE); while(true) { @@ -441,7 +441,7 @@ int main(int argc, char *argv[]) if (c == '\n') { line_eval(lines, line); strcpy(line, ""); - } else if (c == 127) { + } else if (c == 8 || c == 127) { line[strlen(line)-1] = '\0'; } else if (isalnum(c) || ispunct(c) || c == ' ') { strcpy(line, appender(line, (char) c)); From 0ba09a798da26b938f8877716c987042ac03d9e6 Mon Sep 17 00:00:00 2001 From: pb82 Date: Sat, 3 Aug 2013 13:32:56 +0200 Subject: [PATCH 07/16] added some more details (libsodium without checkinstall) --- INSTALL.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 7982d3db..20c2c58e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -19,7 +19,7 @@ Build dependencies: apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake checkinstall ``` -on Fedora: +On Fedora: ```bash yum groupinstall "Development Tools" @@ -39,7 +39,7 @@ sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc sudo ldconfig ``` -or without checkinstall: +Or if checkinstall is not easily available for your distribution (e.g. Fedora): ```bash git clone git://github.com/jedisct1/libsodium.git cd libsodium @@ -49,6 +49,7 @@ git checkout tags/0.4.2 make check sudo make install ``` +This will copy the libs to /usr/local/lib and the headers to /usr/local/include Then clone this repo and generate makefile: From 7b112116db61cc2538a1115129677b275e549fb8 Mon Sep 17 00:00:00 2001 From: pb82 Date: Sat, 3 Aug 2013 13:36:01 +0200 Subject: [PATCH 08/16] rearranged fedora specific instructions --- INSTALL.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 20c2c58e..afce1cc2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -39,7 +39,9 @@ sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc sudo ldconfig ``` -Or if checkinstall is not easily available for your distribution (e.g. Fedora): +Or if checkinstall is not easily available for your distribution (e.g. Fedora), +this will install the libs to /usr/local/lib and the headers to /usr/local/include + ```bash git clone git://github.com/jedisct1/libsodium.git cd libsodium @@ -49,7 +51,6 @@ git checkout tags/0.4.2 make check sudo make install ``` -This will copy the libs to /usr/local/lib and the headers to /usr/local/include Then clone this repo and generate makefile: From b838c867d8108c4014c0daefa23239dd4cf658ef Mon Sep 17 00:00:00 2001 From: pb82 Date: Sat, 3 Aug 2013 13:37:15 +0200 Subject: [PATCH 09/16] typo --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index afce1cc2..625a9c6d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -40,7 +40,7 @@ sudo ldconfig ``` Or if checkinstall is not easily available for your distribution (e.g. Fedora), -this will install the libs to /usr/local/lib and the headers to /usr/local/include +this will install the libs to /usr/local/lib and the headers to /usr/local/include: ```bash git clone git://github.com/jedisct1/libsodium.git From fcad4d0a5a3b5ed87032e21938b709bb98c2b0a4 Mon Sep 17 00:00:00 2001 From: Astonex Date: Sat, 3 Aug 2013 14:14:33 +0100 Subject: [PATCH 10/16] nTox_win32 - Updated friends list display --- testing/nTox_win32.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 9c6e0aac..55440828 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -153,23 +153,32 @@ void add_friend() void list_friends() { - int activefriends = 0; int i; + + printf("\n[i] Friend List"); + + printf("----- PENDING -----\n\n"); for (i = 0; i <= maxnumfriends; i++) { - if (m_friendstatus(i) == 4) - activefriends++; + char name[MAX_NAME_LENGTH]; + getname(i, (uint8_t*)name); + if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4) + printf("[%d] %s\n", i, (uint8_t*)name); } + + printf("\n"); - printf("\n[i] Friend List | Total: %d\n\n", activefriends); + printf("----- ACTIVE -----\n\n"); - for (i = 0; i <= 256; i++) {/* TODO: fix this properly*/ + for (i = 0; i <= maxnumfriends; i++) { char name[MAX_NAME_LENGTH]; getname(i, (uint8_t*)name); if (m_friendstatus(i) == 4) - printf("[%d] %s\n\n", i, (uint8_t*)name); + printf("[%d] %s\n", i, (uint8_t*)name); } + + printf("\n"); } void delete_friend() @@ -323,9 +332,8 @@ void line_eval(char* line) } /* EXIT */ else if (inpt_command == 'q') { - uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline"; - m_set_userstatus(status, strlen((char*)status)); - Sleep(10); + strcpy(line, "Offline"); + change_status(line); exit(EXIT_SUCCESS); } } From 8fac63f6df7e9231bf0642b50881f52162803914 Mon Sep 17 00:00:00 2001 From: Astonex Date: Sat, 3 Aug 2013 15:12:22 +0100 Subject: [PATCH 11/16] Changing status to offline when quitting wont overwrite last saved status --- testing/nTox_win32.c | 28 +++++++++++++++------------- testing/nTox_win32.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 55440828..5501ecf5 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -255,7 +255,7 @@ void change_nickname() fclose(name_file); } -void change_status() +void change_status(int savetofile) { uint8_t status[MAX_USERSTATUS_LENGTH]; int i = 0; @@ -274,10 +274,12 @@ void change_status() sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); printf(numstring); - FILE* status_file = NULL; - status_file = fopen("statusfile.txt", "w"); - fprintf(status_file, "%s", (char*)status); - fclose(status_file); + if (savetofile == 1) { + FILE* status_file = NULL; + status_file = fopen("statusfile.txt", "w"); + fprintf(status_file, "%s", (char*)status); + fclose(status_file); + } } void accept_friend_request() @@ -298,7 +300,7 @@ void line_eval(char* line) char inpt_command = line[1]; if(inpt_command == 'f') { - add_friend(line); + add_friend(); } else if (inpt_command == 'r') { @@ -307,23 +309,23 @@ void line_eval(char* line) } else if (inpt_command == 'l') { - list_friends(line); + list_friends(); } else if (inpt_command == 'd') { - delete_friend(line); + delete_friend(); } /* Send message to friend */ else if (inpt_command == 'm') { - message_friend(line); + message_friend(); } else if (inpt_command == 'n') { - change_nickname(line); + change_nickname(); } else if (inpt_command == 's') { - change_status(line); + change_status(1); } else if (inpt_command == 'a') { @@ -332,8 +334,8 @@ void line_eval(char* line) } /* EXIT */ else if (inpt_command == 'q') { - strcpy(line, "Offline"); - change_status(line); + strcpy(line, "---Offline"); + change_status(0); exit(EXIT_SUCCESS); } } diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 211ac95f..271403b8 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h @@ -39,7 +39,7 @@ void list_friends(); void delete_friend(); void message_friend(); void change_nickname(); -void change_status(); +void change_status(int savetofile); void accept_friend_request(); void line_eval(char* line); void get_input(); From 72c17699dcbffa62c5c23e939a49c40ef2873c1c Mon Sep 17 00:00:00 2001 From: NemDiggers Date: Sat, 3 Aug 2013 11:14:00 -0400 Subject: [PATCH 12/16] Update readme to refer to new developer blog. If you need an account on the CMS; contact me on IRC. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dcb1cf1b..dc16787b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ With the rise of governmental monitoring programs, Tox aims to be an easy to use **IRC**: #tox on freenode, alternatively, you can use the [webchat](http://webchat.freenode.net/?channels=#tox).
**Website**: [http://tox.im](http://tox.im) +**Developer Blog**: [http://dev.tox.im](http://dev.tox.im) **Website translations**: [see stal888's repository](https://github.com/stal888/ProjectTox-Website)
**Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) From e5d2c219af19421c275d9f9f20f1a4a4a994833f Mon Sep 17 00:00:00 2001 From: plutooo Date: Sat, 3 Aug 2013 08:29:23 -0700 Subject: [PATCH 13/16] DHT: added id_equal(), ipport_equal(), is_timeout() --- core/DHT.c | 164 +++++++++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 73 deletions(-) diff --git a/core/DHT.c b/core/DHT.c index 6972fdeb..5d5910e0 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -119,23 +119,39 @@ 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 * client_id, uint8_t * client_id1, uint8_t * client_id2) +int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) { - uint32_t i; - uint8_t tmp1, tmp2; + size_t i; + uint8_t distance1, distance2; for(i = 0; i < CLIENT_ID_SIZE; ++i) { - tmp1 = abs(client_id[i] ^ client_id1[i]); - tmp2 = abs(client_id[i] ^ client_id2[i]); + + distance1 = abs(id[i] ^ id1[i]); + distance2 = abs(id[i] ^ id2[i]); - if(tmp1 < tmp2) + if(distance1 < distance2) return 1; - else if(tmp1 > tmp2) + if(distance1 > distance2) return 2; } return 0; } +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) +{ + return memcmp(a, b, CLIENT_ID_SIZE) == 0; +} + +int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) +{ + return timestamp + timeout <= time_now; +} + /* check if client with client_id is already in list of length length. * if it is then set its corresponding timestamp to current time. * if the id is already in the list with a different ip_port, update it. @@ -150,12 +166,11 @@ int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_ for(i = 0; i < length; ++i) { /*If ip_port is assigned to a different client_id replace it*/ - if(list[i].ip_port.ip.i == ip_port.ip.i && - list[i].ip_port.port == ip_port.port) { + if(ipport_equal(list[i].ip_port, ip_port)) { memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); } - if(memcmp(list[i].client_id, client_id, CLIENT_ID_SIZE) == 0) { + if(id_equal(list[i].client_id, client_id)) { /* Refresh the client timestamp. */ list[i].timestamp = temp_time; list[i].ip_port.ip.i = ip_port.ip.i; @@ -172,10 +187,12 @@ int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_ int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) { uint32_t i; + for(i = 0; i < length; ++i) { - if(memcmp(list[i].client_id, client_id, CLIENT_ID_SIZE) == 0) + if(id_equal(list[i].client_id, client_id)) return 1; } + return 0; } @@ -184,10 +201,12 @@ int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) static int friend_number(uint8_t * client_id) { uint32_t i; + for(i = 0; i < num_friends; ++i) { - if(memcmp(friends_list[i].client_id, client_id, CLIENT_ID_SIZE) == 0) + if(id_equal(friends_list[i].client_id, client_id)) return i; } + return -1; } @@ -199,11 +218,11 @@ static int friend_number(uint8_t * client_id) int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) { uint32_t i, j, k; - uint64_t temp_time = unix_time(); + uint64_t temp_time = unix_time(); int num_nodes = 0, closest, tout, inlist; for (i = 0; i < LCLIENT_LIST; ++i) { - tout = close_clientlist[i].timestamp <= temp_time - BAD_NODE_TIMEOUT; + tout = is_timeout(temp_time, close_clientlist[i].timestamp, BAD_NODE_TIMEOUT); inlist = client_in_nodelist(nodes_list, MAX_SENT_NODES, close_clientlist[i].client_id); /* if node isn't good or is already in list. */ @@ -218,7 +237,9 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) nodes_list[num_nodes].ip_port = close_clientlist[i].ip_port; num_nodes++; + } else { + for(j = 0; j < MAX_SENT_NODES; ++j) { closest = id_closest( client_id, nodes_list[j].client_id, @@ -237,7 +258,8 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) for(i = 0; i < num_friends; ++i) { for(j = 0; j < MAX_FRIEND_CLIENTS; ++j) { - tout = friends_list[i].client_list[j].timestamp <= temp_time - BAD_NODE_TIMEOUT; + + tout = is_timeout(temp_time, friends_list[i].client_list[j].timestamp, BAD_NODE_TIMEOUT); inlist = client_in_nodelist( nodes_list, MAX_SENT_NODES, friends_list[i].client_list[j].client_id); @@ -288,7 +310,7 @@ int replace_bad( Client_data * list, uint64_t temp_time = unix_time(); for(i = 0; i < length; ++i) { /* if node is bad */ - if(list[i].timestamp + BAD_NODE_TIMEOUT < temp_time) { + if(is_timeout(temp_time, list[i].timestamp, BAD_NODE_TIMEOUT)) { memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); list[i].ip_port = ip_port; list[i].timestamp = temp_time; @@ -376,27 +398,23 @@ void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient uint32_t i, j; uint64_t temp_time = unix_time(); - if (memcmp(client_id, self_public_key, CLIENT_ID_SIZE) == 0) { - for (i = 0; i < LCLIENT_LIST; ++i) { + if (id_equal(client_id, self_public_key)) { - if (memcmp( nodeclient_id, - close_clientlist[i].client_id, - CLIENT_ID_SIZE ) == 0) { + for (i = 0; i < LCLIENT_LIST; ++i) { + if (id_equal(nodeclient_id, close_clientlist[i].client_id)) { close_clientlist[i].ret_ip_port = ip_port; close_clientlist[i].ret_timestamp = temp_time; return; } } - } else { - for (i = 0; i < num_friends; ++i) { - if (memcmp( client_id, - friends_list[i].client_id, - CLIENT_ID_SIZE ) == 0) { - for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { - if (memcmp( nodeclient_id, - friends_list[i].client_list[j].client_id, - CLIENT_ID_SIZE ) == 0) { + } else { + + for (i = 0; i < num_friends; ++i) { + if (id_equal(client_id, friends_list[i].client_id)) { + + for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { + if (id_equal(nodeclient_id, friends_list[i].client_list[j].client_id)) { friends_list[i].client_list[j].ret_ip_port = ip_port; friends_list[i].client_list[j].ret_timestamp = temp_time; return; @@ -404,6 +422,7 @@ void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient } } } + } } @@ -419,14 +438,15 @@ int is_pinging(IP_Port ip_port, uint64_t ping_id) uint64_t temp_time = unix_time(); for (i = 0; i < LPING_ARRAY; ++i ) { - if ((pings[i].timestamp + PING_TIMEOUT) > temp_time) { + if (!is_timeout(temp_time, pings[i].timestamp, PING_TIMEOUT)) { pinging = 0; - if (ip_port.ip.i != 0 && - pings[i].ip_port.ip.i == ip_port.ip.i && - pings[i].ip_port.port == ip_port.port) + + if (ip_port.ip.i != 0 && ipport_equal(pings[i].ip_port, ip_port)) ++pinging; + if (ping_id != 0 && pings[i].ping_id == ping_id) ++pinging; + if (pinging == ((ping_id != 0) + (ip_port.ip.i != 0))) return 1; } @@ -443,14 +463,15 @@ int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) uint64_t temp_time = unix_time(); for(i = 0; i < LSEND_NODES_ARRAY; ++i ) { - if((send_nodes[i].timestamp + PING_TIMEOUT) > temp_time) { + if(!is_timeout(temp_time, send_nodes[i].timestamp, PING_TIMEOUT)) { pinging = 0; - if(ip_port.ip.i != 0 && - send_nodes[i].ip_port.ip.i == ip_port.ip.i && - send_nodes[i].ip_port.port == ip_port.port) + + if(ip_port.ip.i != 0 && ipport_equal(send_nodes[i].ip_port, ip_port)) ++pinging; + if(ping_id != 0 && send_nodes[i].ping_id == ping_id) ++pinging; + if(pinging == (ping_id != 0) + (ip_port.ip.i != 0)) return 1; } @@ -471,10 +492,9 @@ uint64_t add_pinging(IP_Port ip_port) uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); uint64_t temp_time = unix_time(); - for(i = 0; i < PING_TIMEOUT; ++i ) { for(j = 0; j < LPING_ARRAY; ++j ) { - if((pings[j].timestamp + PING_TIMEOUT - i) < temp_time) { + if(is_timeout(temp_time, pings[j].timestamp, PING_TIMEOUT - i)) { pings[j].timestamp = temp_time; pings[j].ip_port = ip_port; pings[j].ping_id = ping_id; @@ -495,7 +515,7 @@ uint64_t add_gettingnodes(IP_Port ip_port) for(i = 0; i < PING_TIMEOUT; ++i ) { for(j = 0; j < LSEND_NODES_ARRAY; ++j ) { - if((send_nodes[j].timestamp + PING_TIMEOUT - i) < temp_time) { + if(is_timeout(temp_time, send_nodes[j].timestamp, PING_TIMEOUT - i)) { send_nodes[j].timestamp = temp_time; send_nodes[j].ip_port = ip_port; send_nodes[j].ping_id = ping_id; @@ -513,8 +533,7 @@ uint64_t add_gettingnodes(IP_Port ip_port) static int pingreq(IP_Port ip_port, uint8_t * public_key) { /* check if packet is gonna be sent to ourself */ - if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0 - || is_pinging(ip_port, 0)) + if(id_equal(public_key, self_public_key) || is_pinging(ip_port, 0)) return 1; uint64_t ping_id = add_pinging(ip_port); @@ -548,7 +567,7 @@ static int pingreq(IP_Port ip_port, uint8_t * public_key) static int pingres(IP_Port ip_port, uint8_t * public_key, uint64_t ping_id) { /* check if packet is gonna be sent to ourself */ - if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0) + if(id_equal(public_key, self_public_key)) return 1; uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING]; @@ -577,8 +596,7 @@ static int pingres(IP_Port ip_port, uint8_t * public_key, uint64_t ping_id) static int getnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id) { /* check if packet is gonna be sent to ourself */ - if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0 - || is_gettingnodes(ip_port, 0)) + if(id_equal(public_key, self_public_key) || is_gettingnodes(ip_port, 0)) return 1; uint64_t ping_id = add_gettingnodes(ip_port); @@ -617,7 +635,7 @@ static int getnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id) static int sendnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id, uint64_t ping_id) { /* check if packet is gonna be sent to ourself */ - if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0) + if(id_equal(public_key, self_public_key)) return 1; uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) @@ -665,7 +683,7 @@ int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) return 1; /* check if packet is from ourself. */ - if(memcmp(packet + 1, self_public_key, CLIENT_ID_SIZE) == 0) + if(id_equal(packet + 1, self_public_key)) return 1; int len = decrypt_data( packet + 1, @@ -691,7 +709,7 @@ int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) return 1; /* check if packet is from ourself. */ - if(memcmp(packet + 1, self_public_key, CLIENT_ID_SIZE) == 0) + if(id_equal(packet + 1, self_public_key)) return 1; int len = decrypt_data( packet + 1, @@ -720,7 +738,7 @@ int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) return 1; /* check if packet is from ourself. */ - if (memcmp(packet + 1, self_public_key, CLIENT_ID_SIZE) == 0) + if (id_equal(packet + 1, self_public_key)) return 1; uint8_t plain[sizeof(ping_id) + CLIENT_ID_SIZE]; @@ -810,16 +828,20 @@ int DHT_delfriend(uint8_t * client_id) Friend * temp; for (i = 0; i < num_friends; ++i) { /* Equal */ - if (memcmp(friends_list[i].client_id, client_id, CLIENT_ID_SIZE) == 0) { + if (id_equal(friends_list[i].client_id, client_id)) { --num_friends; + if (num_friends != i) { memcpy( friends_list[i].client_id, friends_list[num_friends].client_id, CLIENT_ID_SIZE ); } + temp = realloc(friends_list, sizeof(Friend) * (num_friends)); - if (temp != NULL) - friends_list = temp; + if (temp == NULL) + return 1; + + friends_list = temp; return 0; } } @@ -836,12 +858,9 @@ IP_Port DHT_getfriendip(uint8_t * client_id) for (i = 0; i < num_friends; ++i) { /* Equal */ - if (memcmp(friends_list[i].client_id, client_id, CLIENT_ID_SIZE) == 0) { + if (id_equal(friends_list[i].client_id, client_id)) { for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { - if (memcmp( friends_list[i].client_list[j].client_id, - client_id, - CLIENT_ID_SIZE ) == 0 && - friends_list[i].client_list[j].timestamp + BAD_NODE_TIMEOUT > temp_time) + if (id_equal(friends_list[i].client_list[j].client_id, client_id) && !is_timeout(temp_time, friends_list[i].client_list[j].timestamp, BAD_NODE_TIMEOUT)) return friends_list[i].client_list[j].ip_port; } return empty; @@ -865,14 +884,14 @@ void doDHTFriends() uint32_t num_nodes = 0; for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { /* if node is not dead. */ - if (friends_list[i].client_list[j].timestamp + Kill_NODE_TIMEOUT > temp_time) { + if (!is_timeout(temp_time, friends_list[i].client_list[j].timestamp, Kill_NODE_TIMEOUT)) { if ((friends_list[i].client_list[j].last_pinged + PING_INTERVAL) <= temp_time) { pingreq( friends_list[i].client_list[j].ip_port, friends_list[i].client_list[j].client_id ); friends_list[i].client_list[j].last_pinged = temp_time; } /* if node is good. */ - if (friends_list[i].client_list[j].timestamp + BAD_NODE_TIMEOUT > temp_time) { + if (!is_timeout(temp_time, friends_list[i].client_list[j].timestamp, BAD_NODE_TIMEOUT)) { index[num_nodes] = j; ++num_nodes; } @@ -903,14 +922,14 @@ void doClose() for (i = 0; i < LCLIENT_LIST; ++i) { /* if node is not dead. */ - if (close_clientlist[i].timestamp + Kill_NODE_TIMEOUT > temp_time) { + if (!is_timeout(temp_time, close_clientlist[i].timestamp, Kill_NODE_TIMEOUT)) { if ((close_clientlist[i].last_pinged + PING_INTERVAL) <= temp_time) { pingreq( close_clientlist[i].ip_port, close_clientlist[i].client_id ); close_clientlist[i].last_pinged = temp_time; } /* if node is good. */ - if (close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time) { + if (!is_timeout(temp_time, close_clientlist[i].timestamp, BAD_NODE_TIMEOUT)) { index[num_nodes] = i; ++num_nodes; } @@ -937,10 +956,12 @@ void DHT_bootstrap(IP_Port ip_port, uint8_t * public_key) int route_packet(uint8_t * client_id, uint8_t * packet, uint32_t length) { uint32_t i; + for (i = 0; i < LCLIENT_LIST; ++i) { - if (memcmp(client_id, close_clientlist[i].client_id, CLIENT_ID_SIZE) == 0) + if (id_equal(client_id, close_clientlist[i].client_id)) return sendpacket(close_clientlist[i].ip_port, packet, length); } + return -1; } @@ -966,10 +987,9 @@ static int friend_iplist(IP_Port * ip_portlist, uint16_t friend_num) client = &friend->client_list[i]; /*If ip is not zero and node is good */ - if (client->ret_ip_port.ip.i != 0 && - client->ret_timestamp + BAD_NODE_TIMEOUT > temp_time) { + if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { - if (memcmp(client->client_id, friend->client_id, CLIENT_ID_SIZE) == 0) + if (id_equal(client->client_id, friend->client_id)) return 0; ip_portlist[num_ips] = client->ret_ip_port; @@ -997,8 +1017,7 @@ int route_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) client = &friend->client_list[i]; /*If ip is not zero and node is good */ - if (client->ret_ip_port.ip.i != 0 && - client->ret_timestamp + BAD_NODE_TIMEOUT > temp_time) { + if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { if (sendpacket(client->ip_port, packet, length) == length) ++sent; @@ -1028,8 +1047,7 @@ int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) client = &friend->client_list[i]; /*If ip is not zero and node is good */ - if(client->ret_ip_port.ip.i != 0 && - client->ret_timestamp + BAD_NODE_TIMEOUT > temp_time) { + if(client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { ip_list[n] = client->ip_port; ++n; } @@ -1052,7 +1070,7 @@ int friend_ips(IP_Port * ip_portlist, uint8_t * friend_id) uint32_t i; for (i = 0; i < num_friends; ++i) { /* Equal */ - if (memcmp(friends_list[i].client_id, friend_id, CLIENT_ID_SIZE) == 0) + if (id_equal(friends_list[i].client_id, friend_id)) return friend_iplist(ip_portlist, i); } return -1; @@ -1094,7 +1112,7 @@ int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) return 1; /* check if request is for us. */ - if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { + if (id_equal(packet + 1, self_public_key)) { uint8_t public_key[crypto_box_PUBLICKEYBYTES]; uint8_t data[MAX_DATA_SIZE]; @@ -1329,7 +1347,7 @@ int DHT_isconnected() uint64_t temp_time = unix_time(); for(i = 0; i < LCLIENT_LIST; ++i) { - if(close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time) + if(!is_timeout(temp_time, close_clientlist[i].timestamp, BAD_NODE_TIMEOUT)) return 1; } return 0; From a1c31557f2141312b5568ee00f3f1741157e01e4 Mon Sep 17 00:00:00 2001 From: NemDiggers Date: Sat, 3 Aug 2013 11:53:51 -0400 Subject: [PATCH 14/16] People aren't that excited to send messages --- testing/toxic/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index bcfc487f..391b0b39 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -50,7 +50,7 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) { void on_message(int friendnumber, uint8_t* string, uint16_t length) { size_t i; - wprintw(prompt->window, "\n(message) %d: %s!\n", friendnumber, string); + wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); for(i=0; i Date: Sat, 3 Aug 2013 18:25:12 +0200 Subject: [PATCH 15/16] Changed CMake options to compile the core shared It is now compiled under 'toxcore' instead of just 'core' to be able to be installed without conflicts. --- CMakeLists.txt | 6 +++--- core/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed934c01..07098391 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,15 +33,15 @@ if(NOT USE_NACL) endif() macro(linkCoreLibraries exe_name) - add_dependencies(${exe_name} core) + add_dependencies(${exe_name} toxcore) if(WIN32) include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) - target_link_libraries(${exe_name} core + 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} core + target_link_libraries(${exe_name} toxcore ${LINK_CRYPTO_LIBRARY}) endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 44ae980c..36acb6cf 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.6.0) -project(core C) +project(toxcore C) if(WIN32) include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) @@ -16,4 +16,4 @@ set(core_sources LAN_discovery.c Messenger.c) -add_library(core ${core_sources}) +add_library(toxcore SHARED ${core_sources}) From fb14b3eccdaeb992d9bbf320d68b810a4fcc5a5b Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 3 Aug 2013 12:45:44 -0400 Subject: [PATCH 16/16] Fixed compatibility with original NaCl. --- core/network.h | 1 + 1 file changed, 1 insertion(+) diff --git a/core/network.h b/core/network.h index a5f7899b..a7559ebe 100644 --- a/core/network.h +++ b/core/network.h @@ -57,6 +57,7 @@ #include #else #include +#define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) #endif #ifdef __cplusplus