diff options
-rw-r--r-- | INSTALL.md | 16 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 50 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/Makefile.inc | 12 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/README.md | 22 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/conf | 39 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/tox_bootstrap_daemon.c (renamed from other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c) | 102 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh (renamed from other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh) | 11 | ||||
-rw-r--r-- | toxcore/DHT.c | 22 | ||||
-rw-r--r-- | toxcore/DHT.h | 3 | ||||
-rw-r--r-- | toxcore/network.c | 6 | ||||
-rw-r--r-- | toxcore/network.h | 18 | ||||
-rw-r--r-- | toxcore/onion.c | 2 | ||||
-rw-r--r-- | toxcore/onion_announce.c | 4 | ||||
-rw-r--r-- | toxcore/onion_client.c | 64 | ||||
-rw-r--r-- | toxcore/ping.c | 2 |
17 files changed, 239 insertions, 142 deletions
@@ -22,6 +22,10 @@ On Ubuntu: | |||
22 | ```bash | 22 | ```bash |
23 | 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 | 23 | 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 | ``` | 24 | ``` |
25 | If you get the "Unable to locate package libopus-dev" message, add the following ppa | ||
26 | ```bash | ||
27 | sudo add-apt-repository ppa:ubuntu-sdk-team/ppa && sudo apt-get update && sudo apt-get dist-upgrade | ||
28 | ``` | ||
25 | 29 | ||
26 | On Fedora: | 30 | On Fedora: |
27 | 31 | ||
@@ -75,7 +79,7 @@ echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf | |||
75 | sudo ldconfig | 79 | sudo ldconfig |
76 | ``` | 80 | ``` |
77 | 81 | ||
78 | You also need recent [FFmpeg](http://git.videolan.org/?p=ffmpeg.git) libraries: | 82 | You also need recent [FFmpeg](https://git.videolan.org/?p=ffmpeg.git) libraries: |
79 | ```bash | 83 | ```bash |
80 | git clone git://source.ffmpeg.org/ffmpeg.git | 84 | git clone git://source.ffmpeg.org/ffmpeg.git |
81 | cd ffmpeg | 85 | cd ffmpeg |
@@ -165,9 +169,9 @@ Advance configure options: | |||
165 | ####Non-homebrew: | 169 | ####Non-homebrew: |
166 | 170 | ||
167 | Grab the following packages: | 171 | Grab the following packages: |
168 | * http://www.gnu.org/software/libtool/ | 172 | * https://gnu.org/software/libtool/ |
169 | * http://www.gnu.org/software/autoconf/ | 173 | * https://gnu.org/software/autoconf/ |
170 | * http://www.gnu.org/software/automake/ | 174 | * https://gnu.org/software/automake/ |
171 | * https://github.com/jedisct1/libsodium | 175 | * https://github.com/jedisct1/libsodium |
172 | * http://www.hyperrealm.com/libconfig/ | 176 | * http://www.hyperrealm.com/libconfig/ |
173 | * http://check.sourceforge.net/ | 177 | * http://check.sourceforge.net/ |
@@ -218,7 +222,7 @@ You should install: | |||
218 | When installing MinGW, make sure to select the MSYS option in the installer. | 222 | When installing MinGW, make sure to select the MSYS option in the installer. |
219 | 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. | 223 | 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. |
220 | 224 | ||
221 | First download the source tarball from http://download.libsodium.org/libsodium/releases/ and build it. | 225 | First download the source tarball from https://download.libsodium.org/libsodium/releases/ and build it. |
222 | Assuming that you got the libsodium-0.4.2.tar.gz release: | 226 | Assuming that you got the libsodium-0.4.2.tar.gz release: |
223 | ```cmd | 227 | ```cmd |
224 | tar -zxvf libsodium-0.4.2.tar.gz | 228 | tar -zxvf libsodium-0.4.2.tar.gz |
@@ -256,4 +260,4 @@ Advance configure options: | |||
256 | 260 | ||
257 | <a name="Clients" /> | 261 | <a name="Clients" /> |
258 | ####Clients: | 262 | ####Clients: |
259 | 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) \ No newline at end of file | 263 | 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) |
@@ -5,9 +5,10 @@ With the rise of governmental monitoring programs, Tox aims to be an easy to use | |||
5 | 5 | ||
6 | 6 | ||
7 | 7 | ||
8 | **IRC**: #tox on freenode, alternatively, you can use the [webchat](http://webchat.freenode.net/?channels=#tox).<br /> | 8 | **IRC**: #tox on freenode, alternatively, you can use the [webchat](https://webchat.freenode.net/?channels=#tox).<br /> |
9 | **Website**: [http://tox.im](http://tox.im) | 9 | **Website**: [https://tox.im](https://tox.im)<br> |
10 | **Developer Blog**: [http://dev.tox.im](http://dev.tox.im) | 10 | **Developer Blog**: [http://dev.tox.im](http://dev.tox.im)<br> |
11 | **Jenkins**: [http://jenkins.tox.im](http://jenkins.tox.im) | ||
11 | 12 | ||
12 | **Website translations**: [here](https://github.com/Tox/tox.im)<br/> | 13 | **Website translations**: [here](https://github.com/Tox/tox.im)<br/> |
13 | **Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) | 14 | **Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI) |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 4dae2136..73f69744 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include "../toxcore/onion.h" | 12 | #include "../toxcore/onion.h" |
13 | #include "../toxcore/onion_announce.h" | 13 | #include "../toxcore/onion_announce.h" |
14 | #include "../toxcore/onion_client.h" | ||
14 | #include "../toxcore/util.h" | 15 | #include "../toxcore/util.h" |
15 | 16 | ||
16 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 17 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) |
@@ -218,6 +219,7 @@ END_TEST | |||
218 | typedef struct { | 219 | typedef struct { |
219 | Onion *onion; | 220 | Onion *onion; |
220 | Onion_Announce *onion_a; | 221 | Onion_Announce *onion_a; |
222 | Onion_Client *onion_c; | ||
221 | } Onions; | 223 | } Onions; |
222 | 224 | ||
223 | Onions *new_onions(uint16_t port) | 225 | Onions *new_onions(uint16_t port) |
@@ -229,14 +231,22 @@ Onions *new_onions(uint16_t port) | |||
229 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); | 231 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); |
230 | on->onion = new_onion(dht); | 232 | on->onion = new_onion(dht); |
231 | on->onion_a = new_onion_announce(dht); | 233 | on->onion_a = new_onion_announce(dht); |
234 | on->onion_c = new_onion_client(dht); | ||
232 | 235 | ||
233 | if (on->onion && on->onion_a) | 236 | if (on->onion && on->onion_a && on->onion_c) |
234 | return on; | 237 | return on; |
235 | 238 | ||
236 | return NULL; | 239 | return NULL; |
237 | } | 240 | } |
238 | 241 | ||
239 | #define NUM_ONIONS 64 | 242 | void do_onions(Onions *on) |
243 | { | ||
244 | networking_poll(on->onion->net); | ||
245 | do_DHT(on->onion->dht); | ||
246 | do_onion_client(on->onion_c); | ||
247 | } | ||
248 | |||
249 | #define NUM_ONIONS 50 | ||
240 | 250 | ||
241 | START_TEST(test_announce) | 251 | START_TEST(test_announce) |
242 | { | 252 | { |
@@ -248,7 +258,41 @@ START_TEST(test_announce) | |||
248 | ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); | 258 | ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); |
249 | } | 259 | } |
250 | 260 | ||
261 | IP ip; | ||
262 | ip_init(&ip, 1); | ||
263 | ip.ip6.uint8[15] = 1; | ||
264 | |||
265 | for (i = 1; i < NUM_ONIONS; ++i) { | ||
266 | IP_Port ip_port = {ip, onions[i - 1]->onion->net->port}; | ||
267 | DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key); | ||
268 | } | ||
269 | |||
270 | uint32_t connected = 0; | ||
251 | 271 | ||
272 | while (connected != NUM_ONIONS) { | ||
273 | connected = 0; | ||
274 | |||
275 | for (i = 0; i < NUM_ONIONS; ++i) { | ||
276 | do_onions(onions[i]); | ||
277 | connected += DHT_isconnected(onions[i]->onion->dht); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); | ||
282 | int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); | ||
283 | |||
284 | uint32_t ok = 0; | ||
285 | |||
286 | while (ok != 1) { | ||
287 | for (i = 0; i < NUM_ONIONS; ++i) { | ||
288 | do_onions(onions[i]); | ||
289 | } | ||
290 | |||
291 | IP_Port ip_port; | ||
292 | ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); | ||
293 | |||
294 | c_sleep(50); | ||
295 | } | ||
252 | } | 296 | } |
253 | END_TEST | 297 | END_TEST |
254 | 298 | ||
@@ -265,7 +309,7 @@ Suite *onion_suite(void) | |||
265 | Suite *s = suite_create("Onion"); | 309 | Suite *s = suite_create("Onion"); |
266 | 310 | ||
267 | DEFTESTCASE_SLOW(basic, 5); | 311 | DEFTESTCASE_SLOW(basic, 5); |
268 | DEFTESTCASE_SLOW(announce, 5); | 312 | DEFTESTCASE_SLOW(announce, 80); |
269 | return s; | 313 | return s; |
270 | } | 314 | } |
271 | 315 | ||
diff --git a/configure.ac b/configure.ac index 62bb91bd..afb327cb 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -333,6 +333,7 @@ AC_TYPE_UINT16_T | |||
333 | AC_TYPE_UINT32_T | 333 | AC_TYPE_UINT32_T |
334 | AC_TYPE_UINT64_T | 334 | AC_TYPE_UINT64_T |
335 | AC_TYPE_UINT8_T | 335 | AC_TYPE_UINT8_T |
336 | AC_C_BIGENDIAN | ||
336 | 337 | ||
337 | # Checks for library functions. | 338 | # Checks for library functions. |
338 | AC_FUNC_FORK | 339 | AC_FUNC_FORK |
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 @@ | |||
1 | if BUILD_DHT_BOOTSTRAP_DAEMON | 1 | if BUILD_DHT_BOOTSTRAP_DAEMON |
2 | 2 | ||
3 | noinst_PROGRAMS += tox_dht_bootstrap_server_daemon | 3 | noinst_PROGRAMS += tox_bootstrap_daemon |
4 | 4 | ||
5 | tox_dht_bootstrap_server_daemon_SOURCES = \ | 5 | tox_bootstrap_daemon_SOURCES = \ |
6 | ../other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c | 6 | ../other/bootstrap_serverdaemon/tox_bootstrap_daemon.c |
7 | 7 | ||
8 | tox_dht_bootstrap_server_daemon_CFLAGS = \ | 8 | tox_bootstrap_daemon_CFLAGS = \ |
9 | -I$(top_srcdir)/other/bootstrap_serverdaemon \ | 9 | -I$(top_srcdir)/other/bootstrap_serverdaemon \ |
10 | $(LIBSODIUM_CFLAGS) \ | 10 | $(LIBSODIUM_CFLAGS) \ |
11 | $(NACL_CFLAGS) \ | 11 | $(NACL_CFLAGS) \ |
12 | $(LIBCONFIG_CFLAGS) | 12 | $(LIBCONFIG_CFLAGS) |
13 | 13 | ||
14 | tox_dht_bootstrap_server_daemon_LDADD = \ | 14 | tox_bootstrap_daemon_LDADD = \ |
15 | $(LIBSODIUM_LDFLAGS) \ | 15 | $(LIBSODIUM_LDFLAGS) \ |
16 | $(NACL_LDFLAGS) \ | 16 | $(NACL_LDFLAGS) \ |
17 | libtoxcore.la \ | 17 | libtoxcore.la \ |
@@ -23,5 +23,5 @@ endif | |||
23 | 23 | ||
24 | EXTRA_DIST += \ | 24 | EXTRA_DIST += \ |
25 | $(top_srcdir)/other/bootstrap_serverdaemon/conf \ | 25 | $(top_srcdir)/other/bootstrap_serverdaemon/conf \ |
26 | $(top_srcdir)/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh | 26 | $(top_srcdir)/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh |
27 | \ No newline at end of file | 27 | \ 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 @@ | |||
2 | 2 | ||
3 | The following commands are to be executed as root: | 3 | The following commands are to be executed as root: |
4 | 4 | ||
5 | 1. In `tox_dht_bootstrap_server_daemon.sh` file change: | 5 | 1. In `tox_bootstrap_daemon.sh` file change: |
6 | - `CFG` to where your config file (`conf`) will be; read rights required | 6 | - `CFG` to where your config file (`conf`) will be; read rights required |
7 | - `DAEMON` to point to the executable | 7 | - `DAEMON` to point to the executable |
8 | - `PIDFILE` to point to a pid file daemon would have rights to create | 8 | - `PIDFILE` to point to a pid file daemon would have rights to create |
9 | 9 | ||
10 | 2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_dht_bootstrap_server_daemon.sh` | 10 | 2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_bootstrap_daemon.sh` |
11 | 11 | ||
12 | 3. Execute: | 12 | 3. Execute: |
13 | ``` | 13 | ``` |
14 | mv tox_dht_bootstrap_server_daemon.sh /etc/init.d/tox_dht_bootstrap_server_daemon | 14 | mv tox_bootstrap_daemon.sh /etc/init.d/tox_bootstrap_daemon |
15 | ``` | 15 | ``` |
16 | *(note that we removed `.sh` ending)* | 16 | *(note that we removed `.sh` ending)* |
17 | 17 | ||
18 | 4. Give the right permissions to this file: | 18 | 4. Give the right permissions to this file: |
19 | ``` | 19 | ``` |
20 | chmod 755 /etc/init.d/tox_dht_bootstrap_server_daemon | 20 | chmod 755 /etc/init.d/tox_bootstrap_daemon |
21 | ``` | 21 | ``` |
22 | 22 | ||
23 | 5. Execute: | 23 | 5. Execute: |
24 | ``` | 24 | ``` |
25 | update-rc.d tox_dht_bootstrap_server_daemon defaults | 25 | update-rc.d tox_bootstrap_daemon defaults |
26 | ``` | 26 | ``` |
27 | 27 | ||
28 | 6. Start the service: | 28 | 6. Start the service: |
29 | ``` | 29 | ``` |
30 | service tox_dht_bootstrap_server_daemon start | 30 | service tox_bootstrap_daemon start |
31 | ``` | 31 | ``` |
32 | 32 | ||
33 | 7. Verify that the service is running: | 33 | 7. Verify that the service is running: |
34 | ``` | 34 | ``` |
35 | service tox_dht_bootstrap_server_daemon status | 35 | service tox_bootstrap_daemon status |
36 | ``` | 36 | ``` |
37 | 37 | ||
38 | -- | 38 | -- |
39 | 39 | ||
40 | You can see daemon's log with | 40 | You can see daemon's log with |
41 | ``` | 41 | ``` |
42 | grep "tox_dht_bootstrap_server_daemon" /var/log/syslog | 42 | grep "tox_bootstrap_daemon" /var/log/syslog |
43 | ``` | 43 | ``` |
44 | 44 | ||
45 | **Note that system log is where you find your public key** | 45 | **Note that system log is where you find your public key** |
@@ -50,12 +50,12 @@ grep "tox_dht_bootstrap_server_daemon" /var/log/syslog | |||
50 | 50 | ||
51 | 1. Check the log for errors with | 51 | 1. Check the log for errors with |
52 | ``` | 52 | ``` |
53 | grep "tox_dht_bootstrap_server_daemon" /var/log/syslog | 53 | grep "tox_bootstrap_daemon" /var/log/syslog |
54 | ``` | 54 | ``` |
55 | 55 | ||
56 | 2. Check that paths in the beginning of `/etc/init.d/tox_dht_bootstrap_server_daemon` are valid | 56 | 2. Check that paths in the beginning of `/etc/init.d/tox_bootstrap_daemon` are valid |
57 | 57 | ||
58 | 3. Make sure that `PIDFILE` from `/etc/init.d/tox_dht_bootstrap_server_daemon` matches with the `pid_file_path` from `conf` | 58 | 3. Make sure that `PIDFILE` from `/etc/init.d/tox_bootstrap_daemon` matches with the `pid_file_path` from `conf` |
59 | 59 | ||
60 | 4. Make sure you have write permission to keys and pid files | 60 | 4. Make sure you have write permission to keys and pid files |
61 | 61 | ||
diff --git a/other/bootstrap_serverdaemon/conf b/other/bootstrap_serverdaemon/conf index 70dbdb14..8451d9a0 100644 --- a/other/bootstrap_serverdaemon/conf +++ b/other/bootstrap_serverdaemon/conf | |||
@@ -1,33 +1,34 @@ | |||
1 | // ProjectTox bootstrap server configuration file | 1 | // ProjectTox dht bootstrap server daemon configuration file. |
2 | 2 | ||
3 | // listening port | 3 | // Listening port. |
4 | port = 33445 | 4 | port = 33445 |
5 | 5 | ||
6 | // The key file is like a password, so keep it where no one can read it | 6 | // The key file is like a password, so keep it where no one can read it. |
7 | // The daemon should have permission to read/write to it | 7 | // The daemon should have permission to read/write to it. |
8 | // Remember to replace the provided example with | 8 | // Remember to replace the provided example with your own path. |
9 | // your own path | 9 | keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" |
10 | keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys" | ||
11 | 10 | ||
12 | // The PID file written to by daemon, | 11 | // The PID file written to by daemon. |
13 | // make sure that the user who runs the server | 12 | // Make sure that the user who runs the daemon has permissions to write to the |
14 | // does have permissions to write to it | 13 | // PID file. |
15 | // Remember to replace the provided example with | 14 | // Remember to replace the provided example with your own path. |
16 | // your own path | 15 | pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" |
17 | pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid" | ||
18 | 16 | ||
17 | // Enable IPv6. | ||
19 | enable_ipv6 = false | 18 | enable_ipv6 = false |
20 | 19 | ||
21 | // Automatically bootstrap with nodes on local network | 20 | // Automatically bootstrap with nodes on local area network. |
22 | enable_lan_discovery = true | 21 | enable_lan_discovery = true |
23 | 22 | ||
24 | // Any number of nodes the daemon will bootstrap itself from | 23 | // Any number of servers the daemon will bootstrap itself from. |
25 | // Remember to replace the provided example with | 24 | // Remember to replace the provided example with your own server list. |
26 | // your own server list | 25 | // You may leave the list empty or remove "bootstrap_servers" complitely, |
26 | // in both cases this will be interpreted as if you don't want to bootstrap | ||
27 | // from anyone. | ||
27 | bootstrap_servers = ( | 28 | bootstrap_servers = ( |
28 | { // Server 1 | 29 | { // Server 1 |
29 | // any ipv4 or ipv6, depending if `enable_ipv6` is set or not | 30 | // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also |
30 | // also any US-ASCII domain name | 31 | // any US-ASCII domain name. |
31 | address = "198.46.136.167" | 32 | address = "198.46.136.167" |
32 | port = 33445 | 33 | port = 33445 |
33 | public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" | 34 | public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" |
diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c index 24bb8266..f2c54bb1 100644 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* tox_dht_bootstrap_server_daemon | 1 | /* tox_bootstrap_daemon.c |
2 | * | 2 | * |
3 | * A simple DHT bootstrap server for tox - daemon edition. | 3 | * Tox DHT bootstrap server daemon. |
4 | * | 4 | * |
5 | * Copyright (C) 2014 Tox project All Rights Reserved. | 5 | * Copyright (C) 2014 Tox project All Rights Reserved. |
6 | * | 6 | * |
@@ -42,13 +42,13 @@ | |||
42 | 42 | ||
43 | #include "../../testing/misc_tools.c" | 43 | #include "../../testing/misc_tools.c" |
44 | 44 | ||
45 | #define DAEMON_NAME "tox_dht_bootstrap_server_daemon" | 45 | #define DAEMON_NAME "tox_bootstrap_daemon" |
46 | 46 | ||
47 | #define SLEEP_TIME_MILLISECONDS 30 | 47 | #define SLEEP_TIME_MILLISECONDS 30 |
48 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) | 48 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) |
49 | 49 | ||
50 | #define DEFAULT_PID_FILE_PATH ".tox_dht_bootstrap_server_daemon.pid" | 50 | #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" |
51 | #define DEFAULT_KEYS_FILE_PATH ".tox_dht_bootstrap_server_daemon.keys" | 51 | #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" |
52 | #define DEFAULT_PORT 33445 | 52 | #define DEFAULT_PORT 33445 |
53 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false | 53 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false |
54 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false | 54 | #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 | |||
186 | 186 | ||
187 | // Bootstraps servers listed in the config file | 187 | // Bootstraps servers listed in the config file |
188 | // | 188 | // |
189 | // returns 1 on success | 189 | // returns 1 on success, some or no bootstrap servers were added |
190 | // 0 on failure, either no or only some servers were bootstrapped | 190 | // 0 on failure, a error accured while parsing config file |
191 | 191 | ||
192 | int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | 192 | int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) |
193 | { | 193 | { |
@@ -210,9 +210,15 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
210 | config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); | 210 | config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); |
211 | 211 | ||
212 | if (server_list == NULL) { | 212 | if (server_list == NULL) { |
213 | syslog(LOG_ERR, "No '%s' setting in configuration file.\n", NAME_BOOTSTRAP_SERVERS); | 213 | syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS); |
214 | config_destroy(&cfg); | 214 | config_destroy(&cfg); |
215 | return 0; | 215 | return 1; |
216 | } | ||
217 | |||
218 | if (config_setting_length(server_list) == 0) { | ||
219 | syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n"); | ||
220 | config_destroy(&cfg); | ||
221 | return 1; | ||
216 | } | 222 | } |
217 | 223 | ||
218 | int bs_port; | 224 | int bs_port; |
@@ -232,21 +238,31 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
232 | return 0; | 238 | return 0; |
233 | } | 239 | } |
234 | 240 | ||
235 | // Proceed only if all parts are present | 241 | // Check that all settings are present |
236 | if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE || | 242 | if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { |
237 | config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE || | 243 | syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); |
238 | config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) { | ||
239 | goto next; | 244 | goto next; |
240 | } | 245 | } |
241 | 246 | ||
247 | if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) { | ||
248 | syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT); | ||
249 | goto next; | ||
250 | } | ||
251 | |||
252 | if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) { | ||
253 | syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS); | ||
254 | goto next; | ||
255 | } | ||
256 | |||
257 | // Process settings | ||
242 | if (strlen(bs_public_key) != 64) { | 258 | if (strlen(bs_public_key) != 64) { |
243 | syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_PUBLIC_KEY, bs_public_key); | 259 | syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); |
244 | goto next; | 260 | goto next; |
245 | } | 261 | } |
246 | 262 | ||
247 | // not (1 <= port <= 65535) | 263 | // not (1 <= port <= 65535) |
248 | if (bs_port < 1 || bs_port > 65535) { | 264 | if (bs_port < 1 || bs_port > 65535) { |
249 | syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %d.\n", i, NAME_PORT, bs_port); | 265 | syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port); |
250 | goto next; | 266 | goto next; |
251 | } | 267 | } |
252 | 268 | ||
@@ -254,11 +270,11 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
254 | hex_string_to_bin((char *)bs_public_key)); | 270 | hex_string_to_bin((char *)bs_public_key)); |
255 | 271 | ||
256 | if (!address_resolved) { | 272 | if (!address_resolved) { |
257 | syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_ADDRESS, bs_address); | 273 | syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address); |
258 | goto next; | 274 | goto next; |
259 | } | 275 | } |
260 | 276 | ||
261 | syslog(LOG_DEBUG, "Successfully connected to %s:%d %s\n", bs_address, bs_port, bs_public_key); | 277 | syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); |
262 | 278 | ||
263 | next: | 279 | next: |
264 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it | 280 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it |
@@ -273,36 +289,6 @@ next: | |||
273 | return 1; | 289 | return 1; |
274 | } | 290 | } |
275 | 291 | ||
276 | // Checks if we are connected to the DHT | ||
277 | // | ||
278 | // returns 1 on success | ||
279 | // 0 on failure | ||
280 | |||
281 | int try_connect(DHT *dht, int port, int enable_lan_discovery) | ||
282 | { | ||
283 | uint16_t htons_port = htons(port); | ||
284 | |||
285 | int i; | ||
286 | |||
287 | for (i = 0; i < 100; i ++) { | ||
288 | do_DHT(dht); | ||
289 | |||
290 | if (enable_lan_discovery) { | ||
291 | send_LANdiscovery(htons_port, dht); | ||
292 | } | ||
293 | |||
294 | networking_poll(dht->c->lossless_udp->net); | ||
295 | |||
296 | if (DHT_isconnected(dht)) { | ||
297 | return 1; | ||
298 | } | ||
299 | |||
300 | sleep; | ||
301 | } | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | // Prints public key | 292 | // Prints public key |
307 | 293 | ||
308 | void print_public_key(uint8_t *public_key) | 294 | void print_public_key(uint8_t *public_key) |
@@ -330,7 +316,7 @@ int main(int argc, char *argv[]) | |||
330 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); | 316 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); |
331 | 317 | ||
332 | if (argc < 2) { | 318 | if (argc < 2) { |
333 | syslog(LOG_ERR, "Please specify a configuration file. Exiting.\n"); | 319 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); |
334 | return 1; | 320 | return 1; |
335 | } | 321 | } |
336 | 322 | ||
@@ -395,13 +381,6 @@ int main(int argc, char *argv[]) | |||
395 | return 1; | 381 | return 1; |
396 | } | 382 | } |
397 | 383 | ||
398 | if (try_connect(dht, port, enable_lan_discovery)) { | ||
399 | syslog(LOG_INFO, "Successfully connected to DHT\n"); | ||
400 | } else { | ||
401 | syslog(LOG_ERR, "Couldn't connect to the DHT. Check settings and network connections. Exiting.\n"); | ||
402 | return 1; | ||
403 | } | ||
404 | |||
405 | print_public_key(dht->c->self_public_key); | 384 | print_public_key(dht->c->self_public_key); |
406 | 385 | ||
407 | // Write the PID file | 386 | // Write the PID file |
@@ -419,11 +398,14 @@ int main(int argc, char *argv[]) | |||
419 | pid_t pid = fork(); | 398 | pid_t pid = fork(); |
420 | 399 | ||
421 | if (pid < 0) { | 400 | if (pid < 0) { |
401 | fclose(pidf); | ||
422 | syslog(LOG_ERR, "Forking failed. Exiting.\n"); | 402 | syslog(LOG_ERR, "Forking failed. Exiting.\n"); |
423 | return 1; | 403 | return 1; |
424 | } | 404 | } |
425 | 405 | ||
426 | if (pid > 0) { | 406 | if (pid > 0) { |
407 | fprintf(pidf, "%d\n", pid); | ||
408 | fclose(pidf); | ||
427 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); | 409 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); |
428 | return 0; | 410 | return 0; |
429 | } | 411 | } |
@@ -431,9 +413,6 @@ int main(int argc, char *argv[]) | |||
431 | // Change the file mode mask | 413 | // Change the file mode mask |
432 | umask(0); | 414 | umask(0); |
433 | 415 | ||
434 | fprintf(pidf, "%d\n", pid); | ||
435 | fclose(pidf); | ||
436 | |||
437 | // Create a new SID for the child process | 416 | // Create a new SID for the child process |
438 | if (setsid() < 0) { | 417 | if (setsid() < 0) { |
439 | syslog(LOG_ERR, "SID creation failure. Exiting.\n"); | 418 | syslog(LOG_ERR, "SID creation failure. Exiting.\n"); |
@@ -454,6 +433,8 @@ int main(int argc, char *argv[]) | |||
454 | uint64_t last_LANdiscovery = 0; | 433 | uint64_t last_LANdiscovery = 0; |
455 | uint16_t htons_port = htons(port); | 434 | uint16_t htons_port = htons(port); |
456 | 435 | ||
436 | int waiting_for_dht_connection = 1; | ||
437 | |||
457 | while (1) { | 438 | while (1) { |
458 | do_DHT(dht); | 439 | do_DHT(dht); |
459 | 440 | ||
@@ -464,6 +445,11 @@ int main(int argc, char *argv[]) | |||
464 | 445 | ||
465 | networking_poll(dht->net); | 446 | networking_poll(dht->net); |
466 | 447 | ||
448 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | ||
449 | syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n"); | ||
450 | waiting_for_dht_connection = 0; | ||
451 | } | ||
452 | |||
467 | sleep; | 453 | sleep; |
468 | } | 454 | } |
469 | 455 | ||
diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh index 678db5e3..83d9a119 100644 --- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh | |||
@@ -1,18 +1,19 @@ | |||
1 | #! /bin/sh | 1 | #! /bin/sh |
2 | ### BEGIN INIT INFO | 2 | ### BEGIN INIT INFO |
3 | # Provides: tox_dht_bootstrap_server_daemon | 3 | # Provides: tox_bootstrap_daemon |
4 | # Required-Start: $remote_fs $syslog | 4 | # Required-Start: $remote_fs $syslog |
5 | # Required-Stop: $remote_fs $syslog | 5 | # Required-Stop: $remote_fs $syslog |
6 | # Default-Start: 2 3 4 5 | 6 | # Default-Start: 2 3 4 5 |
7 | # Default-Stop: 0 1 6 | 7 | # Default-Stop: 0 1 6 |
8 | # Short-Description: Starts the Tox bootstrapping server | 8 | # Short-Description: Starts the Tox DHT bootstrapping server daemon |
9 | # Description: Starts the Tox bootstrapping server | 9 | # Description: Starts the Tox DHT bootstrapping server daemon |
10 | ### END INIT INFO | 10 | ### END INIT INFO |
11 | 11 | ||
12 | # PATH should only include /usr/* if it runs after the mountnfs.sh script | 12 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | 13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
14 | DESC="ProjectTox bootstrap server daemon" | 14 | DESC="Tox DHT bootstrap server daemon" |
15 | NAME=tox_dht_bootstrap_server_daemon | 15 | NAME=tox_bootstrap_daemon |
16 | # You may want to change USER if you are using it anywhere else | ||
16 | USER=tom | 17 | USER=tom |
17 | CFG=/home/$USER/.$NAME/conf | 18 | CFG=/home/$USER/.$NAME/conf |
18 | DAEMON=/home/$USER/$NAME | 19 | DAEMON=/home/$USER/$NAME |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index d5808313..02175c2a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -46,11 +46,13 @@ | |||
46 | /* Ping interval in seconds for each random sending of a get nodes request. */ | 46 | /* Ping interval in seconds for each random sending of a get nodes request. */ |
47 | #define GET_NODE_INTERVAL 5 | 47 | #define GET_NODE_INTERVAL 5 |
48 | 48 | ||
49 | #define MAX_PUNCHING_PORTS 32 | 49 | #define MAX_PUNCHING_PORTS 48 |
50 | 50 | ||
51 | /* Interval in seconds between punching attempts*/ | 51 | /* Interval in seconds between punching attempts*/ |
52 | #define PUNCH_INTERVAL 3 | 52 | #define PUNCH_INTERVAL 3 |
53 | 53 | ||
54 | #define MAX_NORMAL_PUNCHING_TRIES 5 | ||
55 | |||
54 | #define NAT_PING_REQUEST 0 | 56 | #define NAT_PING_REQUEST 0 |
55 | #define NAT_PING_RESPONSE 1 | 57 | #define NAT_PING_RESPONSE 1 |
56 | 58 | ||
@@ -1793,7 +1795,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1793 | pinging.port = htons(firstport); | 1795 | pinging.port = htons(firstport); |
1794 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1796 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); |
1795 | } else { | 1797 | } else { |
1796 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; i++) { | 1798 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { |
1797 | /* TODO: Improve port guessing algorithm. */ | 1799 | /* TODO: Improve port guessing algorithm. */ |
1798 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | 1800 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); |
1799 | IP_Port pinging; | 1801 | IP_Port pinging; |
@@ -1804,6 +1806,22 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1804 | 1806 | ||
1805 | dht->friends_list[friend_num].nat.punching_index = i; | 1807 | dht->friends_list[friend_num].nat.punching_index = i; |
1806 | } | 1808 | } |
1809 | |||
1810 | if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { | ||
1811 | top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS; | ||
1812 | uint16_t port = 1024; | ||
1813 | IP_Port pinging; | ||
1814 | ip_copy(&pinging.ip, &ip); | ||
1815 | |||
1816 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { | ||
1817 | pinging.port = htons(port + i); | ||
1818 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | ||
1819 | } | ||
1820 | |||
1821 | dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2); | ||
1822 | } | ||
1823 | |||
1824 | ++dht->friends_list[friend_num].nat.tries; | ||
1807 | } | 1825 | } |
1808 | 1826 | ||
1809 | static void do_NAT(DHT *dht) | 1827 | 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 { | |||
109 | /* 1 if currently hole punching, otherwise 0 */ | 109 | /* 1 if currently hole punching, otherwise 0 */ |
110 | uint8_t hole_punching; | 110 | uint8_t hole_punching; |
111 | uint32_t punching_index; | 111 | uint32_t punching_index; |
112 | uint32_t tries; | ||
113 | uint32_t punching_index2; | ||
114 | |||
112 | uint64_t punching_timestamp; | 115 | uint64_t punching_timestamp; |
113 | uint64_t recvNATping_timestamp; | 116 | uint64_t recvNATping_timestamp; |
114 | uint64_t NATping_id; | 117 | uint64_t NATping_id; |
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 | |||
258 | ip_port->port = addr_in->sin_port; | 258 | ip_port->port = addr_in->sin_port; |
259 | } else if (addr.ss_family == AF_INET6) { | 259 | } else if (addr.ss_family == AF_INET6) { |
260 | struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; | 260 | struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr; |
261 | |||
262 | ip_port->ip.family = addr_in6->sin6_family; | 261 | ip_port->ip.family = addr_in6->sin6_family; |
263 | ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr; | 262 | ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr; |
264 | ip_port->port = addr_in6->sin6_port; | 263 | ip_port->port = addr_in6->sin6_port; |
264 | |||
265 | if (IN6_IS_ADDR_V4MAPPED(&ip_port->ip.ip6.in6_addr)) { | ||
266 | ip_port->ip.family = AF_INET; | ||
267 | ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3]; | ||
268 | } | ||
265 | } else | 269 | } else |
266 | return -1; | 270 | return -1; |
267 | 271 | ||
diff --git a/toxcore/network.h b/toxcore/network.h index 0e0f0af9..4c7f1a83 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -24,6 +24,11 @@ | |||
24 | #ifndef NETWORK_H | 24 | #ifndef NETWORK_H |
25 | #define NETWORK_H | 25 | #define NETWORK_H |
26 | 26 | ||
27 | #ifdef PLAN9 | ||
28 | #include <u.h> //Plan 9 requires this is imported first | ||
29 | #include <libc.h> | ||
30 | #endif | ||
31 | |||
27 | #include <stdlib.h> | 32 | #include <stdlib.h> |
28 | #include <stdio.h> | 33 | #include <stdio.h> |
29 | #include <stdint.h> | 34 | #include <stdint.h> |
@@ -75,6 +80,19 @@ typedef int sock_t; | |||
75 | 80 | ||
76 | #endif | 81 | #endif |
77 | 82 | ||
83 | #if defined(__AIX__) | ||
84 | # define _XOPEN_SOURCE 1 | ||
85 | #endif | ||
86 | |||
87 | #if defined(__sun__) | ||
88 | #define __EXTENSIONS__ 1 // SunOS! | ||
89 | #if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) || defined(__SunOS5_9__) || defined(__SunOS5_10__) | ||
90 | //Nothing needed | ||
91 | #else | ||
92 | #define __MAKECONTEXT_V2_SOURCE 1 | ||
93 | #endif | ||
94 | #endif | ||
95 | |||
78 | #ifndef VANILLA_NACL | 96 | #ifndef VANILLA_NACL |
79 | /* We use libsodium by default. */ | 97 | /* We use libsodium by default. */ |
80 | #include <sodium.h> | 98 | #include <sodium.h> |
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 | |||
55 | memcpy(step1 + sizeof(IP_Port), data, length); | 55 | memcpy(step1 + sizeof(IP_Port), data, length); |
56 | 56 | ||
57 | uint8_t nonce[crypto_box_NONCEBYTES]; | 57 | uint8_t nonce[crypto_box_NONCEBYTES]; |
58 | new_nonce(nonce); | 58 | random_nonce(nonce); |
59 | uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; | 59 | uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; |
60 | uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; | 60 | uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; |
61 | crypto_box_keypair(random_public_key, random_secret_key); | 61 | 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 | |||
61 | ONION_ANNOUNCE_SENDBACK_DATA_LENGTH); | 61 | ONION_ANNOUNCE_SENDBACK_DATA_LENGTH); |
62 | uint8_t packet[ANNOUNCE_REQUEST_SIZE]; | 62 | uint8_t packet[ANNOUNCE_REQUEST_SIZE]; |
63 | packet[0] = NET_PACKET_ANNOUNCE_REQUEST; | 63 | packet[0] = NET_PACKET_ANNOUNCE_REQUEST; |
64 | new_nonce(packet + 1); | 64 | random_nonce(packet + 1); |
65 | 65 | ||
66 | int len = encrypt_data(nodes[3].client_id, secret_key, packet + 1, plain, sizeof(plain), | 66 | int len = encrypt_data(nodes[3].client_id, secret_key, packet + 1, plain, sizeof(plain), |
67 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES); | 67 | 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 | |||
253 | to_net_family(&nodes_list[i].ip_port.ip); | 253 | to_net_family(&nodes_list[i].ip_port.ip); |
254 | 254 | ||
255 | uint8_t nonce[crypto_box_NONCEBYTES]; | 255 | uint8_t nonce[crypto_box_NONCEBYTES]; |
256 | new_nonce(nonce); | 256 | random_nonce(nonce); |
257 | 257 | ||
258 | uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)]; | 258 | uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)]; |
259 | 259 | ||
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index f0f8fa70..93697c28 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 | |||
50 | { | 50 | { |
51 | uint8_t plain[sizeof(uint32_t) + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; | 51 | uint8_t plain[sizeof(uint32_t) + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; |
52 | uint64_t time = unix_time(); | 52 | uint64_t time = unix_time(); |
53 | new_nonce(sendback); | 53 | random_nonce(sendback); |
54 | memcpy(plain, &num, sizeof(uint32_t)); | 54 | memcpy(plain, &num, sizeof(uint32_t)); |
55 | memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t)); | 55 | memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t)); |
56 | memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES); | 56 | memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES); |
@@ -183,13 +183,19 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ | |||
183 | qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); | 183 | qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); |
184 | 184 | ||
185 | int index = -1; | 185 | int index = -1; |
186 | uint32_t i; | ||
186 | 187 | ||
187 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) | 188 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
188 | || id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) { | 189 | if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT) |
189 | index = 0; | 190 | || id_closest(reference_id, list_nodes[i].client_id, public_key) == 2) { |
190 | } | 191 | index = i; |
191 | 192 | ||
192 | uint32_t i; | 193 | if (i != 0) |
194 | break; | ||
195 | } else { | ||
196 | break; | ||
197 | } | ||
198 | } | ||
193 | 199 | ||
194 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { | 200 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
195 | if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 201 | 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 | |||
255 | } | 261 | } |
256 | } | 262 | } |
257 | 263 | ||
258 | if (j == MAX_ONION_CLIENTS) | 264 | if (j == MAX_ONION_CLIENTS) { |
259 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); | 265 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); |
266 | } | ||
260 | } | 267 | } |
261 | } | 268 | } |
262 | 269 | ||
@@ -306,7 +313,10 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe | |||
306 | if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) | 313 | if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) |
307 | return 1; | 314 | return 1; |
308 | 315 | ||
309 | if (client_ping_nodes(onion_c, num, (Node_format *)plain + 1 + ONION_PING_ID_SIZE, num_nodes, source) == -1) | 316 | Node_format nodes[MAX_SENT_NODES]; |
317 | memcpy(nodes, plain + 1 + ONION_PING_ID_SIZE, num_nodes * sizeof(Node_format)); | ||
318 | |||
319 | if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) | ||
310 | return 1; | 320 | return 1; |
311 | 321 | ||
312 | return 0; | 322 | return 0; |
@@ -420,7 +430,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32 | |||
420 | return -1; | 430 | return -1; |
421 | 431 | ||
422 | uint8_t nonce[crypto_box_NONCEBYTES]; | 432 | uint8_t nonce[crypto_box_NONCEBYTES]; |
423 | new_nonce(nonce); | 433 | random_nonce(nonce); |
424 | 434 | ||
425 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; | 435 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; |
426 | memcpy(packet, onion_c->dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); | 436 | 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 | |||
703 | return -1; | 713 | return -1; |
704 | 714 | ||
705 | onion_c->friends_list[friend_num].is_online = is_online; | 715 | onion_c->friends_list[friend_num].is_online = is_online; |
706 | /* Should we reset the no_replay when the other goes offline? | 716 | |
717 | /* This should prevent some clock related issues */ | ||
707 | if (!is_online) | 718 | if (!is_online) |
708 | onion_c->friends_list[friend_num].last_noreplay = 0; */ | 719 | onion_c->friends_list[friend_num].last_noreplay = 0; |
720 | |||
709 | return 0; | 721 | return 0; |
710 | } | 722 | } |
711 | 723 | ||
@@ -754,16 +766,17 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
754 | } | 766 | } |
755 | } | 767 | } |
756 | 768 | ||
757 | if (count < MAX_ONION_CLIENTS / 2) { | 769 | if (count != MAX_ONION_CLIENTS) { |
758 | Node_format nodes_list[MAX_SENT_NODES]; | 770 | if (count < rand() % MAX_ONION_CLIENTS) { |
759 | uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, | 771 | Node_format nodes_list[MAX_SENT_NODES]; |
760 | rand() % 2 ? AF_INET : AF_INET6, 1, 0); | 772 | uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, |
773 | rand() % 2 ? AF_INET : AF_INET6, 1, 0); | ||
761 | 774 | ||
762 | for (i = 0; i < num_nodes; ++i) | 775 | for (i = 0; i < num_nodes; ++i) |
763 | client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); | 776 | client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); |
777 | } | ||
764 | } | 778 | } |
765 | 779 | ||
766 | |||
767 | /* send packets to friend telling them our fake DHT id. */ | 780 | /* send packets to friend telling them our fake DHT id. */ |
768 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) | 781 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) |
769 | if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) | 782 | if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) |
@@ -772,6 +785,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
772 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) | 785 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) |
773 | if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) | 786 | if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) |
774 | onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); | 787 | onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); |
788 | |||
775 | } | 789 | } |
776 | } | 790 | } |
777 | /* Function to call when onion data packet with contents beginning with byte is received. */ | 791 | /* 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) | |||
808 | } | 822 | } |
809 | } | 823 | } |
810 | 824 | ||
811 | if (count < MAX_ONION_CLIENTS / 2) { | 825 | if (count != MAX_ONION_CLIENTS) { |
812 | Node_format nodes_list[MAX_SENT_NODES]; | 826 | if (count < rand() % MAX_ONION_CLIENTS) { |
813 | uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, | 827 | Node_format nodes_list[MAX_SENT_NODES]; |
814 | rand() % 2 ? AF_INET : AF_INET6, 1, 0); | 828 | uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, |
829 | rand() % 2 ? AF_INET : AF_INET6, 1, 0); | ||
815 | 830 | ||
816 | for (i = 0; i < num_nodes; ++i) | 831 | for (i = 0; i < num_nodes; ++i) |
817 | client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); | 832 | client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); |
833 | } | ||
818 | } | 834 | } |
819 | } | 835 | } |
820 | 836 | ||
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 @@ | |||
35 | #include "network.h" | 35 | #include "network.h" |
36 | #include "util.h" | 36 | #include "util.h" |
37 | 37 | ||
38 | #define PING_NUM_MAX 384 | 38 | #define PING_NUM_MAX 512 |
39 | 39 | ||
40 | /* Ping newly announced nodes to ping per TIME_TOPING seconds*/ | 40 | /* Ping newly announced nodes to ping per TIME_TOPING seconds*/ |
41 | #define TIME_TOPING 5 | 41 | #define TIME_TOPING 5 |