Added fixes to rtp and updated phone

This commit is contained in:
mannol 2014-02-01 12:44:08 +01:00
commit 984c564cba
17 changed files with 240 additions and 143 deletions

View File

@ -22,6 +22,10 @@ On Ubuntu:
```bash ```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 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: On Fedora:
@ -75,7 +79,7 @@ echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf
sudo ldconfig 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 ```bash
git clone git://source.ffmpeg.org/ffmpeg.git git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg cd ffmpeg
@ -165,9 +169,9 @@ Advance configure options:
####Non-homebrew: ####Non-homebrew:
Grab the following packages: Grab the following packages:
* http://www.gnu.org/software/libtool/ * https://gnu.org/software/libtool/
* http://www.gnu.org/software/autoconf/ * https://gnu.org/software/autoconf/
* http://www.gnu.org/software/automake/ * https://gnu.org/software/automake/
* https://github.com/jedisct1/libsodium * https://github.com/jedisct1/libsodium
* http://www.hyperrealm.com/libconfig/ * http://www.hyperrealm.com/libconfig/
* http://check.sourceforge.net/ * http://check.sourceforge.net/
@ -218,7 +222,7 @@ You should install:
When installing MinGW, make sure to select the MSYS option in the installer. 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 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: Assuming that you got the libsodium-0.4.2.tar.gz release:
```cmd ```cmd
tar -zxvf libsodium-0.4.2.tar.gz tar -zxvf libsodium-0.4.2.tar.gz
@ -256,4 +260,4 @@ Advance configure options:
<a name="Clients" /> <a name="Clients" />
####Clients: ####Clients:
While [Toxic](https://github.com/tox/toxic) is no longer in core, a list of Tox clients are located in our [wiki](http://wiki.tox.im/client) While [Toxic](https://github.com/tox/toxic) is no longer in core, a list of Tox clients are located in our [wiki](http://wiki.tox.im/client)

View File

@ -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).<br /> **IRC**: #tox on freenode, alternatively, you can use the [webchat](https://webchat.freenode.net/?channels=#tox).<br />
**Website**: [http://tox.im](http://tox.im) **Website**: [https://tox.im](https://tox.im)<br>
**Developer Blog**: [http://dev.tox.im](http://dev.tox.im) **Developer Blog**: [http://dev.tox.im](http://dev.tox.im)<br>
**Jenkins**: [http://jenkins.tox.im](http://jenkins.tox.im)
**Website translations**: [here](https://github.com/Tox/tox.im)<br/> **Website translations**: [here](https://github.com/Tox/tox.im)<br/>
**Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) **Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI)

View File

@ -11,6 +11,7 @@
#include "../toxcore/onion.h" #include "../toxcore/onion.h"
#include "../toxcore/onion_announce.h" #include "../toxcore/onion_announce.h"
#include "../toxcore/onion_client.h"
#include "../toxcore/util.h" #include "../toxcore/util.h"
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
@ -218,6 +219,7 @@ END_TEST
typedef struct { typedef struct {
Onion *onion; Onion *onion;
Onion_Announce *onion_a; Onion_Announce *onion_a;
Onion_Client *onion_c;
} Onions; } Onions;
Onions *new_onions(uint16_t port) 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))); DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port)));
on->onion = new_onion(dht); on->onion = new_onion(dht);
on->onion_a = new_onion_announce(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 on;
return NULL; 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 50
START_TEST(test_announce) START_TEST(test_announce)
{ {
@ -248,7 +258,41 @@ START_TEST(test_announce)
ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); 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 END_TEST
@ -265,7 +309,7 @@ Suite *onion_suite(void)
Suite *s = suite_create("Onion"); Suite *s = suite_create("Onion");
DEFTESTCASE_SLOW(basic, 5); DEFTESTCASE_SLOW(basic, 5);
DEFTESTCASE_SLOW(announce, 5); DEFTESTCASE_SLOW(announce, 80);
return s; return s;
} }

View File

@ -333,6 +333,7 @@ AC_TYPE_UINT16_T
AC_TYPE_UINT32_T AC_TYPE_UINT32_T
AC_TYPE_UINT64_T AC_TYPE_UINT64_T
AC_TYPE_UINT8_T AC_TYPE_UINT8_T
AC_C_BIGENDIAN
# Checks for library functions. # Checks for library functions.
AC_FUNC_FORK AC_FUNC_FORK

View File

@ -1,17 +1,17 @@
if BUILD_DHT_BOOTSTRAP_DAEMON if BUILD_DHT_BOOTSTRAP_DAEMON
noinst_PROGRAMS += tox_dht_bootstrap_server_daemon noinst_PROGRAMS += tox_bootstrap_daemon
tox_dht_bootstrap_server_daemon_SOURCES = \ tox_bootstrap_daemon_SOURCES = \
../other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c ../other/bootstrap_serverdaemon/tox_bootstrap_daemon.c
tox_dht_bootstrap_server_daemon_CFLAGS = \ tox_bootstrap_daemon_CFLAGS = \
-I$(top_srcdir)/other/bootstrap_serverdaemon \ -I$(top_srcdir)/other/bootstrap_serverdaemon \
$(LIBSODIUM_CFLAGS) \ $(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS) \ $(NACL_CFLAGS) \
$(LIBCONFIG_CFLAGS) $(LIBCONFIG_CFLAGS)
tox_dht_bootstrap_server_daemon_LDADD = \ tox_bootstrap_daemon_LDADD = \
$(LIBSODIUM_LDFLAGS) \ $(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \ $(NACL_LDFLAGS) \
libtoxcore.la \ libtoxcore.la \
@ -23,5 +23,5 @@ endif
EXTRA_DIST += \ EXTRA_DIST += \
$(top_srcdir)/other/bootstrap_serverdaemon/conf \ $(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

View File

@ -2,44 +2,44 @@
The following commands are to be executed as root: 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 - `CFG` to where your config file (`conf`) will be; read rights required
- `DAEMON` to point to the executable - `DAEMON` to point to the executable
- `PIDFILE` to point to a pid file daemon would have rights to create - `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: 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)* *(note that we removed `.sh` ending)*
4. Give the right permissions to this file: 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: 5. Execute:
``` ```
update-rc.d tox_dht_bootstrap_server_daemon defaults update-rc.d tox_bootstrap_daemon defaults
``` ```
6. Start the service: 6. Start the service:
``` ```
service tox_dht_bootstrap_server_daemon start service tox_bootstrap_daemon start
``` ```
7. Verify that the service is running: 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 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** **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 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 4. Make sure you have write permission to keys and pid files

View File

@ -1,33 +1,34 @@
// ProjectTox bootstrap server configuration file // ProjectTox dht bootstrap server daemon configuration file.
// listening port // Listening port.
port = 33445 port = 33445
// The key file is like a password, so keep it where no one can read it // 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 // The daemon should have permission to read/write to it.
// Remember to replace the provided example with // Remember to replace the provided example with your own path.
// your own path keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys"
keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys"
// The PID file written to by daemon, // The PID file written to by daemon.
// make sure that the user who runs the server // Make sure that the user who runs the daemon has permissions to write to the
// does have permissions to write to it // PID file.
// Remember to replace the provided example with // Remember to replace the provided example with your own path.
// your own path pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid"
pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid"
// Enable IPv6.
enable_ipv6 = false enable_ipv6 = false
// Automatically bootstrap with nodes on local network // Automatically bootstrap with nodes on local area network.
enable_lan_discovery = true enable_lan_discovery = true
// Any number of nodes the daemon will bootstrap itself from // Any number of servers the daemon will bootstrap itself from.
// Remember to replace the provided example with // Remember to replace the provided example with your own server list.
// 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 = ( bootstrap_servers = (
{ // Server 1 { // Server 1
// any ipv4 or ipv6, depending if `enable_ipv6` is set or not // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also
// also any US-ASCII domain name // any US-ASCII domain name.
address = "198.46.136.167" address = "198.46.136.167"
port = 33445 port = 33445
public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854"

View File

@ -1,6 +1,6 @@
/* tox_dht_bootstrap_server_daemon /* tox_bootstrap_daemon.c
* *
* A simple DHT bootstrap server for tox - daemon edition. * Tox DHT bootstrap server daemon.
* *
* Copyright (C) 2014 Tox project All Rights Reserved. * Copyright (C) 2014 Tox project All Rights Reserved.
* *
@ -42,13 +42,13 @@
#include "../../testing/misc_tools.c" #include "../../testing/misc_tools.c"
#define DAEMON_NAME "tox_dht_bootstrap_server_daemon" #define DAEMON_NAME "tox_bootstrap_daemon"
#define SLEEP_TIME_MILLISECONDS 30 #define SLEEP_TIME_MILLISECONDS 30
#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS)
#define DEFAULT_PID_FILE_PATH ".tox_dht_bootstrap_server_daemon.pid" #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid"
#define DEFAULT_KEYS_FILE_PATH ".tox_dht_bootstrap_server_daemon.keys" #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys"
#define DEFAULT_PORT 33445 #define DEFAULT_PORT 33445
#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
@ -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 // Bootstraps servers listed in the config file
// //
// returns 1 on success // returns 1 on success, some or no bootstrap servers were added
// 0 on failure, either no or only some servers were bootstrapped // 0 on failure, a error accured while parsing config file
int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) 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); config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS);
if (server_list == NULL) { 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); 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; int bs_port;
@ -232,21 +238,31 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
return 0; 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 || 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 || syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY);
config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) {
goto next; 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) { 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; goto next;
} }
// not (1 <= port <= 65535) // not (1 <= port <= 65535)
if (bs_port < 1 || bs_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; goto next;
} }
@ -254,11 +270,11 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
hex_string_to_bin((char *)bs_public_key)); hex_string_to_bin((char *)bs_public_key));
if (!address_resolved) { 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; 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: next:
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it // config_setting_lookup_string() allocates string inside and doesn't allow us to free it
@ -273,36 +289,6 @@ next:
return 1; 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 // Prints public key
void print_public_key(uint8_t *public_key) void print_public_key(uint8_t *public_key)
@ -330,7 +316,7 @@ int main(int argc, char *argv[])
openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON);
if (argc < 2) { 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; return 1;
} }
@ -395,13 +381,6 @@ int main(int argc, char *argv[])
return 1; 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); print_public_key(dht->c->self_public_key);
// Write the PID file // Write the PID file
@ -419,11 +398,14 @@ int main(int argc, char *argv[])
pid_t pid = fork(); pid_t pid = fork();
if (pid < 0) { if (pid < 0) {
fclose(pidf);
syslog(LOG_ERR, "Forking failed. Exiting.\n"); syslog(LOG_ERR, "Forking failed. Exiting.\n");
return 1; return 1;
} }
if (pid > 0) { if (pid > 0) {
fprintf(pidf, "%d\n", pid);
fclose(pidf);
syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid);
return 0; return 0;
} }
@ -431,9 +413,6 @@ int main(int argc, char *argv[])
// Change the file mode mask // Change the file mode mask
umask(0); umask(0);
fprintf(pidf, "%d\n", pid);
fclose(pidf);
// Create a new SID for the child process // Create a new SID for the child process
if (setsid() < 0) { if (setsid() < 0) {
syslog(LOG_ERR, "SID creation failure. Exiting.\n"); syslog(LOG_ERR, "SID creation failure. Exiting.\n");
@ -454,6 +433,8 @@ int main(int argc, char *argv[])
uint64_t last_LANdiscovery = 0; uint64_t last_LANdiscovery = 0;
uint16_t htons_port = htons(port); uint16_t htons_port = htons(port);
int waiting_for_dht_connection = 1;
while (1) { while (1) {
do_DHT(dht); do_DHT(dht);
@ -464,6 +445,11 @@ int main(int argc, char *argv[])
networking_poll(dht->net); 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; sleep;
} }

View File

@ -1,18 +1,19 @@
#! /bin/sh #! /bin/sh
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: tox_dht_bootstrap_server_daemon # Provides: tox_bootstrap_daemon
# Required-Start: $remote_fs $syslog # Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog # Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: Starts the Tox bootstrapping server # Short-Description: Starts the Tox DHT bootstrapping server daemon
# Description: Starts the Tox bootstrapping server # Description: Starts the Tox DHT bootstrapping server daemon
### END INIT INFO ### END INIT INFO
# PATH should only include /usr/* if it runs after the mountnfs.sh script # PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="ProjectTox bootstrap server daemon" DESC="Tox DHT bootstrap server daemon"
NAME=tox_dht_bootstrap_server_daemon NAME=tox_bootstrap_daemon
# You may want to change USER if you are using it anywhere else
USER=tom USER=tom
CFG=/home/$USER/.$NAME/conf CFG=/home/$USER/.$NAME/conf
DAEMON=/home/$USER/$NAME DAEMON=/home/$USER/$NAME

View File

@ -46,11 +46,13 @@
/* Ping interval in seconds for each random sending of a get nodes request. */ /* Ping interval in seconds for each random sending of a get nodes request. */
#define GET_NODE_INTERVAL 5 #define GET_NODE_INTERVAL 5
#define MAX_PUNCHING_PORTS 32 #define MAX_PUNCHING_PORTS 48
/* Interval in seconds between punching attempts*/ /* Interval in seconds between punching attempts*/
#define PUNCH_INTERVAL 3 #define PUNCH_INTERVAL 3
#define MAX_NORMAL_PUNCHING_TRIES 5
#define NAT_PING_REQUEST 0 #define NAT_PING_REQUEST 0
#define NAT_PING_RESPONSE 1 #define NAT_PING_RESPONSE 1
@ -1793,7 +1795,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
pinging.port = htons(firstport); pinging.port = htons(firstport);
send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id);
} else { } 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. */ /* TODO: Improve port guessing algorithm. */
uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1);
IP_Port pinging; IP_Port pinging;
@ -1804,6 +1806,22 @@ 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.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;
} }
static void do_NAT(DHT *dht) static void do_NAT(DHT *dht)

View File

@ -109,6 +109,9 @@ typedef struct {
/* 1 if currently hole punching, otherwise 0 */ /* 1 if currently hole punching, otherwise 0 */
uint8_t hole_punching; uint8_t hole_punching;
uint32_t punching_index; uint32_t punching_index;
uint32_t tries;
uint32_t punching_index2;
uint64_t punching_timestamp; uint64_t punching_timestamp;
uint64_t recvNATping_timestamp; uint64_t recvNATping_timestamp;
uint64_t NATping_id; uint64_t NATping_id;

View File

@ -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; ip_port->port = addr_in->sin_port;
} else if (addr.ss_family == AF_INET6) { } else if (addr.ss_family == AF_INET6) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr;
ip_port->ip.family = addr_in6->sin6_family; ip_port->ip.family = addr_in6->sin6_family;
ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr; ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr;
ip_port->port = addr_in6->sin6_port; 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 } else
return -1; return -1;

View File

@ -24,6 +24,11 @@
#ifndef NETWORK_H #ifndef NETWORK_H
#define NETWORK_H #define NETWORK_H
#ifdef PLAN9
#include <u.h> //Plan 9 requires this is imported first
#include <libc.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
@ -75,6 +80,19 @@ typedef int sock_t;
#endif #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
#endif
#ifndef VANILLA_NACL #ifndef VANILLA_NACL
/* We use libsodium by default. */ /* We use libsodium by default. */
#include <sodium.h> #include <sodium.h>

View File

@ -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); memcpy(step1 + sizeof(IP_Port), data, length);
uint8_t nonce[crypto_box_NONCEBYTES]; uint8_t nonce[crypto_box_NONCEBYTES];
new_nonce(nonce); random_nonce(nonce);
uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; uint8_t random_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; uint8_t random_secret_key[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(random_public_key, random_secret_key); crypto_box_keypair(random_public_key, random_secret_key);

View File

@ -61,7 +61,7 @@ int send_announce_request(DHT *dht, Node_format *nodes, uint8_t *public_key, uin
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH); ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
uint8_t packet[ANNOUNCE_REQUEST_SIZE]; uint8_t packet[ANNOUNCE_REQUEST_SIZE];
packet[0] = NET_PACKET_ANNOUNCE_REQUEST; 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), int len = encrypt_data(nodes[3].client_id, secret_key, packet + 1, plain, sizeof(plain),
packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES); 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); to_net_family(&nodes_list[i].ip_port.ip);
uint8_t nonce[crypto_box_NONCEBYTES]; uint8_t nonce[crypto_box_NONCEBYTES];
new_nonce(nonce); random_nonce(nonce);
uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)]; uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)];

View File

@ -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)]; uint8_t plain[sizeof(uint32_t) + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)];
uint64_t time = unix_time(); uint64_t time = unix_time();
new_nonce(sendback); random_nonce(sendback);
memcpy(plain, &num, sizeof(uint32_t)); memcpy(plain, &num, sizeof(uint32_t));
memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t)); memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t));
memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES); memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES);
@ -183,14 +183,20 @@ 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); qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry);
int index = -1; int index = -1;
if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT)
|| id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) {
index = 0;
}
uint32_t i; uint32_t i;
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;
if (i != 0)
break;
} else {
break;
}
}
for (i = 0; i < MAX_ONION_CLIENTS; ++i) { for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) {
index = i; index = i;
@ -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); 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) if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1)
return 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 1;
return 0; return 0;
@ -420,7 +430,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32
return -1; return -1;
uint8_t nonce[crypto_box_NONCEBYTES]; uint8_t nonce[crypto_box_NONCEBYTES];
new_nonce(nonce); random_nonce(nonce);
uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length];
memcpy(packet, onion_c->dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); memcpy(packet, onion_c->dht->c->self_public_key, crypto_box_PUBLICKEYBYTES);
@ -703,9 +713,11 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on
return -1; return -1;
onion_c->friends_list[friend_num].is_online = is_online; 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) if (!is_online)
onion_c->friends_list[friend_num].last_noreplay = 0; */ onion_c->friends_list[friend_num].last_noreplay = 0;
return 0; return 0;
} }
@ -754,16 +766,17 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
} }
} }
if (count < MAX_ONION_CLIENTS / 2) { if (count != MAX_ONION_CLIENTS) {
Node_format nodes_list[MAX_SENT_NODES]; if (count < rand() % MAX_ONION_CLIENTS) {
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, Node_format nodes_list[MAX_SENT_NODES];
rand() % 2 ? AF_INET : AF_INET6, 1, 0); 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) 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); 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. */ /* 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 (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL))
if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) if (send_fakeid_announce(onion_c, friendnum, 0) >= 1)
@ -772,6 +785,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL))
if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) if (send_fakeid_announce(onion_c, friendnum, 1) >= 1)
onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); 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. */ /* Function to call when onion data packet with contents beginning with byte is received. */
@ -808,13 +822,15 @@ static void do_announce(Onion_Client *onion_c)
} }
} }
if (count < MAX_ONION_CLIENTS / 2) { if (count != MAX_ONION_CLIENTS) {
Node_format nodes_list[MAX_SENT_NODES]; if (count < rand() % MAX_ONION_CLIENTS) {
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, Node_format nodes_list[MAX_SENT_NODES];
rand() % 2 ? AF_INET : AF_INET6, 1, 0); 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) 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); client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0);
}
} }
} }

View File

@ -35,7 +35,7 @@
#include "network.h" #include "network.h"
#include "util.h" #include "util.h"
#define PING_NUM_MAX 384 #define PING_NUM_MAX 512
/* Ping newly announced nodes to ping per TIME_TOPING seconds*/ /* Ping newly announced nodes to ping per TIME_TOPING seconds*/
#define TIME_TOPING 5 #define TIME_TOPING 5