From 7b252be29921513abbd726c51de028873f0f2f9a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 24 Jan 2014 21:20:32 -0500 Subject: Set last_noreplay to zero when friend goes offline. --- toxcore/onion_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index f0f8fa70..97ef3b84 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -703,9 +703,11 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on return -1; onion_c->friends_list[friend_num].is_online = is_online; - /* Should we reset the no_replay when the other goes offline? + + /* This should prevent some clock related issues */ if (!is_online) - onion_c->friends_list[friend_num].last_noreplay = 0; */ + onion_c->friends_list[friend_num].last_noreplay = 0; + return 0; } -- cgit v1.2.3 From 0d53abebcdea36adc509ee46e2bfdacea41ac5e4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 25 Jan 2014 13:33:39 -0500 Subject: Fixed possible anonimity leak with the onion routing. --- toxcore/onion.c | 2 +- toxcore/onion_announce.c | 4 ++-- toxcore/onion_client.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/toxcore/onion.c b/toxcore/onion.c index b4d2a364..961f5bd5 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -55,7 +55,7 @@ int send_onion_packet(DHT *dht, Node_format *nodes, uint8_t *data, uint32_t leng memcpy(step1 + sizeof(IP_Port), data, length); uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; crypto_box_keypair(random_public_key, random_secret_key); diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 8150974b..2ca53896 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -61,7 +61,7 @@ int send_announce_request(DHT *dht, Node_format *nodes, uint8_t *public_key, uin ONION_ANNOUNCE_SENDBACK_DATA_LENGTH); uint8_t packet[ANNOUNCE_REQUEST_SIZE]; packet[0] = NET_PACKET_ANNOUNCE_REQUEST; - new_nonce(packet + 1); + random_nonce(packet + 1); int len = encrypt_data(nodes[3].client_id, secret_key, packet + 1, plain, sizeof(plain), packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES); @@ -253,7 +253,7 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet to_net_family(&nodes_list[i].ip_port.ip); uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)]; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 97ef3b84..a85a07a2 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -50,7 +50,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key { uint8_t plain[sizeof(uint32_t) + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; uint64_t time = unix_time(); - new_nonce(sendback); + random_nonce(sendback); memcpy(plain, &num, sizeof(uint32_t)); memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t)); memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES); @@ -420,7 +420,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32 return -1; uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; memcpy(packet, onion_c->dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); -- cgit v1.2.3 From 900e3bea6b4949cf646071967f2be93ce6009651 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 10:44:07 -0800 Subject: Improved support for Plan 9, older SunOS, and AIX. --- toxcore/tox.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/toxcore/tox.h b/toxcore/tox.h index f3118270..aff8b17e 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -24,6 +24,11 @@ #ifndef TOX_H #define TOX_H +#ifndef PLAN9 +#include +#include +#endif + #include #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) @@ -57,6 +62,18 @@ typedef short sa_family_t; extern "C" { #endif +#if defined(__AIX__) +# define _XOPEN_SOURCE 1 +#endif + +#if defined(__sun__) +#define __EXTENSIONS__ 1 /* SunOS */ +#if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) || defined(__SunOS5_9__) || defined(__SunOS5_10__) +//Nothing needed +#else +#define __MAKECONTEXT_V2_SOURCE 1 +#endif + #define TOX_MAX_NAME_LENGTH 128 #define TOX_MAX_STATUSMESSAGE_LENGTH 128 #define TOX_CLIENT_ID_SIZE 32 -- cgit v1.2.3 From b9ef9b91aff17533254073538467684d62ed465f Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 25 Jan 2014 20:00:34 -0500 Subject: Added more error checking --- .../tox_dht_bootstrap_server_daemon.c | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c index 24bb8266..1a68393f 100644 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c +++ b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c @@ -233,20 +233,29 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) } // Proceed only if all parts are present - if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE || - config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE || - config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) { + if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); + goto next; + } + + if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT); + goto next; + } + + if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS); goto next; } if (strlen(bs_public_key) != 64) { - syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_PUBLIC_KEY, bs_public_key); + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); goto next; } // not (1 <= port <= 65535) if (bs_port < 1 || bs_port > 65535) { - syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %d.\n", i, NAME_PORT, bs_port); + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port); goto next; } @@ -254,11 +263,11 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) hex_string_to_bin((char *)bs_public_key)); if (!address_resolved) { - syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_ADDRESS, bs_address); + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address); goto next; } - syslog(LOG_DEBUG, "Successfully connected to %s:%d %s\n", bs_address, bs_port, bs_public_key); + syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); next: // config_setting_lookup_string() allocates string inside and doesn't allow us to free it @@ -330,7 +339,7 @@ int main(int argc, char *argv[]) openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); if (argc < 2) { - syslog(LOG_ERR, "Please specify a configuration file. Exiting.\n"); + syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); return 1; } -- cgit v1.2.3 From 4782a8475a3476642d5a9f747a5de7080a44b1ea Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 25 Jan 2014 20:37:01 -0500 Subject: Made bootstrapping optional --- other/bootstrap_serverdaemon/conf | 35 +++++++------ .../tox_dht_bootstrap_server_daemon.c | 61 +++++++--------------- 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/other/bootstrap_serverdaemon/conf b/other/bootstrap_serverdaemon/conf index 70dbdb14..136db0f5 100644 --- a/other/bootstrap_serverdaemon/conf +++ b/other/bootstrap_serverdaemon/conf @@ -1,33 +1,34 @@ -// ProjectTox bootstrap server configuration file +// ProjectTox dht bootstrap server daemon configuration file. -// listening port +// Listening port. port = 33445 -// The key file is like a password, so keep it where no one can read it -// The daemon should have permission to read/write to it -// Remember to replace the provided example with -// your own path +// The key file is like a password, so keep it where no one can read it. +// The daemon should have permission to read/write to it. +// Remember to replace the provided example with your own path. keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys" -// The PID file written to by daemon, -// make sure that the user who runs the server -// does have permissions to write to it -// Remember to replace the provided example with -// your own path +// The PID file written to by daemon. +// Make sure that the user who runs the daemon has permissions to write to the +// PID file. +// Remember to replace the provided example with your own path. pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid" +// Enable IPv6. enable_ipv6 = false -// Automatically bootstrap with nodes on local network +// Automatically bootstrap with nodes on local area network. enable_lan_discovery = true -// Any number of nodes the daemon will bootstrap itself from -// Remember to replace the provided example with -// your own server list +// Any number of servers the daemon will bootstrap itself from. +// Remember to replace the provided example with your own server list. +// You may leave the list empty or remove "bootstrap_servers" complitely, +// in both cases this will be interpreted as if you don't want to bootstrap +// from anyone. bootstrap_servers = ( { // Server 1 - // any ipv4 or ipv6, depending if `enable_ipv6` is set or not - // also any US-ASCII domain name + // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also + // any US-ASCII domain name. address = "198.46.136.167" port = 33445 public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c index 1a68393f..a6cffb54 100644 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c +++ b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c @@ -186,8 +186,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi // Bootstraps servers listed in the config file // -// returns 1 on success -// 0 on failure, either no or only some servers were bootstrapped +// returns 1 on success, some or no bootstrap servers were added +// 0 on failure, a error accured while parsing config file int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) { @@ -210,9 +210,15 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); if (server_list == NULL) { - syslog(LOG_ERR, "No '%s' setting in configuration file.\n", NAME_BOOTSTRAP_SERVERS); + syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS); config_destroy(&cfg); - return 0; + return 1; + } + + if (config_setting_length(server_list) == 0) { + syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n"); + config_destroy(&cfg); + return 1; } int bs_port; @@ -232,7 +238,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) return 0; } - // Proceed only if all parts are present + // Check that all settings are present if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); goto next; @@ -248,6 +254,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } + // Process settings if (strlen(bs_public_key) != 64) { syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); goto next; @@ -282,36 +289,6 @@ next: return 1; } -// Checks if we are connected to the DHT -// -// returns 1 on success -// 0 on failure - -int try_connect(DHT *dht, int port, int enable_lan_discovery) -{ - uint16_t htons_port = htons(port); - - int i; - - for (i = 0; i < 100; i ++) { - do_DHT(dht); - - if (enable_lan_discovery) { - send_LANdiscovery(htons_port, dht); - } - - networking_poll(dht->c->lossless_udp->net); - - if (DHT_isconnected(dht)) { - return 1; - } - - sleep; - } - - return 0; -} - // Prints public key void print_public_key(uint8_t *public_key) @@ -404,13 +381,6 @@ int main(int argc, char *argv[]) return 1; } - if (try_connect(dht, port, enable_lan_discovery)) { - syslog(LOG_INFO, "Successfully connected to DHT\n"); - } else { - syslog(LOG_ERR, "Couldn't connect to the DHT. Check settings and network connections. Exiting.\n"); - return 1; - } - print_public_key(dht->c->self_public_key); // Write the PID file @@ -463,6 +433,8 @@ int main(int argc, char *argv[]) uint64_t last_LANdiscovery = 0; uint16_t htons_port = htons(port); + int waiting_for_dht_connection = 1; + while (1) { do_DHT(dht); @@ -473,6 +445,11 @@ int main(int argc, char *argv[]) networking_poll(dht->net); + if (waiting_for_dht_connection && DHT_isconnected(dht)) { + syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n"); + waiting_for_dht_connection = 0; + } + sleep; } -- cgit v1.2.3 From 553472442fd1ddcf224b7a3bbfc1ed51c2cedfad Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 25 Jan 2014 21:00:31 -0500 Subject: Shortened daemon's name --- other/bootstrap_serverdaemon/Makefile.inc | 12 +- other/bootstrap_serverdaemon/README.md | 22 +- other/bootstrap_serverdaemon/conf | 4 +- .../bootstrap_serverdaemon/tox_bootstrap_daemon.c | 457 +++++++++++++++++++++ .../bootstrap_serverdaemon/tox_bootstrap_daemon.sh | 110 +++++ .../tox_dht_bootstrap_server_daemon.c | 457 --------------------- .../tox_dht_bootstrap_server_daemon.sh | 109 ----- 7 files changed, 586 insertions(+), 585 deletions(-) create mode 100644 other/bootstrap_serverdaemon/tox_bootstrap_daemon.c create mode 100644 other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh delete mode 100644 other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c delete mode 100644 other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh diff --git a/other/bootstrap_serverdaemon/Makefile.inc b/other/bootstrap_serverdaemon/Makefile.inc index 5ab17b56..effe59e8 100644 --- a/other/bootstrap_serverdaemon/Makefile.inc +++ b/other/bootstrap_serverdaemon/Makefile.inc @@ -1,17 +1,17 @@ if BUILD_DHT_BOOTSTRAP_DAEMON -noinst_PROGRAMS += tox_dht_bootstrap_server_daemon +noinst_PROGRAMS += tox_bootstrap_daemon -tox_dht_bootstrap_server_daemon_SOURCES = \ - ../other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c +tox_bootstrap_daemon_SOURCES = \ + ../other/bootstrap_serverdaemon/tox_bootstrap_daemon.c -tox_dht_bootstrap_server_daemon_CFLAGS = \ +tox_bootstrap_daemon_CFLAGS = \ -I$(top_srcdir)/other/bootstrap_serverdaemon \ $(LIBSODIUM_CFLAGS) \ $(NACL_CFLAGS) \ $(LIBCONFIG_CFLAGS) -tox_dht_bootstrap_server_daemon_LDADD = \ +tox_bootstrap_daemon_LDADD = \ $(LIBSODIUM_LDFLAGS) \ $(NACL_LDFLAGS) \ libtoxcore.la \ @@ -23,5 +23,5 @@ endif EXTRA_DIST += \ $(top_srcdir)/other/bootstrap_serverdaemon/conf \ - $(top_srcdir)/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh + $(top_srcdir)/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh \ No newline at end of file diff --git a/other/bootstrap_serverdaemon/README.md b/other/bootstrap_serverdaemon/README.md index 30cb14aa..53a25cdb 100644 --- a/other/bootstrap_serverdaemon/README.md +++ b/other/bootstrap_serverdaemon/README.md @@ -2,44 +2,44 @@ The following commands are to be executed as root: -1. In `tox_dht_bootstrap_server_daemon.sh` file change: +1. In `tox_bootstrap_daemon.sh` file change: - `CFG` to where your config file (`conf`) will be; read rights required - `DAEMON` to point to the executable - `PIDFILE` to point to a pid file daemon would have rights to create -2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_dht_bootstrap_server_daemon.sh` +2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_bootstrap_daemon.sh` 3. Execute: ``` -mv tox_dht_bootstrap_server_daemon.sh /etc/init.d/tox_dht_bootstrap_server_daemon +mv tox_bootstrap_daemon.sh /etc/init.d/tox_bootstrap_daemon ``` *(note that we removed `.sh` ending)* 4. Give the right permissions to this file: ``` -chmod 755 /etc/init.d/tox_dht_bootstrap_server_daemon +chmod 755 /etc/init.d/tox_bootstrap_daemon ``` 5. Execute: ``` -update-rc.d tox_dht_bootstrap_server_daemon defaults +update-rc.d tox_bootstrap_daemon defaults ``` 6. Start the service: ``` -service tox_dht_bootstrap_server_daemon start +service tox_bootstrap_daemon start ``` 7. Verify that the service is running: ``` -service tox_dht_bootstrap_server_daemon status +service tox_bootstrap_daemon status ``` -- You can see daemon's log with ``` -grep "tox_dht_bootstrap_server_daemon" /var/log/syslog +grep "tox_bootstrap_daemon" /var/log/syslog ``` **Note that system log is where you find your public key** @@ -50,12 +50,12 @@ grep "tox_dht_bootstrap_server_daemon" /var/log/syslog 1. Check the log for errors with ``` -grep "tox_dht_bootstrap_server_daemon" /var/log/syslog +grep "tox_bootstrap_daemon" /var/log/syslog ``` -2. Check that paths in the beginning of `/etc/init.d/tox_dht_bootstrap_server_daemon` are valid +2. Check that paths in the beginning of `/etc/init.d/tox_bootstrap_daemon` are valid -3. Make sure that `PIDFILE` from `/etc/init.d/tox_dht_bootstrap_server_daemon` matches with the `pid_file_path` from `conf` +3. Make sure that `PIDFILE` from `/etc/init.d/tox_bootstrap_daemon` matches with the `pid_file_path` from `conf` 4. Make sure you have write permission to keys and pid files diff --git a/other/bootstrap_serverdaemon/conf b/other/bootstrap_serverdaemon/conf index 136db0f5..8451d9a0 100644 --- a/other/bootstrap_serverdaemon/conf +++ b/other/bootstrap_serverdaemon/conf @@ -6,13 +6,13 @@ port = 33445 // The key file is like a password, so keep it where no one can read it. // The daemon should have permission to read/write to it. // Remember to replace the provided example with your own path. -keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys" +keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" // The PID file written to by daemon. // Make sure that the user who runs the daemon has permissions to write to the // PID file. // Remember to replace the provided example with your own path. -pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid" +pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" // Enable IPv6. enable_ipv6 = false diff --git a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c new file mode 100644 index 00000000..e82e49cd --- /dev/null +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c @@ -0,0 +1,457 @@ +/* tox_bootstrap_daemon.c + * + * Tox DHT bootstrap server daemon. + * + * Copyright (C) 2014 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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "../../toxcore/DHT.h" +#include "../../toxcore/friend_requests.h" +#include "../../toxcore/LAN_discovery.h" + +#include "../../testing/misc_tools.c" + +#define DAEMON_NAME "tox_bootstrap_daemon" + +#define SLEEP_TIME_MILLISECONDS 30 +#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) + +#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" +#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" +#define DEFAULT_PORT 33445 +#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false +#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false + + +// Uses the already existing key or creates one if it didn't exist +// +// retirns 1 on success +// 0 on failure - no keys were read or stored + +int manage_keys(DHT *dht, char *keys_file_path) +{ + const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; + uint8_t keys[KEYS_SIZE]; + FILE *keys_file; + + // Check if file exits, proceed to open and load keys + keys_file = fopen(keys_file_path, "r"); + + if (keys_file != NULL) { + size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); + + if (read_size != KEYS_SIZE) { + return 0; + } + + load_keys(dht->c, keys); + } else { + // Otherwise save new keys + new_keys(dht->c); + save_keys(dht->c, keys); + + keys_file = fopen(keys_file_path, "w"); + + size_t write_size = fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); + + if (write_size != KEYS_SIZE) { + return 0; + } + } + + fclose(keys_file); + + // We want our DHT public key to be the same as our internal one since this is a bootstrap server + memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); + memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); + + return 1; +} + +// Gets general config options +// +// Important: you are responsible for freeing `pid_file_path` and `keys_file_path` +// +// returns 1 on success +// 0 on failure, doesn't modify any data pointed by arguments + +int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, + int *enable_lan_discovery) +{ + config_t cfg; + + const char *NAME_PORT = "port"; + const char *NAME_PID_FILE_PATH = "pid_file_path"; + const char *NAME_KEYS_FILE_PATH = "keys_file_path"; + const char *NAME_ENABLE_IPV6 = "enable_ipv6"; + const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; + + config_init(&cfg); + + // Read the file. If there is an error, report it and exit. + if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { + syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + return 0; + } + + // Get port + if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT); + syslog(LOG_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT); + *port = DEFAULT_PORT; + } + + // Get PID file location + const char *tmp_pid_file; + + if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH); + tmp_pid_file = DEFAULT_PID_FILE_PATH; + } + + *pid_file_path = malloc(strlen(tmp_pid_file) + 1); + strcpy(*pid_file_path, tmp_pid_file); + + // Get keys file location + const char *tmp_keys_file; + + if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH); + tmp_keys_file = DEFAULT_KEYS_FILE_PATH; + } + + *keys_file_path = malloc(strlen(tmp_keys_file) + 1); + strcpy(*keys_file_path, tmp_keys_file); + + // Get IPv6 option + if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false"); + *enable_ipv6 = DEFAULT_ENABLE_IPV6; + } + + // Get LAN discovery option + if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, + DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); + *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; + } + + config_destroy(&cfg); + + syslog(LOG_DEBUG, "Successfully read:\n"); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); + syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); + + return 1; +} + +// Bootstraps servers listed in the config file +// +// returns 1 on success, some or no bootstrap servers were added +// 0 on failure, a error accured while parsing config file + +int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) +{ + const char *NAME_BOOTSTRAP_SERVERS = "bootstrap_servers"; + + const char *NAME_PUBLIC_KEY = "public_key"; + const char *NAME_PORT = "port"; + const char *NAME_ADDRESS = "address"; + + config_t cfg; + + config_init(&cfg); + + if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { + syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + return 0; + } + + config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); + + if (server_list == NULL) { + syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS); + config_destroy(&cfg); + return 1; + } + + if (config_setting_length(server_list) == 0) { + syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n"); + config_destroy(&cfg); + return 1; + } + + int bs_port; + const char *bs_address; + const char *bs_public_key; + + config_setting_t *server; + + int i = 0; + + while (config_setting_length(server_list)) { + + server = config_setting_get_elem(server_list, 0); + + if (server == NULL) { + config_destroy(&cfg); + return 0; + } + + // Check that all settings are present + if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); + goto next; + } + + if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT); + goto next; + } + + if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS); + goto next; + } + + // Process settings + if (strlen(bs_public_key) != 64) { + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); + goto next; + } + + // not (1 <= port <= 65535) + if (bs_port < 1 || bs_port > 65535) { + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port); + goto next; + } + + const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), + hex_string_to_bin((char *)bs_public_key)); + + if (!address_resolved) { + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address); + goto next; + } + + syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); + +next: + // config_setting_lookup_string() allocates string inside and doesn't allow us to free it + // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element + // which will cause libconfig to free allocated strings + config_setting_remove_elem(server_list, 0); + i++; + } + + config_destroy(&cfg); + + return 1; +} + +// Prints public key + +void print_public_key(uint8_t *public_key) +{ + char buffer[64 + 1]; + int index = 0; + + int i; + + for (i = 0; i < 32; i++) { + if (public_key[i] < 16) { + index += sprintf(buffer + index, "0"); + } + + index += sprintf(buffer + index, "%hhX", public_key[i]); + } + + syslog(LOG_INFO, "Public Key: %s\n", buffer); + + return; +} + +int main(int argc, char *argv[]) +{ + openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); + + if (argc < 2) { + syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); + return 1; + } + + char *cfg_file_path = argv[1]; + char *pid_file_path, *keys_file_path; + int port; + int enable_ipv6; + int enable_lan_discovery; + + if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery)) { + syslog(LOG_DEBUG, "General config read successfully\n"); + } else { + syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); + return 1; + } + + // not (1 <= port <= 65535) + if (port < 1 || port > 65535) { + syslog(LOG_ERR, "Invalid port: %d, must be 1 <= port <= 65535. Exiting.\n", port); + return 1; + } + + // Check if the PID file exists + if (fopen(pid_file_path, "r")) { + syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); + return 1; + } + + IP ip; + ip_init(&ip, enable_ipv6); + + DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); + + if (dht == NULL) { + syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); + return 1; + } + + Onion *onion = new_onion(dht); + Onion_Announce *onion_a = new_onion_announce(dht); + + if (!(onion && onion_a)) { + syslog(LOG_ERR, "Couldn't initialize Tox Onion. Exiting.\n"); + return 1; + } + + if (enable_lan_discovery) { + LANdiscovery_init(dht); + } + + if (manage_keys(dht, keys_file_path)) { + syslog(LOG_DEBUG, "Keys are managed successfully\n"); + } else { + syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); + return 1; + } + + if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { + syslog(LOG_DEBUG, "List of bootstrap servers read successfully\n"); + } else { + syslog(LOG_ERR, "Couldn't read list of bootstrap servers in %s. Exiting.\n", cfg_file_path); + return 1; + } + + print_public_key(dht->c->self_public_key); + + // Write the PID file + FILE *pidf = fopen(pid_file_path, "w"); + + if (pidf == NULL) { + syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); + return 1; + } + + free(pid_file_path); + free(keys_file_path); + + // Fork off from the parent process + pid_t pid = fork(); + + if (pid < 0) { + syslog(LOG_ERR, "Forking failed. Exiting.\n"); + return 1; + } + + if (pid > 0) { + syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); + return 0; + } + + // Change the file mode mask + umask(0); + + fprintf(pidf, "%d\n", pid); + fclose(pidf); + + // Create a new SID for the child process + if (setsid() < 0) { + syslog(LOG_ERR, "SID creation failure. Exiting.\n"); + return 1; + } + + // Change the current working directory + if ((chdir("/")) < 0) { + syslog(LOG_ERR, "Couldn't change working directory to '/'. Exiting.\n"); + return 1; + } + + // Go quiet + close(STDOUT_FILENO); + close(STDIN_FILENO); + close(STDERR_FILENO); + + uint64_t last_LANdiscovery = 0; + uint16_t htons_port = htons(port); + + int waiting_for_dht_connection = 1; + + while (1) { + do_DHT(dht); + + if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { + send_LANdiscovery(htons_port, dht); + last_LANdiscovery = unix_time(); + } + + networking_poll(dht->net); + + if (waiting_for_dht_connection && DHT_isconnected(dht)) { + syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n"); + waiting_for_dht_connection = 0; + } + + sleep; + } + + return 1; +} diff --git a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh new file mode 100644 index 00000000..83d9a119 --- /dev/null +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh @@ -0,0 +1,110 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: tox_bootstrap_daemon +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts the Tox DHT bootstrapping server daemon +# Description: Starts the Tox DHT bootstrapping server daemon +### END INIT INFO + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="Tox DHT bootstrap server daemon" +NAME=tox_bootstrap_daemon +# You may want to change USER if you are using it anywhere else +USER=tom +CFG=/home/$USER/.$NAME/conf +DAEMON=/home/$USER/$NAME +DAEMON_ARGS="$CFG" +PIDFILE=/home/$USER/.$NAME/pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Read configuration variable file if it is present +#[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + $DAEMON_ARGS \ + || return 2 + sleep 1 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + + restart) #|force-reload) + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 + exit 3 + ;; +esac diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c deleted file mode 100644 index a6cffb54..00000000 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c +++ /dev/null @@ -1,457 +0,0 @@ -/* tox_dht_bootstrap_server_daemon - * - * A simple DHT bootstrap server for tox - daemon edition. - * - * Copyright (C) 2014 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 -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "../../toxcore/DHT.h" -#include "../../toxcore/friend_requests.h" -#include "../../toxcore/LAN_discovery.h" - -#include "../../testing/misc_tools.c" - -#define DAEMON_NAME "tox_dht_bootstrap_server_daemon" - -#define SLEEP_TIME_MILLISECONDS 30 -#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) - -#define DEFAULT_PID_FILE_PATH ".tox_dht_bootstrap_server_daemon.pid" -#define DEFAULT_KEYS_FILE_PATH ".tox_dht_bootstrap_server_daemon.keys" -#define DEFAULT_PORT 33445 -#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false -#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false - - -// Uses the already existing key or creates one if it didn't exist -// -// retirns 1 on success -// 0 on failure - no keys were read or stored - -int manage_keys(DHT *dht, char *keys_file_path) -{ - const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; - uint8_t keys[KEYS_SIZE]; - FILE *keys_file; - - // Check if file exits, proceed to open and load keys - keys_file = fopen(keys_file_path, "r"); - - if (keys_file != NULL) { - size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); - - if (read_size != KEYS_SIZE) { - return 0; - } - - load_keys(dht->c, keys); - } else { - // Otherwise save new keys - new_keys(dht->c); - save_keys(dht->c, keys); - - keys_file = fopen(keys_file_path, "w"); - - size_t write_size = fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); - - if (write_size != KEYS_SIZE) { - return 0; - } - } - - fclose(keys_file); - - // We want our DHT public key to be the same as our internal one since this is a bootstrap server - memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); - memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); - - return 1; -} - -// Gets general config options -// -// Important: you are responsible for freeing `pid_file_path` and `keys_file_path` -// -// returns 1 on success -// 0 on failure, doesn't modify any data pointed by arguments - -int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, - int *enable_lan_discovery) -{ - config_t cfg; - - const char *NAME_PORT = "port"; - const char *NAME_PID_FILE_PATH = "pid_file_path"; - const char *NAME_KEYS_FILE_PATH = "keys_file_path"; - const char *NAME_ENABLE_IPV6 = "enable_ipv6"; - const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; - - config_init(&cfg); - - // Read the file. If there is an error, report it and exit. - if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { - syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); - config_destroy(&cfg); - return 0; - } - - // Get port - if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) { - syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT); - syslog(LOG_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT); - *port = DEFAULT_PORT; - } - - // Get PID file location - const char *tmp_pid_file; - - if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) { - syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH); - syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH); - tmp_pid_file = DEFAULT_PID_FILE_PATH; - } - - *pid_file_path = malloc(strlen(tmp_pid_file) + 1); - strcpy(*pid_file_path, tmp_pid_file); - - // Get keys file location - const char *tmp_keys_file; - - if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) { - syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH); - syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH); - tmp_keys_file = DEFAULT_KEYS_FILE_PATH; - } - - *keys_file_path = malloc(strlen(tmp_keys_file) + 1); - strcpy(*keys_file_path, tmp_keys_file); - - // Get IPv6 option - if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) { - syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6); - syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false"); - *enable_ipv6 = DEFAULT_ENABLE_IPV6; - } - - // Get LAN discovery option - if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { - syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); - syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, - DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false"); - *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; - } - - config_destroy(&cfg); - - syslog(LOG_DEBUG, "Successfully read:\n"); - syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path); - syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); - syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); - syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); - syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); - - return 1; -} - -// Bootstraps servers listed in the config file -// -// returns 1 on success, some or no bootstrap servers were added -// 0 on failure, a error accured while parsing config file - -int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) -{ - const char *NAME_BOOTSTRAP_SERVERS = "bootstrap_servers"; - - const char *NAME_PUBLIC_KEY = "public_key"; - const char *NAME_PORT = "port"; - const char *NAME_ADDRESS = "address"; - - config_t cfg; - - config_init(&cfg); - - if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { - syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); - config_destroy(&cfg); - return 0; - } - - config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); - - if (server_list == NULL) { - syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS); - config_destroy(&cfg); - return 1; - } - - if (config_setting_length(server_list) == 0) { - syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n"); - config_destroy(&cfg); - return 1; - } - - int bs_port; - const char *bs_address; - const char *bs_public_key; - - config_setting_t *server; - - int i = 0; - - while (config_setting_length(server_list)) { - - server = config_setting_get_elem(server_list, 0); - - if (server == NULL) { - config_destroy(&cfg); - return 0; - } - - // Check that all settings are present - if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { - syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); - goto next; - } - - if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) { - syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT); - goto next; - } - - if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { - syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS); - goto next; - } - - // Process settings - if (strlen(bs_public_key) != 64) { - syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); - goto next; - } - - // not (1 <= port <= 65535) - if (bs_port < 1 || bs_port > 65535) { - syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port); - goto next; - } - - const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), - hex_string_to_bin((char *)bs_public_key)); - - if (!address_resolved) { - syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address); - goto next; - } - - syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); - -next: - // config_setting_lookup_string() allocates string inside and doesn't allow us to free it - // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element - // which will cause libconfig to free allocated strings - config_setting_remove_elem(server_list, 0); - i++; - } - - config_destroy(&cfg); - - return 1; -} - -// Prints public key - -void print_public_key(uint8_t *public_key) -{ - char buffer[64 + 1]; - int index = 0; - - int i; - - for (i = 0; i < 32; i++) { - if (public_key[i] < 16) { - index += sprintf(buffer + index, "0"); - } - - index += sprintf(buffer + index, "%hhX", public_key[i]); - } - - syslog(LOG_INFO, "Public Key: %s\n", buffer); - - return; -} - -int main(int argc, char *argv[]) -{ - openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); - - if (argc < 2) { - syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); - return 1; - } - - char *cfg_file_path = argv[1]; - char *pid_file_path, *keys_file_path; - int port; - int enable_ipv6; - int enable_lan_discovery; - - if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery)) { - syslog(LOG_DEBUG, "General config read successfully\n"); - } else { - syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); - return 1; - } - - // not (1 <= port <= 65535) - if (port < 1 || port > 65535) { - syslog(LOG_ERR, "Invalid port: %d, must be 1 <= port <= 65535. Exiting.\n", port); - return 1; - } - - // Check if the PID file exists - if (fopen(pid_file_path, "r")) { - syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); - return 1; - } - - IP ip; - ip_init(&ip, enable_ipv6); - - DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); - - if (dht == NULL) { - syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); - return 1; - } - - Onion *onion = new_onion(dht); - Onion_Announce *onion_a = new_onion_announce(dht); - - if (!(onion && onion_a)) { - syslog(LOG_ERR, "Couldn't initialize Tox Onion. Exiting.\n"); - return 1; - } - - if (enable_lan_discovery) { - LANdiscovery_init(dht); - } - - if (manage_keys(dht, keys_file_path)) { - syslog(LOG_DEBUG, "Keys are managed successfully\n"); - } else { - syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); - return 1; - } - - if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { - syslog(LOG_DEBUG, "List of bootstrap servers read successfully\n"); - } else { - syslog(LOG_ERR, "Couldn't read list of bootstrap servers in %s. Exiting.\n", cfg_file_path); - return 1; - } - - print_public_key(dht->c->self_public_key); - - // Write the PID file - FILE *pidf = fopen(pid_file_path, "w"); - - if (pidf == NULL) { - syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); - return 1; - } - - free(pid_file_path); - free(keys_file_path); - - // Fork off from the parent process - pid_t pid = fork(); - - if (pid < 0) { - syslog(LOG_ERR, "Forking failed. Exiting.\n"); - return 1; - } - - if (pid > 0) { - syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); - return 0; - } - - // Change the file mode mask - umask(0); - - fprintf(pidf, "%d\n", pid); - fclose(pidf); - - // Create a new SID for the child process - if (setsid() < 0) { - syslog(LOG_ERR, "SID creation failure. Exiting.\n"); - return 1; - } - - // Change the current working directory - if ((chdir("/")) < 0) { - syslog(LOG_ERR, "Couldn't change working directory to '/'. Exiting.\n"); - return 1; - } - - // Go quiet - close(STDOUT_FILENO); - close(STDIN_FILENO); - close(STDERR_FILENO); - - uint64_t last_LANdiscovery = 0; - uint16_t htons_port = htons(port); - - int waiting_for_dht_connection = 1; - - while (1) { - do_DHT(dht); - - if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { - send_LANdiscovery(htons_port, dht); - last_LANdiscovery = unix_time(); - } - - networking_poll(dht->net); - - if (waiting_for_dht_connection && DHT_isconnected(dht)) { - syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n"); - waiting_for_dht_connection = 0; - } - - sleep; - } - - return 1; -} diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh deleted file mode 100644 index 678db5e3..00000000 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh +++ /dev/null @@ -1,109 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: tox_dht_bootstrap_server_daemon -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Starts the Tox bootstrapping server -# Description: Starts the Tox bootstrapping server -### END INIT INFO - -# PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/sbin:/usr/sbin:/bin:/usr/bin -DESC="ProjectTox bootstrap server daemon" -NAME=tox_dht_bootstrap_server_daemon -USER=tom -CFG=/home/$USER/.$NAME/conf -DAEMON=/home/$USER/$NAME -DAEMON_ARGS="$CFG" -PIDFILE=/home/$USER/.$NAME/pid -SCRIPTNAME=/etc/init.d/$NAME - -# Exit if the package is not installed -[ -x "$DAEMON" ] || exit 0 - -# Read configuration variable file if it is present -#[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -. /lib/init/vars.sh - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.2-14) to ensure that this file is present -# and status_of_proc is working. -. /lib/lsb/init-functions - -# -# Function that starts the daemon/service -# -do_start() -{ - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ - || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_ARGS \ - || return 2 - sleep 1 -} - -# -# Function that stops the daemon/service -# -do_stop() -{ - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON - RETVAL="$?" - [ "$RETVAL" = 2 ] && return 2 - - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON - [ "$?" = 2 ] && return 2 - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE - return "$RETVAL" -} - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - do_stop - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - status) - status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - - restart) #|force-reload) - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - do_start - case "$?" in - 0) log_end_msg 0 ;; - 1) log_end_msg 1 ;; # Old process is still running - *) log_end_msg 1 ;; # Failed to start - esac - ;; - *) - # Failed to stop - log_end_msg 1 - ;; - esac - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 - exit 3 - ;; -esac -- cgit v1.2.3 From 86ba73519848011bacd3cdd690eeaf402af21989 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 25 Jan 2014 21:09:26 -0500 Subject: Improved hole punching a bit. --- toxcore/DHT.c | 23 +++++++++++++++++++++-- toxcore/DHT.h | 3 +++ toxcore/ping.c | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index d5808313..65fe6ae0 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -46,11 +46,13 @@ /* Ping interval in seconds for each random sending of a get nodes request. */ #define GET_NODE_INTERVAL 5 -#define MAX_PUNCHING_PORTS 32 +#define MAX_PUNCHING_PORTS 48 /* Interval in seconds between punching attempts*/ #define PUNCH_INTERVAL 3 +#define MAX_NORMAL_PUNCHING_TRIES 5 + #define NAT_PING_REQUEST 0 #define NAT_PING_RESPONSE 1 @@ -1792,8 +1794,23 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, ip_copy(&pinging.ip, &ip); pinging.port = htons(firstport); send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); + + if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { + top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS / 2; + uint16_t port1 = 1024; + uint16_t port2 = ~0; + + for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { + pinging.port = htons(port1 + i); + send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); + pinging.port = htons(port2 - i); + send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); + } + + dht->friends_list[friend_num].nat.punching_index2 = i; + } } else { - for (i = dht->friends_list[friend_num].nat.punching_index; i != top; i++) { + for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { /* TODO: Improve port guessing algorithm. */ uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); IP_Port pinging; @@ -1804,6 +1821,8 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, dht->friends_list[friend_num].nat.punching_index = i; } + + ++dht->friends_list[friend_num].nat.tries; } static void do_NAT(DHT *dht) diff --git a/toxcore/DHT.h b/toxcore/DHT.h index eb889d5d..b649338a 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -109,6 +109,9 @@ typedef struct { /* 1 if currently hole punching, otherwise 0 */ uint8_t hole_punching; uint32_t punching_index; + uint32_t tries; + uint32_t punching_index2; + uint64_t punching_timestamp; uint64_t recvNATping_timestamp; uint64_t NATping_id; diff --git a/toxcore/ping.c b/toxcore/ping.c index a37b531d..6b1b906a 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -35,7 +35,7 @@ #include "network.h" #include "util.h" -#define PING_NUM_MAX 384 +#define PING_NUM_MAX 512 /* Ping newly announced nodes to ping per TIME_TOPING seconds*/ #define TIME_TOPING 5 -- cgit v1.2.3 From d89bd2a6a99701f6367486f70ad48094e5d73fd4 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 18:44:36 -0800 Subject: Not my finest moment --- toxcore/tox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toxcore/tox.h b/toxcore/tox.h index aff8b17e..072979c8 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -24,7 +24,7 @@ #ifndef TOX_H #define TOX_H -#ifndef PLAN9 +#ifdef PLAN9 #include #include #endif -- cgit v1.2.3 From 803c6f41d7c5dd177c7ebd3c75e53908da80dedf Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 18:48:49 -0800 Subject: Moved to networking.h Plan 9 requires u.h in every file --- toxcore/network.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/toxcore/network.h b/toxcore/network.h index 0e0f0af9..ae2cb081 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -24,6 +24,11 @@ #ifndef NETWORK_H #define NETWORK_H +#ifdef PLAN9 +#include //Plan 9 requires this is imported first +#include +#endif + #include #include #include @@ -75,6 +80,18 @@ typedef int sock_t; #endif +#if defined(__AIX__) +# define _XOPEN_SOURCE 1 +#endif + +#if defined(__sun__) +#define __EXTENSIONS__ 1 // SunOS! +#if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) || defined(__SunOS5_9__) || defined(__SunOS5_10__) +//Nothing needed +#else +#define __MAKECONTEXT_V2_SOURCE 1 +#endif + #ifndef VANILLA_NACL /* We use libsodium by default. */ #include -- cgit v1.2.3 From 4e84497a68de79d5f52471f612a8a0e93c133078 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 18:50:23 -0800 Subject: Moved Unix support Networking.h is imported by everything. --- toxcore/tox.h | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/toxcore/tox.h b/toxcore/tox.h index 072979c8..7151c9ae 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -23,12 +23,6 @@ #ifndef TOX_H #define TOX_H - -#ifdef PLAN9 -#include -#include -#endif - #include #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) @@ -62,18 +56,6 @@ typedef short sa_family_t; extern "C" { #endif -#if defined(__AIX__) -# define _XOPEN_SOURCE 1 -#endif - -#if defined(__sun__) -#define __EXTENSIONS__ 1 /* SunOS */ -#if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) || defined(__SunOS5_9__) || defined(__SunOS5_10__) -//Nothing needed -#else -#define __MAKECONTEXT_V2_SOURCE 1 -#endif - #define TOX_MAX_NAME_LENGTH 128 #define TOX_MAX_STATUSMESSAGE_LENGTH 128 #define TOX_CLIENT_ID_SIZE 32 -- cgit v1.2.3 From c766ff95d023b905ad6ded50e57bb89e94627693 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 18:51:55 -0800 Subject: That newline looks cleaner --- toxcore/tox.h | 1 + 1 file changed, 1 insertion(+) diff --git a/toxcore/tox.h b/toxcore/tox.h index 7151c9ae..f3118270 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -23,6 +23,7 @@ #ifndef TOX_H #define TOX_H + #include #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) -- cgit v1.2.3 From 2ead95b56bb11643d6d3edb911e22a52c2fb6b68 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 19:02:47 -0800 Subject: made install.md Unix friendly --- INSTALL.md | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 03e3da2c..4f98831d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,7 +1,7 @@ #Install Instructions - [Installation](#installation) - - [Linux](#linux) + - [Unix like (Linux)](#unix) - [OS X](#osx) - [Homebrew](#homebrew) - [Non-Homebrew](#non-homebrew) @@ -10,11 +10,15 @@ ##Installation - -###Linux: + +###Most Unix like OSes (Linux): Build dependencies: +Note: package fetching commands may vary by OS. + +On Ubuntu: + ```bash sudo apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev checkinstall check git libswscale-dev libsdl-dev libopenal-dev libopus-dev libvpx-dev yasm ``` @@ -24,7 +28,7 @@ On Fedora: ```bash yum groupinstall "Development Tools" yum install libtool autoconf automake libconfig-devel ncurses-devel check check-devel -``` +``` Note that `libconfig-dev` should be >= 1.4. @@ -54,7 +58,7 @@ make check sudo make install cd .. ``` -If your default prefix is /usr/local and you happen to get an error that says "error while loading shared libraries: libtoxcore.so.0: cannot open shared object file: No such file or directory", then you can try running ```sudo ldconfig```. If that doesn't fix it, run: +If your default prefix is /usr/local and you happen to get an error that says "error while loading shared libraries: libtoxcore.so.0: cannot open shared object file: No such file or directory", then you can try running ```sudo ldconfig```, this is an issue common on Linux. If that doesn't fix it, run: ``` echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf sudo ldconfig @@ -100,13 +104,6 @@ The following libraries are required along with libsodium and cmake for Mountain There are no binaries/executables going to /bin/ or /usr/bin/ now. Everything is compiled and ran from the inside your local branch. See [Usage](#usage) below. ####Homebrew: -To install from the formula: -```bash -brew tap Tox/tox -brew install --HEAD libtoxcore -``` - -To do it manually: ``` brew install libtool automake autoconf libconfig libsodium check ``` @@ -119,21 +116,6 @@ autoreconf -i make make install ``` - -If execution fails with errors like "dyld: Library not loaded: /opt/tox-im/lib/libtoxcore.0.dylib", you may need to specify libsodium path: - -Determine paths: -``` -brew list libsodium -``` - -Configure include and lib folder and build again: -```bash -./configure--with-libsodium-headers=/usr/local/Cellar/libsodium/0.4.5/include/ --with-libsodium-libs=/usr/local/Cellar/libsodium/0.4.5/lib/ -make -make install -``` - Advance configure options: - --prefix=/where/to/install - --with-libsodium-headers=/path/to/libsodium/include/ @@ -201,7 +183,7 @@ You should install: - [MinGW](http://sourceforge.net/projects/mingw/) When installing MinGW, make sure to select the MSYS option in the installer. -MinGW will install an "MinGW shell" (you should get a shortcut for it), make sure to perform all operations (i.e. generating/running configure script, compiling, etc.) from the MinGW shell. +MinGW will install an "MinGW shell" (you should get a shortcut for it), make sure to perform all opeartions (i.e. generating/running configure script, compiling, etc.) from the MinGW shell. First download the source tarball from http://download.libsodium.org/libsodium/releases/ and build it. Assuming that you got the libsodium-0.4.2.tar.gz release: -- cgit v1.2.3 From 934ddff24bac0c99e25942be76f67584845e847f Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 19:13:07 -0800 Subject: Fixed reverting install.md --- INSTALL.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4f98831d..5d8cd2c2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,7 +28,7 @@ On Fedora: ```bash yum groupinstall "Development Tools" yum install libtool autoconf automake libconfig-devel ncurses-devel check check-devel -``` +``` Note that `libconfig-dev` should be >= 1.4. @@ -58,7 +58,7 @@ make check sudo make install cd .. ``` -If your default prefix is /usr/local and you happen to get an error that says "error while loading shared libraries: libtoxcore.so.0: cannot open shared object file: No such file or directory", then you can try running ```sudo ldconfig```, this is an issue common on Linux. If that doesn't fix it, run: +If your default prefix is /usr/local and you happen to get an error that says "error while loading shared libraries: libtoxcore.so.0: cannot open shared object file: No such file or directory", then you can try running ```sudo ldconfig```. If that doesn't fix it, run: ``` echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf sudo ldconfig @@ -104,6 +104,13 @@ The following libraries are required along with libsodium and cmake for Mountain There are no binaries/executables going to /bin/ or /usr/bin/ now. Everything is compiled and ran from the inside your local branch. See [Usage](#usage) below. ####Homebrew: +To install from the formula: +```bash +brew tap Tox/tox +brew install --HEAD libtoxcore +``` + +To do it manually: ``` brew install libtool automake autoconf libconfig libsodium check ``` @@ -116,6 +123,21 @@ autoreconf -i make make install ``` + +If execution fails with errors like "dyld: Library not loaded: /opt/tox-im/lib/libtoxcore.0.dylib", you may need to specify libsodium path: + +Determine paths: +``` +brew list libsodium +``` + +Configure include and lib folder and build again: +```bash +./configure--with-libsodium-headers=/usr/local/Cellar/libsodium/0.4.5/include/ --with-libsodium-libs=/usr/local/Cellar/libsodium/0.4.5/lib/ +make +make install +``` + Advance configure options: - --prefix=/where/to/install - --with-libsodium-headers=/path/to/libsodium/include/ @@ -183,7 +205,7 @@ You should install: - [MinGW](http://sourceforge.net/projects/mingw/) When installing MinGW, make sure to select the MSYS option in the installer. -MinGW will install an "MinGW shell" (you should get a shortcut for it), make sure to perform all opeartions (i.e. generating/running configure script, compiling, etc.) from the MinGW shell. +MinGW will install an "MinGW shell" (you should get a shortcut for it), make sure to perform all operations (i.e. generating/running configure script, compiling, etc.) from the MinGW shell. First download the source tarball from http://download.libsodium.org/libsodium/releases/ and build it. Assuming that you got the libsodium-0.4.2.tar.gz release: -- cgit v1.2.3 From b14fd4fe719f8ef0e2478f38fd45bd425b77edd0 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 19:22:30 -0800 Subject: FBSD 10+, SunOS support --- INSTALL.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 5d8cd2c2..858dff61 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -30,6 +30,17 @@ yum groupinstall "Development Tools" yum install libtool autoconf automake libconfig-devel ncurses-devel check check-devel ``` +On SunOS: + +```pfexcec +pkg install autoconf automake gcc-47 +``` +On FreeBSD 10+: + +```tcsh +pkg install automake autoconf +``` + Note that `libconfig-dev` should be >= 1.4. You should get and install [libsodium](https://github.com/jedisct1/libsodium): -- cgit v1.2.3 From 460e52c42696a0de8cbe5b86f67f7cab0d8cf95a Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 25 Jan 2014 19:49:37 -0800 Subject: missing #endif --- toxcore/network.h | 1 + 1 file changed, 1 insertion(+) diff --git a/toxcore/network.h b/toxcore/network.h index ae2cb081..2ba2b005 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -91,6 +91,7 @@ typedef int sock_t; #else #define __MAKECONTEXT_V2_SOURCE 1 #endif +#endif #ifndef VANILLA_NACL /* We use libsodium by default. */ -- cgit v1.2.3 From 575135b327cf45edb9789f4d4fb2d62407acb314 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 26 Jan 2014 17:44:20 -0500 Subject: Attempted fix of some hole punching issues. --- toxcore/DHT.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 65fe6ae0..02175c2a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1794,21 +1794,6 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, ip_copy(&pinging.ip, &ip); pinging.port = htons(firstport); send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); - - if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { - top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS / 2; - uint16_t port1 = 1024; - uint16_t port2 = ~0; - - for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { - pinging.port = htons(port1 + i); - send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); - pinging.port = htons(port2 - i); - send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); - } - - dht->friends_list[friend_num].nat.punching_index2 = i; - } } else { for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { /* TODO: Improve port guessing algorithm. */ @@ -1822,6 +1807,20 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, dht->friends_list[friend_num].nat.punching_index = i; } + if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { + top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS; + uint16_t port = 1024; + IP_Port pinging; + ip_copy(&pinging.ip, &ip); + + for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { + pinging.port = htons(port + i); + send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); + } + + dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2); + } + ++dht->friends_list[friend_num].nat.tries; } -- cgit v1.2.3 From 5f26d8ae148ac785206449d3ac59becdd9f0b6ec Mon Sep 17 00:00:00 2001 From: Sean Date: Sun, 26 Jan 2014 18:02:16 -0800 Subject: Mention Jenkins, default to ssl --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e794b7fb..d526a4c5 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ 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) +**IRC**: #tox on freenode, alternatively, you can use the [webchat](https://webchat.freenode.net/?channels=#tox).
+**Website**: [https://tox.im](https://tox.im)
+**Developer Blog**: [http://dev.tox.im](http://dev.tox.im)
+**Jenkins**: [http://jenkins.tox.im](http://jenkins.tox.im) **Website translations**: [here](https://github.com/Tox/tox.im)
**Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) -- cgit v1.2.3 From 30200d04b702f51c898e969e6be2d10324b34ed5 Mon Sep 17 00:00:00 2001 From: Sean Date: Sun, 26 Jan 2014 18:07:58 -0800 Subject: Use ssl whenever possible --- INSTALL.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 858dff61..5bf20bf5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -75,7 +75,7 @@ echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf sudo ldconfig ``` -You also need recent [FFmpeg](http://git.videolan.org/?p=ffmpeg.git) libraries: +You also need recent [FFmpeg](https://git.videolan.org/?p=ffmpeg.git) libraries: ```bash git clone git://source.ffmpeg.org/ffmpeg.git cd ffmpeg @@ -165,9 +165,9 @@ Advance configure options: ####Non-homebrew: Grab the following packages: - * http://www.gnu.org/software/libtool/ - * http://www.gnu.org/software/autoconf/ - * http://www.gnu.org/software/automake/ + * https://gnu.org/software/libtool/ + * https://gnu.org/software/autoconf/ + * https://gnu.org/software/automake/ * https://github.com/jedisct1/libsodium * http://www.hyperrealm.com/libconfig/ * http://check.sourceforge.net/ @@ -218,7 +218,7 @@ You should install: When installing MinGW, make sure to select the MSYS option in the installer. MinGW will install an "MinGW shell" (you should get a shortcut for it), make sure to perform all operations (i.e. generating/running configure script, compiling, etc.) from the MinGW shell. -First download the source tarball from http://download.libsodium.org/libsodium/releases/ and build it. +First download the source tarball from https://download.libsodium.org/libsodium/releases/ and build it. Assuming that you got the libsodium-0.4.2.tar.gz release: ```cmd tar -zxvf libsodium-0.4.2.tar.gz -- cgit v1.2.3 From 17000b1b7cf1cdfe7d9739d96cbdfcb254a8655e Mon Sep 17 00:00:00 2001 From: Kelong Cong Date: Tue, 28 Jan 2014 14:57:26 +0000 Subject: added solution to the 'Unable to locate package libopus-dev' problem --- INSTALL.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 5bf20bf5..76a2623b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -22,6 +22,10 @@ On Ubuntu: ```bash sudo apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev checkinstall check git libswscale-dev libsdl-dev libopenal-dev libopus-dev libvpx-dev yasm ``` +If you get the "Unable to locate package libopus-dev" message, add the following ppa +```bash +sudo add-apt-repository ppa:ubuntu-sdk-team/ppa && sudo apt-get update && sudo apt-get dist-upgrade +``` On Fedora: -- cgit v1.2.3 From f1e0e16b67eb8d38c7829397a957eef636497d07 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 29 Jan 2014 20:59:50 -0500 Subject: A bit of tests added. --- auto_tests/onion_test.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 4dae2136..bdafa638 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -11,6 +11,7 @@ #include "../toxcore/onion.h" #include "../toxcore/onion_announce.h" +#include "../toxcore/onion_client.h" #include "../toxcore/util.h" #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) @@ -218,6 +219,7 @@ END_TEST typedef struct { Onion *onion; Onion_Announce *onion_a; + Onion_Client *onion_c; } Onions; Onions *new_onions(uint16_t port) @@ -229,14 +231,22 @@ Onions *new_onions(uint16_t port) DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); on->onion = new_onion(dht); on->onion_a = new_onion_announce(dht); + on->onion_c = new_onion_client(dht); - if (on->onion && on->onion_a) + if (on->onion && on->onion_a && on->onion_c) return on; return NULL; } -#define NUM_ONIONS 64 +void do_onions(Onions *on) +{ + networking_poll(on->onion->net); + do_DHT(on->onion->dht); + do_onion_client(on->onion_c); +} + +#define NUM_ONIONS 24 START_TEST(test_announce) { @@ -248,7 +258,42 @@ START_TEST(test_announce) ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); } + IP ip; + ip_init(&ip, 1); + ip.ip6.uint8[15] = 1; + + for (i = 1; i < NUM_ONIONS; ++i) { + IP_Port ip_port = {ip, onions[i - 1]->onion->net->port}; + DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key); + } + + uint32_t connected = 0; + + while (connected != NUM_ONIONS) { + connected = 0; + + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + connected += DHT_isconnected(onions[i]->onion->dht); + } + } + + /* + onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); + int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); + + uint32_t ok = 0; + + while (ok != 1) { + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + } + + IP_Port ip_port; + ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); + c_sleep(50); + }*/ } END_TEST @@ -265,7 +310,7 @@ Suite *onion_suite(void) Suite *s = suite_create("Onion"); DEFTESTCASE_SLOW(basic, 5); - DEFTESTCASE_SLOW(announce, 5); + DEFTESTCASE_SLOW(announce, 40); return s; } -- cgit v1.2.3 From 5da80263a511f7f9d03e553a1b97e55de86966d6 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jan 2014 13:59:10 -0500 Subject: Convert IPv4 in IPv6 to IPv6 address in recieve packet. --- toxcore/network.c | 6 +++++- toxcore/network.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/toxcore/network.c b/toxcore/network.c index 08fb71c7..1186a468 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -258,10 +258,14 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t ip_port->port = addr_in->sin_port; } else if (addr.ss_family == AF_INET6) { struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; - ip_port->ip.family = addr_in6->sin6_family; ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr; ip_port->port = addr_in6->sin6_port; + + if (IN6_IS_ADDR_V4MAPPED(&ip_port->ip.ip6.in6_addr)) { + ip_port->ip.family = AF_INET; + ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3]; + } } else return -1; diff --git a/toxcore/network.h b/toxcore/network.h index 2ba2b005..4c7f1a83 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -81,7 +81,7 @@ typedef int sock_t; #endif #if defined(__AIX__) -# define _XOPEN_SOURCE 1 +# define _XOPEN_SOURCE 1 #endif #if defined(__sun__) -- cgit v1.2.3 From 1505d489f43c649cd7263fdbeffae25d218fbde5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jan 2014 14:23:19 -0500 Subject: Fixed bug with client_ping_nodes() not pinging any nodes. --- toxcore/onion_client.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index a85a07a2..337bc296 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -183,13 +183,19 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); int index = -1; + uint32_t i; - if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) - || id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) { - index = 0; - } + for (i = 0; i < MAX_ONION_CLIENTS; ++i) { + if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT) + || id_closest(reference_id, list_nodes[i].client_id, public_key) == 2) { + index = i; - uint32_t i; + if (i != 0) + break; + } else { + break; + } + } for (i = 0; i < MAX_ONION_CLIENTS; ++i) { if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { @@ -255,8 +261,9 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n } } - if (j == MAX_ONION_CLIENTS) + if (j == MAX_ONION_CLIENTS) { client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); + } } } @@ -306,7 +313,10 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) return 1; - if (client_ping_nodes(onion_c, num, (Node_format *)plain + 1 + ONION_PING_ID_SIZE, num_nodes, source) == -1) + Node_format nodes[MAX_SENT_NODES]; + memcpy(nodes, plain + 1 + ONION_PING_ID_SIZE, num_nodes * sizeof(Node_format)); + + if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) return 1; return 0; -- cgit v1.2.3 From a13e30e8bb59f60b4971b0d46dd573ffe7b44104 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jan 2014 14:59:31 -0500 Subject: Test passes now, uncommented it. --- auto_tests/onion_test.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index bdafa638..73f69744 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -246,7 +246,7 @@ void do_onions(Onions *on) do_onion_client(on->onion_c); } -#define NUM_ONIONS 24 +#define NUM_ONIONS 50 START_TEST(test_announce) { @@ -278,22 +278,21 @@ START_TEST(test_announce) } } - /* - onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); - int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); + onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); + int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); - uint32_t ok = 0; + uint32_t ok = 0; - while (ok != 1) { - for (i = 0; i < NUM_ONIONS; ++i) { - do_onions(onions[i]); - } + while (ok != 1) { + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + } - IP_Port ip_port; - ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); + IP_Port ip_port; + ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); - c_sleep(50); - }*/ + c_sleep(50); + } } END_TEST @@ -310,7 +309,7 @@ Suite *onion_suite(void) Suite *s = suite_create("Onion"); DEFTESTCASE_SLOW(basic, 5); - DEFTESTCASE_SLOW(announce, 40); + DEFTESTCASE_SLOW(announce, 80); return s; } -- cgit v1.2.3 From 04580cf122f4b85bd9f49a7d2c7f4df7299ed9d7 Mon Sep 17 00:00:00 2001 From: tawm Date: Thu, 30 Jan 2014 15:56:45 -0500 Subject: Fixed PID forgetfulness. --- other/bootstrap_serverdaemon/tox_bootstrap_daemon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c index e82e49cd..f2c54bb1 100644 --- a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c @@ -398,11 +398,14 @@ int main(int argc, char *argv[]) pid_t pid = fork(); if (pid < 0) { + fclose(pidf); syslog(LOG_ERR, "Forking failed. Exiting.\n"); return 1; } if (pid > 0) { + fprintf(pidf, "%d\n", pid); + fclose(pidf); syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); return 0; } @@ -410,9 +413,6 @@ int main(int argc, char *argv[]) // Change the file mode mask umask(0); - fprintf(pidf, "%d\n", pid); - fclose(pidf); - // Create a new SID for the child process if (setsid() < 0) { syslog(LOG_ERR, "SID creation failure. Exiting.\n"); -- cgit v1.2.3 From a377c7fbf4344ba5359bc1fafafde415f50b4749 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 31 Jan 2014 18:05:49 -0500 Subject: Improved onion connection by a bit. --- toxcore/onion_client.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 337bc296..7cba27a9 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -766,24 +766,26 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) } } - if (count < MAX_ONION_CLIENTS / 2) { - Node_format nodes_list[MAX_SENT_NODES]; - uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, - rand() % 2 ? AF_INET : AF_INET6, 1, 0); - - for (i = 0; i < num_nodes; ++i) - client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); - } + if (count != MAX_ONION_CLIENTS) { + if (count < rand() % MAX_ONION_CLIENTS) { + Node_format nodes_list[MAX_SENT_NODES]; + uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, + rand() % 2 ? AF_INET : AF_INET6, 1, 0); + + for (i = 0; i < num_nodes; ++i) + client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + } - /* send packets to friend telling them our fake DHT id. */ - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) - onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); + /* send packets to friend telling them our fake DHT id. */ + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) + onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) - onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) + onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); + } } } /* Function to call when onion data packet with contents beginning with byte is received. */ @@ -820,13 +822,15 @@ static void do_announce(Onion_Client *onion_c) } } - if (count < MAX_ONION_CLIENTS / 2) { - Node_format nodes_list[MAX_SENT_NODES]; - uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, - rand() % 2 ? AF_INET : AF_INET6, 1, 0); + if (count != MAX_ONION_CLIENTS) { + if (count < rand() % MAX_ONION_CLIENTS) { + Node_format nodes_list[MAX_SENT_NODES]; + uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, + rand() % 2 ? AF_INET : AF_INET6, 1, 0); - for (i = 0; i < num_nodes; ++i) - client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + for (i = 0; i < num_nodes; ++i) + client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + } } } -- cgit v1.2.3 From d5c005f02462b996c067d7ed4f1ef71bbd4e5dd2 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 31 Jan 2014 20:25:46 -0500 Subject: Fixed error in last commit. The tests actually work. --- toxcore/onion_client.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 7cba27a9..93697c28 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -775,17 +775,17 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) for (i = 0; i < num_nodes; ++i) client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); } + } + /* send packets to friend telling them our fake DHT id. */ + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) + onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); - /* send packets to friend telling them our fake DHT id. */ - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) - onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) + onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) - onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); - } } } /* Function to call when onion data packet with contents beginning with byte is received. */ -- cgit v1.2.3