From 5ad33e7398fb2ec0dd8d960f3e66371eb5b15782 Mon Sep 17 00:00:00 2001 From: Astonex Date: Mon, 29 Jul 2013 23:00:56 +0100 Subject: [PATCH 01/32] Essentially nTox without the ncurses for Windows. Slightly modified main() --- other/DHT_bootstrap.c | 8 ++ testing/CMakeLists.txt | 3 + testing/nTox_win32.c | 281 +++++++++++++++++++++++++++++++++++++++++ testing/nTox_win32.h | 32 +++++ 4 files changed, 324 insertions(+) create mode 100644 testing/nTox_win32.c create mode 100644 testing/nTox_win32.h diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 19714e70b..befe22258 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -79,12 +79,20 @@ int main(int argc, char *argv[]) manage_keys(); printf("Public key: "); uint32_t i; + + FILE *file; + file = fopen("PUBLIC_ID.txt", "w"); + for(i = 0; i < 32; i++) { if(self_public_key[i] < 16) printf("0"); printf("%hhX",self_public_key[i]); + fprintf(file, "%hhX",self_public_key[i]); } + + fclose(file); + printf("\n"); printf("Port: %u\n", PORT); //initialize networking diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 12efc2f46..6b0d64c34 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,6 +8,9 @@ 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) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) endif() diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c new file mode 100644 index 000000000..340e0cb4c --- /dev/null +++ b/testing/nTox_win32.c @@ -0,0 +1,281 @@ +/* nTox_win32.c + * + * Textual frontend for Tox - Windows version + * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#include "nTox_win32.h" +#include "misc_tools.h" + +uint8_t pending_requests[256][CLIENT_ID_SIZE]; +uint8_t num_requests; + +char line[STRING_LENGTH]; + +void do_header() +{ + system("cls"); + + printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)\n\n"); +} + +void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) +{ + printf("\n[i] received friend request with message\n"); + printf((char *)data); + char numchar[100]; + sprintf(numchar, "\n[i] accept request with /a %u\n", num_requests); + printf(numchar); + memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); + ++num_requests; +} + +void print_message(int friendnumber, uint8_t * string, uint16_t length) +{ + char name[MAX_NAME_LENGTH]; + getname(friendnumber, (uint8_t*)name); + char msg[100+length+strlen(name)+1]; + time_t rawtime; + struct tm * timeinfo; + time (&rawtime); + timeinfo = localtime (&rawtime); + char* temp = asctime(timeinfo); + size_t len = strlen(temp); + temp[len-1]='\0'; + sprintf(msg, "\n[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp + printf(msg); +} + +void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) +{ + char name[MAX_NAME_LENGTH]; + getname(friendnumber, (uint8_t*)name); + char msg[100+length]; + sprintf(msg, "\n[i] [%d] %s is now known as %s.", friendnumber, name, string); + printf(msg); +} + +void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { + char name[MAX_NAME_LENGTH]; + getname(friendnumber, (uint8_t*)name); + char msg[100+length+strlen(name)+1]; + sprintf(msg, "\n[i] [%d] %s's status changed to %s.", friendnumber, name, string); + printf(msg); +} + + +void load_key() +{ + FILE *data_file = NULL; + + if ((data_file = fopen("data", "r"))) { + fseek(data_file, 0, SEEK_END); + int size = ftell(data_file); + fseek(data_file, 0, SEEK_SET); + uint8_t data[size]; + + if(fread(data, sizeof(uint8_t), size, data_file) != size) { + printf("\n[i] Could not read the data file. Exiting."); + exit(1); + } + + Messenger_load(data, size); + } else { + int size = Messenger_size(); + uint8_t data[size]; + Messenger_save(data); + data_file = fopen("data", "w"); + + if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { + printf("\n[i] Could not write data to file. Exiting."); + exit(1); + } + } + + fclose(data_file); +} + +void line_eval(char* line) +{ + if(line[0] == '/') { + /* Add friend */ + if(line[1] == 'f') { + int i; + char temp_id[128]; + for (i=0; i<128; i++) + temp_id[i] = line[i+3]; + int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); + char numstring[100]; + sprintf(numstring, "\n[i] added friend %d\n\n", num); + printf(numstring); + } + + else if (line[1] == 'd') { + doMessenger(); + } + /* Send message to friend */ + else if (line[1] == 'm') { + int i; + size_t len = strlen(line); + char numstring[len-3]; + char message[len-3]; + for (i=0; i\n", argv[0]); + exit(0); + } + + if (initMessenger() == -1) { + printf("initMessenger failed"); + exit(0); + } + + + if (argc > 4) { + if(strncmp(argv[4], "nokey", 6) < 0) { + //nothing + } else { + load_key(); + } + } + + m_callback_friendrequest(print_request); + m_callback_friendmessage(print_message); + m_callback_namechange(print_nickchange); + m_callback_userstatus(print_statuschange); + + char idstring0[200]; + char idstring1[32][5]; + char idstring2[32][5]; + uint32_t i; + for(i = 0; i < 32; i++) + { + if(self_public_key[i] < 16) + strcpy(idstring1[i],"0"); + else + strcpy(idstring1[i], ""); + sprintf(idstring2[i], "%hhX",self_public_key[i]); + } + strcpy(idstring0,"\n[i] your ID: "); + for (i=0; i<32; i++) { + strcat(idstring0,idstring1[i]); + strcat(idstring0,idstring2[i]); + } + + do_header(); + + IP_Port bootstrap_ip_port; + bootstrap_ip_port.port = htons(atoi(argv[2])); + int resolved_address = resolve_addr(argv[1]); + if (resolved_address != -1) + bootstrap_ip_port.ip.i = resolved_address; + else + exit(1); + + DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); + + + int c; + int on = 0; + + while(1) { + if (on == 0 && DHT_isconnected()) { + printf("\n[i] connected to DHT\n\n"); + on = 1; + } + + doMessenger(); + + fgets(line, STRING_LENGTH, stdin); + + line_eval(line); + + strcpy(line, ""); + } + + return 0; +} \ No newline at end of file diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h new file mode 100644 index 000000000..74ea5f58a --- /dev/null +++ b/testing/nTox_win32.h @@ -0,0 +1,32 @@ +/* nTox_win32.h + * + * Textual frontend for Tox - Windows version + * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + */ + +#ifndef NTOX_WIN32_H +#define NTOX_WIN32_H + +#include "../core/Messenger.h" +#include "../core/network.h" + +#define STRING_LENGTH 256 +#define HISTORY 50 + +#endif \ No newline at end of file From 6c6a54b1326973b5312b1f53d914a5c8138fcd98 Mon Sep 17 00:00:00 2001 From: Astonex Date: Mon, 29 Jul 2013 23:11:20 +0100 Subject: [PATCH 02/32] Adding nTox_win32.make --- testing/cmake/nTox_win32.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 testing/cmake/nTox_win32.cmake diff --git a/testing/cmake/nTox_win32.cmake b/testing/cmake/nTox_win32.cmake new file mode 100644 index 000000000..5acfb4118 --- /dev/null +++ b/testing/cmake/nTox_win32.cmake @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.6.0) +project(nTox_win32 C) + +set(exe_name nTox_win32) + +add_executable(${exe_name} + nTox_win32.c misc_tools.c) + +linkCoreLibraries(${exe_name}) From 0cd561ee48a5593264392b47ab1c4bcda87d8348 Mon Sep 17 00:00:00 2001 From: Astonex Date: Mon, 29 Jul 2013 23:15:12 +0100 Subject: [PATCH 03/32] Removed unsued HISTORY define --- testing/nTox_win32.h | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 74ea5f58a..7861be1c1 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h @@ -27,6 +27,5 @@ #include "../core/network.h" #define STRING_LENGTH 256 -#define HISTORY 50 #endif \ No newline at end of file From 7e973c8cac08acb5724b5e1f462faf539b647a8f Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 00:05:51 +0100 Subject: [PATCH 04/32] Some changes so the user's ID gets displayed --- testing/nTox_win32.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 340e0cb4c..6e71a436f 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -31,8 +31,6 @@ char line[STRING_LENGTH]; void do_header() { - system("cls"); - printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)\n\n"); } @@ -148,7 +146,7 @@ void line_eval(char* line) } int num = atoi(numstring); if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { - printf("\n[i] could not send message\n\n"); + printf("\n[i] could not send message: %s\n\n", message); } } @@ -228,6 +226,8 @@ int main(int argc, char *argv[]) m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); + system("cls"); + char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; @@ -246,7 +246,9 @@ int main(int argc, char *argv[]) strcat(idstring0,idstring2[i]); } + printf(idstring0); do_header(); + IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); From a39ee46b18ac92b480ab184bedfb12784df12f04 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 29 Jul 2013 19:42:04 -0400 Subject: [PATCH 05/32] Fixed build. --- testing/cmake/toxic.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/cmake/toxic.cmake b/testing/cmake/toxic.cmake index 494dea90b..1ffab788d 100644 --- a/testing/cmake/toxic.cmake +++ b/testing/cmake/toxic.cmake @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.6.0) project(toxic C) -set(exe_name toxic/toxic) +set(exe_name toxic) add_executable(${exe_name} toxic/main.c toxic/prompt.c) From 59ccce35a6afd8e98c28c26d8a53b1880cb16ba8 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 01:27:48 +0100 Subject: [PATCH 06/32] Added multi-threading so user input doens't hold up checking the network --- testing/nTox_win32.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 6e71a436f..51f310012 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -24,6 +24,8 @@ #include "nTox_win32.h" #include "misc_tools.h" +#include + uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t num_requests; @@ -200,6 +202,15 @@ void line_eval(char* line) } } +void get_input() +{ + while(1) { + fgets(line, STRING_LENGTH, stdin); + line_eval(line); + strcpy(line, ""); + } +} + int main(int argc, char *argv[]) { if (argc < 4) { @@ -264,6 +275,8 @@ int main(int argc, char *argv[]) int c; int on = 0; + _beginthread(get_input, 0, NULL); + while(1) { if (on == 0 && DHT_isconnected()) { printf("\n[i] connected to DHT\n\n"); @@ -271,12 +284,6 @@ int main(int argc, char *argv[]) } doMessenger(); - - fgets(line, STRING_LENGTH, stdin); - - line_eval(line); - - strcpy(line, ""); } return 0; From 1d8f6e94e73c569f09a2bc8bd008d0ceb2e5b8cc Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Mon, 29 Jul 2013 20:45:53 -0400 Subject: [PATCH 07/32] Fixed formatting of some cmake files --- core/CMakeLists.txt | 14 +++++++------- other/bootstrap_serverdaemon/CMakeLists.txt | 6 ++++-- other/cmake/DHT_bootstrap.cmake | 3 ++- testing/CMakeLists.txt | 4 ++-- testing/cmake/DHT_cryptosendfiletest.cmake | 3 ++- testing/cmake/DHT_sendfiletest.cmake | 2 +- testing/cmake/DHT_test.cmake | 3 ++- testing/cmake/Lossless_UDP_testclient.cmake | 2 +- testing/cmake/Lossless_UDP_testserver.cmake | 2 +- testing/cmake/Messenger_test.cmake | 2 +- testing/cmake/nTox.cmake | 7 ++++--- .../{cmake/toxic.cmake => toxic/CMakeLists.txt} | 8 +++++--- 12 files changed, 32 insertions(+), 24 deletions(-) rename testing/{cmake/toxic.cmake => toxic/CMakeLists.txt} (62%) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 6ddd5b9b1..420308d82 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -6,12 +6,12 @@ if(WIN32) endif() set(core_sources - DHT.c - network.c - Lossless_UDP.c - net_crypto.c - friend_requests.c - LAN_discovery.c - Messenger.c) + DHT.c + network.c + Lossless_UDP.c + net_crypto.c + friend_requests.c + LAN_discovery.c + Messenger.c) add_library(core ${core_sources}) diff --git a/other/bootstrap_serverdaemon/CMakeLists.txt b/other/bootstrap_serverdaemon/CMakeLists.txt index 6aa4dbeef..57ba48415 100644 --- a/other/bootstrap_serverdaemon/CMakeLists.txt +++ b/other/bootstrap_serverdaemon/CMakeLists.txt @@ -4,7 +4,9 @@ project(DHT_bootstrap_daemon C) set(exe_name DHT_bootstrap_daemon) add_executable(${exe_name} - DHT_bootstrap_daemon.c) + DHT_bootstrap_daemon.c) + +target_link_libraries(${exe_name} + config) -target_link_libraries(${exe_name} config) linkCoreLibraries(${exe_name}) diff --git a/other/cmake/DHT_bootstrap.cmake b/other/cmake/DHT_bootstrap.cmake index e2b164bab..403522ab5 100644 --- a/other/cmake/DHT_bootstrap.cmake +++ b/other/cmake/DHT_bootstrap.cmake @@ -4,6 +4,7 @@ project(DHT_bootstrap C) set(exe_name DHT_bootstrap) add_executable(${exe_name} - DHT_bootstrap.c ../testing/misc_tools.c) + DHT_bootstrap.c + ../testing/misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 3085b0c5f..86f95dc8c 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,8 +8,8 @@ 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(NOT WIN32) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toxic.cmake) - + add_subdirectory(other) endif() diff --git a/testing/cmake/DHT_cryptosendfiletest.cmake b/testing/cmake/DHT_cryptosendfiletest.cmake index c98a2bcd4..5470d02a0 100644 --- a/testing/cmake/DHT_cryptosendfiletest.cmake +++ b/testing/cmake/DHT_cryptosendfiletest.cmake @@ -4,6 +4,7 @@ project(DHT_cryptosendfiletest C) set(exe_name DHT_cryptosendfiletest) add_executable(${exe_name} - DHT_cryptosendfiletest.c misc_tools.c) + DHT_cryptosendfiletest.c + misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/DHT_sendfiletest.cmake b/testing/cmake/DHT_sendfiletest.cmake index 937379146..298db46cd 100644 --- a/testing/cmake/DHT_sendfiletest.cmake +++ b/testing/cmake/DHT_sendfiletest.cmake @@ -4,6 +4,6 @@ project(DHT_sendfiletest C) set(exe_name DHT_sendfiletest) add_executable(${exe_name} - DHT_sendfiletest.c) + DHT_sendfiletest.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/DHT_test.cmake b/testing/cmake/DHT_test.cmake index 74fdf35d2..bb5bf05f7 100644 --- a/testing/cmake/DHT_test.cmake +++ b/testing/cmake/DHT_test.cmake @@ -4,6 +4,7 @@ project(DHT_test C) set(exe_name DHT_test) add_executable(${exe_name} - DHT_test.c misc_tools.c) + DHT_test.c + misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/Lossless_UDP_testclient.cmake b/testing/cmake/Lossless_UDP_testclient.cmake index e894d228a..5f6518072 100644 --- a/testing/cmake/Lossless_UDP_testclient.cmake +++ b/testing/cmake/Lossless_UDP_testclient.cmake @@ -4,6 +4,6 @@ project(Lossless_UDP_testclient C) set(exe_name Lossless_UDP_testclient) add_executable(${exe_name} - Lossless_UDP_testclient.c) + Lossless_UDP_testclient.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/Lossless_UDP_testserver.cmake b/testing/cmake/Lossless_UDP_testserver.cmake index 04306c1a7..26f9302e8 100644 --- a/testing/cmake/Lossless_UDP_testserver.cmake +++ b/testing/cmake/Lossless_UDP_testserver.cmake @@ -4,6 +4,6 @@ project(Lossless_UDP_testserver C) set(exe_name Lossless_UDP_testserver) add_executable(${exe_name} - Lossless_UDP_testserver.c) + Lossless_UDP_testserver.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/Messenger_test.cmake b/testing/cmake/Messenger_test.cmake index b2f54d0a9..15fcd77b0 100644 --- a/testing/cmake/Messenger_test.cmake +++ b/testing/cmake/Messenger_test.cmake @@ -4,6 +4,6 @@ project(Messenger_test C) set(exe_name Messenger_test) add_executable(${exe_name} - Messenger_test.c misc_tools.c) + Messenger_test.c misc_tools.c) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/nTox.cmake b/testing/cmake/nTox.cmake index 4c6905e5b..44476b8f9 100644 --- a/testing/cmake/nTox.cmake +++ b/testing/cmake/nTox.cmake @@ -4,8 +4,9 @@ project(nTox C) set(exe_name nTox) add_executable(${exe_name} - nTox.c misc_tools.c) - -target_link_libraries(${exe_name} ncurses) + nTox.c misc_tools.c) + +target_link_libraries(${exe_name} + ncurses) linkCoreLibraries(${exe_name}) diff --git a/testing/cmake/toxic.cmake b/testing/toxic/CMakeLists.txt similarity index 62% rename from testing/cmake/toxic.cmake rename to testing/toxic/CMakeLists.txt index 1ffab788d..43eb379ab 100644 --- a/testing/cmake/toxic.cmake +++ b/testing/toxic/CMakeLists.txt @@ -4,8 +4,10 @@ project(toxic C) set(exe_name toxic) add_executable(${exe_name} - toxic/main.c toxic/prompt.c) - -target_link_libraries(${exe_name} curses) + toxic/main.c + toxic/prompt.c) + +target_link_libraries(${exe_name} + curses) linkCoreLibraries(${exe_name}) From 261f365e55d4711372f7053667aa368788eabea1 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Mon, 29 Jul 2013 20:47:12 -0400 Subject: [PATCH 08/32] Fixed function signature --- core/network.c | 2 +- core/network.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/network.c b/core/network.c index aa16bda9d..ced08207a 100644 --- a/core/network.c +++ b/core/network.c @@ -169,7 +169,7 @@ void shutdown_networking() address should represent IPv4, IPv6 or a hostname on success returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i on failure returns -1 */ -int resolve_addr(char *address) +int resolve_addr(const char *address) { struct addrinfo hints; memset(&hints, 0, sizeof(hints)); diff --git a/core/network.h b/core/network.h index aaaaa4099..8af4b32f6 100644 --- a/core/network.h +++ b/core/network.h @@ -125,7 +125,7 @@ void shutdown_networking(); address should represent IPv4, IPv6 or a hostname on success returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i on failure returns -1 */ -int resolve_addr(char *address); +int resolve_addr(const char *address); #ifdef __cplusplus } From de7ebc55b1ee31d252160eed88d743c8ef45320b Mon Sep 17 00:00:00 2001 From: Erik Price Date: Mon, 29 Jul 2013 21:32:27 -0400 Subject: [PATCH 09/32] Replace magic value "7" with string "echo" --- core/network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/network.c b/core/network.c index aa16bda9d..3cd53ef7c 100644 --- a/core/network.c +++ b/core/network.c @@ -178,7 +178,7 @@ int resolve_addr(char *address) struct addrinfo *server = NULL; - int success = getaddrinfo(address, "7", &hints, &server); + int success = getaddrinfo(address, "echo", &hints, &server); if(success != 0) return -1; From 3b52624f58f4044e655920fb4e0784be3a897b03 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 04:41:09 +0100 Subject: [PATCH 10/32] Update INSTALL.md Changing the libsodium link from a list of its release archives to the windows specific one - it is windows specific install instructions after all. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 8e67d848f..c3deec36b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -68,7 +68,7 @@ You have to [modify your PATH environment variable](http://www.computerhope.com/ Then you should either clone this repo by using git, or just download a [zip of current Master branch](https://github.com/irungentoo/ProjectTox-Core/archive/master.zip) and extract it somewhere. -After that you should get precompiled packages of libsodium from [here](https://download.libsodium.org/libsodium/releases/) and extract the archive into this repo's root. That is, `sodium` folder should be along with `core`, `testing` and other folders. +After that you should get precompiled package of libsodium from [here](https://download.libsodium.org/libsodium/releases/libsodium-win32-0.4.2.tar.gz) and extract the archive into this repo's root. That is, `sodium` folder should be along with `core`, `testing` and other folders. Navigate in `cmd` to this repo and run: ```cmd From 09a71f37ec3f18184364d4a6bcc93ab5c50da759 Mon Sep 17 00:00:00 2001 From: Ryan Lewon Date: Tue, 30 Jul 2013 07:19:07 +0000 Subject: [PATCH 11/32] New friend list function for nTox client. --- testing/nTox.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 960dfb279..b5fff89d1 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -20,10 +20,11 @@ * along with Tox. If not, see . * */ - +#include "../core/DHT.c" #include "nTox.h" #include "misc_tools.h" + #include #include #ifdef WIN32 @@ -50,6 +51,25 @@ void new_lines(char *line) do_refresh(); } +void print_friendlist() +{ + char name[MAX_NAME_LENGTH]; + uint32_t i; + + new_lines("[i] Friend List:"); + for (i=0; i <= num_requests; i++) { + char fstring[128]; + + getname(i, (uint8_t*)name); + if (strlen(name) <= 0) { + sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); + } else { + sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); + } + new_lines(fstring); + } +} + void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { @@ -104,6 +124,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) sprintf(numstring, "[i] changed nick to %s", (char*)name); new_lines(numstring); } + else if (line[1] == 'l') { + print_friendlist(); + } else if (line[1] == 's') { uint8_t status[MAX_USERSTATUS_LENGTH]; int i = 0; @@ -313,7 +336,8 @@ int main(int argc, char *argv[]) raw(); getmaxyx(stdscr,y,x); new_lines(idstring0); - new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)"); + new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); + new_lines("[i] /l list (list friends), /n nick (to change nickname), /q (to quit)"); strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); From 20aad9c73bfad93099a2614d7be1fe8a245665c7 Mon Sep 17 00:00:00 2001 From: Ryan Lewon Date: Tue, 30 Jul 2013 07:26:58 +0000 Subject: [PATCH 12/32] Removed unneeded include. Fixed formatting and cleaned up output. --- testing/nTox.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index b5fff89d1..b926ebca0 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -20,7 +20,6 @@ * along with Tox. If not, see . * */ -#include "../core/DHT.c" #include "nTox.h" #include "misc_tools.h" @@ -62,9 +61,9 @@ void print_friendlist() getname(i, (uint8_t*)name); if (strlen(name) <= 0) { - sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); - } else { - sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); + sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); + } else { + sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } new_lines(fstring); } From 84a0871cf6afad74441087939cec9c0e55d39961 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 08:52:18 +0100 Subject: [PATCH 13/32] Fixed bugs, added friend listing (slightly buggy), and changed the general aesthetics --- testing/nTox_win32.c | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 51f310012..6faae31d9 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -30,18 +30,23 @@ uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t num_requests; char line[STRING_LENGTH]; +char users_id[200]; void do_header() { - printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)\n\n"); + system("cls"); + printf(users_id); + printf("\n---------------------------------"); + printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /q (to quit), /r (reset screen)"); + printf("\n---------------------------------"); } void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) { - printf("\n[i] received friend request with message\n"); + printf("\n\n[i] received friend request with message\n"); printf((char *)data); char numchar[100]; - sprintf(numchar, "\n[i] accept request with /a %u\n", num_requests); + sprintf(numchar, "\n\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; @@ -59,7 +64,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) char* temp = asctime(timeinfo); size_t len = strlen(temp); temp[len-1]='\0'; - sprintf(msg, "\n[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp + sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp printf(msg); } @@ -68,7 +73,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); char msg[100+length]; - sprintf(msg, "\n[i] [%d] %s is now known as %s.", friendnumber, name, string); + sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); printf(msg); } @@ -76,11 +81,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); char msg[100+length+strlen(name)+1]; - sprintf(msg, "\n[i] [%d] %s's status changed to %s.", friendnumber, name, string); + sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string); printf(msg); } - void load_key() { FILE *data_file = NULL; @@ -127,6 +131,23 @@ void line_eval(char* line) printf(numstring); } + else if (line[1] == 'r') { + do_header(); + printf("\n\n"); + } + + else if (line[1] == 'l') { + printf("\n[i] Friend List\n\n"); + + int i; + + for (i=0; i <= num_requests; i++) { + char name[MAX_NAME_LENGTH]; + getname(i, (uint8_t*)name); + printf("[%d] %s\n\n", i, (uint8_t*)name); + } + } + else if (line[1] == 'd') { doMessenger(); } @@ -148,7 +169,10 @@ void line_eval(char* line) } int num = atoi(numstring); if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { - printf("\n[i] could not send message: %s\n\n", message); + printf("\n[i] could not send message: %s\n", message); + } else { + //simply for aesthetics + printf("\n"); } } @@ -222,14 +246,12 @@ int main(int argc, char *argv[]) printf("initMessenger failed"); exit(0); } - if (argc > 4) { if(strncmp(argv[4], "nokey", 6) < 0) { - //nothing - } else { - load_key(); } + } else { + load_key(); } m_callback_friendrequest(print_request); @@ -237,9 +259,6 @@ int main(int argc, char *argv[]) m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); - system("cls"); - - char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; uint32_t i; @@ -251,15 +270,13 @@ int main(int argc, char *argv[]) strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } - strcpy(idstring0,"\n[i] your ID: "); + strcpy(users_id,"[i] your ID: "); for (i=0; i<32; i++) { - strcat(idstring0,idstring1[i]); - strcat(idstring0,idstring2[i]); + strcat(users_id,idstring1[i]); + strcat(users_id,idstring2[i]); } - printf(idstring0); do_header(); - IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); @@ -271,15 +288,22 @@ int main(int argc, char *argv[]) DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); - int c; int on = 0; _beginthread(get_input, 0, NULL); while(1) { + if (on == 1 && DHT_isconnected() == -1) { + printf("\n---------------------------------"); + printf("\n[i] Disconnected from the DHT"); + printf("\n---------------------------------\n\n"); + on = 0; + } + if (on == 0 && DHT_isconnected()) { - printf("\n[i] connected to DHT\n\n"); + printf("\n[i] Connected to DHT"); + printf("\n---------------------------------\n\n"); on = 1; } From e920be4c01c3cb5493aab71268b763bea77e5104 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:21:22 +0100 Subject: [PATCH 14/32] Fixed the friends listing --- core/Messenger.c | 6 ++++++ testing/nTox_win32.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index f77b4491a..4c76dd300 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -71,6 +71,12 @@ int getfriend_id(uint8_t *client_id) return -1; } +/* Returns number of friends */ +int getnumfriends() +{ + return numfriends; +} + /* copies the public key associated to that friend id into client_id buffer. make sure that client_id is of size CLIENT_ID_SIZE. return 0 if success diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 6faae31d9..9e9a5b1a9 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -137,11 +137,11 @@ void line_eval(char* line) } else if (line[1] == 'l') { - printf("\n[i] Friend List\n\n"); + printf("\n[i] Friend List - %d\n\n", getnumfriends()); int i; - for (i=0; i <= num_requests; i++) { + for (i=0; i < getnumfriends(); i++) { char name[MAX_NAME_LENGTH]; getname(i, (uint8_t*)name); printf("[%d] %s\n\n", i, (uint8_t*)name); From d5e5412cb3b416efe40ba9ba053a0b0fd2894c1c Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:23:15 +0100 Subject: [PATCH 15/32] Slight aesthetic change --- testing/nTox_win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 9e9a5b1a9..71a291c6c 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -137,7 +137,7 @@ void line_eval(char* line) } else if (line[1] == 'l') { - printf("\n[i] Friend List - %d\n\n", getnumfriends()); + printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); int i; From 6ea5420a070ea58e910992cfaf890839a5dbc561 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:56:39 +0100 Subject: [PATCH 16/32] Implemented m_delfriend() --- testing/nTox_win32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 71a291c6c..3a9caaf5e 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -37,7 +37,7 @@ void do_header() system("cls"); printf(users_id); printf("\n---------------------------------"); - printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /q (to quit), /r (reset screen)"); + printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)"); printf("\n---------------------------------"); } @@ -149,7 +149,16 @@ void line_eval(char* line) } else if (line[1] == 'd') { - doMessenger(); + size_t len = strlen(line); + char numstring[len-3]; + int i; + for (i=0; i Date: Tue, 30 Jul 2013 12:31:02 +0300 Subject: [PATCH 17/32] Add invalid command --- testing/nTox.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/nTox.c b/testing/nTox.c index 960dfb279..201f4a54e 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -132,8 +132,11 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) else if (line[1] == 'q') { //exit endwin(); exit(EXIT_SUCCESS); + } else { + new_lines("[i] invalid command"); } } else { + new_lines("[i] invalid command"); //new_lines(line); } } From 5a6645709b72e932ff8d47f3141d3f7346b49a5f Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 07:38:47 -0400 Subject: [PATCH 18/32] Fixed build. --- testing/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index af771085b..b942e1ca2 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -15,5 +15,4 @@ endif() if(NOT WIN32) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toxic.cmake) - add_subdirectory(other) endif() From dbdeb670e467eac430789c6ec8f03ebad7a5edf1 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 08:43:44 -0400 Subject: [PATCH 19/32] Typo in readme fixed. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4381bc9f..8f903bc0a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ With the rise of governmental monitoring programs, Tox aims to be an easy to use + Tox must use UDP simply because you can't hole punch with TCP. It's possible, but it doesn't work all the time. + Every peer is represented as a byte string (the public key of the peer [client id]) + We're using torrent-style DHT so that peers can find the IP of the other peers when they have their ID. -+ Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto) ++ Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)) + When both peers are securely connect with the encryption, they can securely exchange messages, initiate a video chat, send files, etc.
+ Current build status: [![Build Status](https://travis-ci.org/irungentoo/ProjectTox-Core.png?branch=master)](https://travis-ci.org/irungentoo/ProjectTox-Core) From 3f85bdca15d2f0258413039978b6552965385335 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 08:48:36 -0400 Subject: [PATCH 20/32] Fixed warning. --- testing/DHT_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 2e9c2ac27..a215463df 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -134,7 +134,9 @@ int main(int argc, char *argv[]) char temp_id[128]; printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); - scanf("%s", temp_id); + if(scanf("%s", temp_id) != 1) + exit(0); + DHT_addfriend(hex_string_to_bin(temp_id)); /* initialize networking */ From 1ae27fb227939dc2debb69bb02530ae183663367 Mon Sep 17 00:00:00 2001 From: dypa Date: Tue, 30 Jul 2013 06:40:16 -0700 Subject: [PATCH 21/32] replace make install to checkinstall for linux installation --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index c3deec36b..d309cbcde 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,7 +5,7 @@ Build dependencies: ```bash -apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev +apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev checkinstall ``` You should get and install [libsodium](https://github.com/jedisct1/libsodium): @@ -15,7 +15,7 @@ cd libsodium git checkout tags/0.4.2 ./autogen.sh ./configure && make check -sudo make install +sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc sudo ldconfig ``` From d1a26f720f68640dad2616645d28c328ecb1cfcd Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 30 Jul 2013 11:04:59 -0400 Subject: [PATCH 22/32] Update INSTALL.md --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index c3deec36b..8ab367e71 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,7 +5,7 @@ Build dependencies: ```bash -apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev +apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake ``` You should get and install [libsodium](https://github.com/jedisct1/libsodium): From 12b19f691072b7cf292329953a9f8516dc6bf0a1 Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Tue, 30 Jul 2013 17:09:09 +0200 Subject: [PATCH 23/32] renamed getname to getfriendname and added a getname function to get the name of our client --- core/Messenger.c | 8 +++++++- core/Messenger.h | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index f77b4491a..148c3350c 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -234,12 +234,18 @@ int setname(uint8_t * name, uint16_t length) return 0; } +int getname(uint8_t *name) +{ + memcpy(name, self_name, sizeof(self_name)); + return 0; +} + /* get name of friendnumber put it in name name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. return 0 if success return -1 if failure */ -int getname(int friendnumber, uint8_t * name) +int getfriendname(int friendnumber, uint8_t * name) { if (friendnumber >= numfriends || friendnumber < 0) return -1; diff --git a/core/Messenger.h b/core/Messenger.h index 7263901c2..08f6de2ad 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -92,12 +92,16 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); return -1 if failure */ int setname(uint8_t *name, uint16_t length); +/* Get our own nickname + Set's name to the our own nickname */ +int getname(uint8_t *name); + /* get name of friendnumber put it in name name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. return 0 if success return -1 if failure */ -int getname(int friendnumber, uint8_t *name); +int getfriendname(int friendnumber, uint8_t *name); /* set our user status you are responsible for freeing status after From 2c756f1c53e0c4faad8716425eafdf1b6e58f5c0 Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Tue, 30 Jul 2013 17:10:20 +0200 Subject: [PATCH 24/32] changing testing clients to reflect changes made in core/Messenger.h --- testing/Messenger_test.c | 2 +- testing/nTox.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 0518d2848..baecea36a 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) while(1) { uint8_t name[128]; - getname(num, name); + getfriendname(num, name); printf("%s\n", name); m_sendmessage(num, (uint8_t*)"Test", 5); diff --git a/testing/nTox.c b/testing/nTox.c index 960dfb279..c960f761a 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -88,6 +88,19 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) int num = atoi(numstring); if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { new_lines("[i] could not send message"); + } else { + char name[MAX_NAME_LENGTH]; + getname((uint8_t*)name); + char msg[100+strlen(message)+strlen(name)+1]; + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + char* time = asctime(timeinfo); + size_t len = strlen(time); + time[len-1]='\0'; + sprintf(msg, "[%d] %s <%s> %s", num, time, name, message); // timestamp + new_lines(msg); } } else if (line[1] == 'n') { @@ -214,7 +227,7 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) void print_message(int friendnumber, uint8_t * string, uint16_t length) { char name[MAX_NAME_LENGTH]; - getname(friendnumber, (uint8_t*)name); + getfriendname(friendnumber, (uint8_t*)name); char msg[100+length+strlen(name)+1]; time_t rawtime; struct tm * timeinfo; @@ -229,7 +242,7 @@ void print_message(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); + getfriendname(friendnumber, (uint8_t*)name); char msg[100+length]; sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); new_lines(msg); @@ -237,7 +250,7 @@ void print_nickchange(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); + getfriendname(friendnumber, (uint8_t*)name); char msg[100+length+strlen(name)+1]; sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); new_lines(msg); From dc57b779d2e3d1df836698cd119a3890ffecf86d Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Tue, 30 Jul 2013 17:32:17 +0200 Subject: [PATCH 25/32] added utility function format_message --- testing/nTox.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index c960f761a..3d410f198 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -50,6 +50,26 @@ void new_lines(char *line) do_refresh(); } +char *format_message(char *message, int friendnum) +{ + char name[MAX_NAME_LENGTH]; + if(friendnum != -1) { + getfriendname(friendnum, (uint8_t*)name); + } else { + getname((uint8_t*)name); + } + char *msg = malloc(100+strlen(message)+strlen(name)+1); + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + char* time = asctime(timeinfo); + size_t len = strlen(time); + time[len-1]='\0'; + sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp + return msg; +} + void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { @@ -89,18 +109,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { new_lines("[i] could not send message"); } else { - char name[MAX_NAME_LENGTH]; - getname((uint8_t*)name); - char msg[100+strlen(message)+strlen(name)+1]; - time_t rawtime; - struct tm * timeinfo; - time ( &rawtime ); - timeinfo = localtime ( &rawtime ); - char* time = asctime(timeinfo); - size_t len = strlen(time); - time[len-1]='\0'; - sprintf(msg, "[%d] %s <%s> %s", num, time, name, message); // timestamp - new_lines(msg); + new_lines(format_message(message, -1)); } } else if (line[1] == 'n') { @@ -237,7 +246,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) size_t len = strlen(temp); temp[len-1]='\0'; sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp - new_lines(msg); + new_lines(format_message((char*)string, friendnumber)); } void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { From 915ffaa8889eee6153b7507c838f77dbbd7905ae Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 30 Jul 2013 11:58:51 -0400 Subject: [PATCH 26/32] Update nTox.c Added help command to nTox.c --- testing/nTox.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/nTox.c b/testing/nTox.c index f00fe200f..97a39a120 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -151,6 +151,12 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) do_refresh(); } + + else if (line[1] == 'h') { //help + new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); + new_lines("[i] /l list (list friends), /h for help, /n nick (to change nickname), /q (to quit)"); + } + else if (line[1] == 'q') { //exit endwin(); exit(EXIT_SUCCESS); From 184eaacd2a0e49277367001b209f1844ea017ace Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Tue, 30 Jul 2013 11:55:46 -0400 Subject: [PATCH 27/32] Fixed cmake --- testing/CMakeLists.txt | 6 +++--- testing/cmake/toxic.cmake | 11 ----------- testing/toxic/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 testing/cmake/toxic.cmake diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index b942e1ca2..abbc278ee 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -9,10 +9,10 @@ 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) + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) endif() if(NOT WIN32) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toxic.cmake) + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake) + add_subdirectory(toxic) endif() diff --git a/testing/cmake/toxic.cmake b/testing/cmake/toxic.cmake deleted file mode 100644 index 1ffab788d..000000000 --- a/testing/cmake/toxic.cmake +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 2.6.0) -project(toxic C) - -set(exe_name toxic) - -add_executable(${exe_name} - toxic/main.c toxic/prompt.c) - -target_link_libraries(${exe_name} curses) - -linkCoreLibraries(${exe_name}) diff --git a/testing/toxic/CMakeLists.txt b/testing/toxic/CMakeLists.txt index 43eb379ab..4f9785d53 100644 --- a/testing/toxic/CMakeLists.txt +++ b/testing/toxic/CMakeLists.txt @@ -4,8 +4,8 @@ project(toxic C) set(exe_name toxic) add_executable(${exe_name} - toxic/main.c - toxic/prompt.c) + main.c + prompt.c) target_link_libraries(${exe_name} curses) From 60250546ca7876cc013217d8e21716322dd76378 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Tue, 30 Jul 2013 13:27:32 -0400 Subject: [PATCH 28/32] Added a note about libconfig --- INSTALL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/INSTALL.md b/INSTALL.md index 9e89c8b36..3459a5c79 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -7,6 +7,7 @@ Build dependencies: ```bash apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake checkinstall ``` +Note that `libconfig-dev` should be >= 1.4. You should get and install [libsodium](https://github.com/jedisct1/libsodium): ```bash From 77fa38f597305195d50c6674150365a601c30add Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 14:32:18 -0400 Subject: [PATCH 29/32] Clarification. --- core/Messenger.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/Messenger.c b/core/Messenger.c index 3a287363c..272c5fa7a 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -242,6 +242,7 @@ int setname(uint8_t * name, uint16_t length) /* get our nickname put it in name + name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. return the length of the name */ uint16_t getself_name(uint8_t *name) { From bd695135dcb9220e6a75e48975dd8473d3d1fcbe Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 14:43:32 -0400 Subject: [PATCH 30/32] Fixed segfault. --- core/Lossless_UDP.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index eb1314d16..6be8328f5 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c @@ -308,12 +308,16 @@ IP_Port connection_ip(int connection_id) /* returns the number of packets in the queue waiting to be successfully sent. */ uint32_t sendqueue(int connection_id) { + if (connection_id < 0 || connection_id >= MAX_CONNECTIONS) + return 0; return connections[connection_id].sendbuff_packetnum - connections[connection_id].successful_sent; } /* returns the number of packets in the queue waiting to be successfully read with read_packet(...) */ uint32_t recvqueue(int connection_id) { + if (connection_id < 0 || connection_id >= MAX_CONNECTIONS) + return 0; return connections[connection_id].recv_packetnum - connections[connection_id].successful_read; } @@ -321,6 +325,8 @@ uint32_t recvqueue(int connection_id) return -1 if no packet in queue */ char id_packet(int connection_id) { + if (connection_id < 0 || connection_id >= MAX_CONNECTIONS) + return -1; if (recvqueue(connection_id) != 0 && connections[connection_id].status != 0) return connections[connection_id].recvbuffer[connections[connection_id].successful_read % MAX_QUEUE_NUM].data[0]; return -1; From fd13ae24c4f88f62ef34b40358d272747820094d Mon Sep 17 00:00:00 2001 From: Rylai Date: Tue, 30 Jul 2013 14:43:31 -0400 Subject: [PATCH 31/32] travis: use apt-get -y option instead of GNU yes The Advanced Packaging Tool has an option to automatically assume Yes to all queries. We don't need to use GNU yes for this. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9de4e2823..3386e6782 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_script: # installing libconfig, needed for DHT_bootstrap_daemon - sudo sed -i 's/precise/quantal/' /etc/apt/sources.list # needed for libconfig-dev - sudo apt-get update -qq - - yes | sudo apt-get install libconfig-dev + - sudo apt-get -y install libconfig-dev script: - mkdir build && cd build From 579fa95df45c18b79507fe96a8cca74f2be70442 Mon Sep 17 00:00:00 2001 From: Rylai Date: Tue, 30 Jul 2013 15:16:17 -0400 Subject: [PATCH 32/32] travis: use -q instead of -qq to prevent travis from sometimes timing out on long apt-get updates --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3386e6782..ff1732a06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_script: - cd .. # installing libconfig, needed for DHT_bootstrap_daemon - sudo sed -i 's/precise/quantal/' /etc/apt/sources.list # needed for libconfig-dev - - sudo apt-get update -qq + - sudo apt-get update -q - sudo apt-get -y install libconfig-dev script: