From 86cd3141d0380c77fc14545206ce9545563b49d8 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 10 May 2015 03:04:42 -0400 Subject: Updated daemon's systemd file, fixed typos in README @arthurtiteica has pointed out that systemd has more suitable facilities for creating a temporary directory for a PID file rather than calling ExecStartPre, which requires an absolute path to coreutils executables we used for creating a directory and changing its owner, paths of which are are not universal across distributions. Systemd can take care of it for us without need to provide absolute paths, which is what we use here. --- other/bootstrap_daemon/README.md | 134 +++++++++++++++++--------- other/bootstrap_daemon/tox-bootstrapd.service | 8 +- 2 files changed, 90 insertions(+), 52 deletions(-) diff --git a/other/bootstrap_daemon/README.md b/other/bootstrap_daemon/README.md index d0c16eb1..e77e3ae0 100644 --- a/other/bootstrap_daemon/README.md +++ b/other/bootstrap_daemon/README.md @@ -1,6 +1,17 @@ -##Instructions +#Instructions -This instruction primarily tested on Linux but, may be, will work on other POSIX-compliant systems. +- [For `systemd` users](#systemd) + - [Troubleshooting](#systemd-troubleshooting) +
+- [For `init.d` users](#initd) + - [Troubleshooting](#initd-troubleshooting) + + +These instructions are primarily tested on Debian Linux, Wheezy for init.d and Jessie for systemd, but they should work on other POSIX-compliant systems too. + + + +##For `systemd` users: For security reasons we run the daemon under its own user. @@ -9,100 +20,129 @@ Create a new user by executing the following: sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd ``` -Copy `tox-bootstrapd.conf` file to where `CFGFILE` variable from `tox-bootstrapd.sh` tells (for `init.d` users) or `ExecStart=` from `tox-bootstrap.service` ( for `systemd` users). By default it's `/etc/tox-bootstrapd.conf`. - -Go over everything in `tox-bootstrapd.conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox-bootstrapd.sh` (`init.d`) or `PIDFile=` from `tox-bootstrap.service` AND file in `ExecStartPre`(`systemd`). - - Restrict access to home directory: ```sh sudo chmod 700 /var/lib/tox-bootstrapd ``` -##For `init.d` users: +Copy `tox-bootstrapd.conf` file to where `ExecStart=` from `tox-bootstrapd.service` points to. By default it's `/etc/tox-bootstrapd.conf`. +```sh +sudo cp tox-bootstrapd.conf /etc/tox-bootstrapd.conf +``` -Look at the variable declarations in the beginning of `tox-bootstrapd.sh` init script to see if you need to change anything for it to work for you. The default values must be fine for most users and we assume that you use those next. +Go over everything in the copied `tox-bootstrapd.conf` file. Set options you want and add actual working nodes to the `bootstrap_nodes` list, instead of the example ones, if you want your node to connect to the Tox network. Make sure `pid_file_path` matches `PIDFile=` from `tox-bootstrapd.service`. -Copy `tox-bootstrapd.sh` init file to `/etc/init.d/tox-bootstrapd` (note the disappearance of ".sh" ending). +Copy `tox-bootstrapd.service` to `/etc/systemd/system/`: ```sh -sudo cp tox-bootstrapd.sh /etc/init.d/tox-bootstrapd +sudo cp tox-bootstrapd.service /etc/systemd/system/ ``` -Set permissions for the init system to run the script: +You must uncomment the next line in tox-bootstrapd.service, if you want to use port number < 1024 + + #CapabilityBoundingSet=CAP_NET_BIND_SERVICE + +and, possibly, install `libcap2-bin` or `libcap2` package, depending of your distribution. + +Reload systemd units definitions, enable service for automatic start (if needed), start it and verify it's running: ```sh -sudo chmod 755 /etc/init.d/tox-bootstrapd +sudo systemctl daemon-reload +sudo systemctl enable tox-bootstrapd.service +sudo systemctl start tox-bootstrapd.service +sudo systemctl status tox-bootstrapd.service ``` -Make the init system aware of the script: +Get your public key and check that the daemon initialized correctly: ```sh -sudo update-rc.d tox-bootstrapd defaults +sudo grep "tox-bootstrapd" /var/log/syslog ``` -Start the daemon: + +###Troubleshooting: + +- Check daemon's status: ```sh -sudo service tox-bootstrapd start +sudo systemctl status tox-bootstrapd.service ``` -Verify it's running: +- Check the log for errors: ```sh -sudo service tox-bootstrapd status +sudo grep "tox-bootstrapd" /var/log/syslog +# or +sudo journalctl --pager-end +# or +sudo journalctl -f _SYSTEMD_UNIT=tox-bootstrapd.service ``` -Get your public key and check that the daemon initialized correctly: +- Make sure tox-bootstrapd user has write permission for keys and pid files. + +- Make sure tox-bootstrapd has read permission for the config file. + +- Make sure tox-bootstrapd location matches its path in tox-bootstrapd.service file. + + + +##For `init.d` users + +For security reasons we run the daemon under its own user. + +Create a new user by executing the following: ```sh -sudo grep "tox-bootstrapd" /var/log/syslog +sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd ``` -##For `systemd` users: +Restrict access to home directory: +```sh +sudo chmod 700 /var/lib/tox-bootstrapd +``` -Copy tox-bootstrap.service to /etc/systemd/system/: +Copy `tox-bootstrapd.conf` file to where `CFGFILE` variable from `tox-bootstrapd.sh` points to. By default it's `/etc/tox-bootstrapd.conf`. ```sh -sudo cp tox-bootstrap.service /etc/systemd/system/ +sudo cp tox-bootstrapd.conf /etc/tox-bootstrapd.conf ``` -Make sure, that path to `chown` and `mkdir` is correct in `tox-bootstrap.service` (they may be different in some distributions, by default `/bin/chown` and `/bin/mkdir`) +Go over everything in the copied `tox-bootstrapd.conf` file. Set options you want and add actual working nodes to the `bootstrap_nodes` list, instead of the example ones, if you want your node to connect to the Tox network. Make sure `pid_file_path` matches `PIDFILE` from `tox-bootstrapd.sh`. -You must uncomment the next line in tox-bootstrap.service, if you want to use port number <1024 - - #CapabilityBoundingSet=CAP_NET_BIND_SERVICE +Look at the variable declarations in the beginning of `tox-bootstrapd.sh` init script to see if you need to change anything for it to work on your system. The default values must be fine for most users and we assume that you use those next. -and, possibly, install `libcap2-bin` or `libcap2` package, depending of your distribution. +Copy `tox-bootstrapd.sh` init script to `/etc/init.d/tox-bootstrapd` (note the disappearance of ".sh" ending): +```sh +sudo cp tox-bootstrapd.sh /etc/init.d/tox-bootstrapd +``` +Set permissions for the init system to run the script: +```sh +sudo chmod 755 /etc/init.d/tox-bootstrapd +``` -Reload systemd units definitions, enable service for automatic start (if needed), and start it: +Make the init system aware of the script, start the daemon and verify it's running: ```sh -sudo systemctl daemon-reload -sudo systemctl enable tox-bootstrap.service -sudo systemctl start tox-bootstrap.service +sudo update-rc.d tox-bootstrapd defaults +sudo service tox-bootstrapd start +sudo service tox-bootstrapd status +``` + +Get your public key and check that the daemon initialized correctly: +```sh +sudo grep "tox-bootstrapd" /var/log/syslog ``` + + ###Troubleshooting: - Check daemon's status: ```sh -#init.d sudo service tox-bootstrapd status - -#systemd -sudo systemctl status tox-bootstrap.service ``` - Check the log for errors: ```sh -#init.d sudo grep "tox-bootstrapd" /var/log/syslog - -#systemd -sudo journalctl -f _SYSTEMD_UNIT=tox-bootstrap.service ``` -`init.d`: - Check that variables in the beginning of `/etc/init.d/tox-bootstrapd` are valid. - -Common: - -- Make sure tox-bootstrapd user has write permission for keys and pid files (in systemd pid file insured by unit definition). +- Make sure tox-bootstrapd user has write permission for keys and pid files. - Make sure tox-bootstrapd has read permission for the config file. -- Make sure tox-bootstrapd location matches its path in init scripts, if you specified non-default `--prefix`, when building. +- Make sure tox-bootstrapd location matches its path in the `/etc/init.d/tox-bootstrapd` init script. diff --git a/other/bootstrap_daemon/tox-bootstrapd.service b/other/bootstrap_daemon/tox-bootstrapd.service index 4b499311..db54cc41 100644 --- a/other/bootstrap_daemon/tox-bootstrapd.service +++ b/other/bootstrap_daemon/tox-bootstrapd.service @@ -4,16 +4,14 @@ After=network.target [Service] Type=forking -PermissionsStartOnly=true -ExecStartPre=-/bin/mkdir /var/run/tox-bootstrapd -p -ExecStartPre=/bin/chown tox-bootstrapd:tox-bootstrapd -R /var/run/tox-bootstrapd +RuntimeDirectory=tox-bootstrapd +RuntimeDirectoryMode=750 +PIDFile=/var/run/tox-bootstrapd/tox-bootstrapd.pid WorkingDirectory=/var/lib/tox-bootstrapd ExecStart=/usr/local/bin/tox-bootstrapd /etc/tox-bootstrapd.conf User=tox-bootstrapd Group=tox-bootstrapd -PIDFile=/var/run/tox-bootstrapd/tox-bootstrapd.pid #CapabilityBoundingSet=CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target - -- cgit v1.2.3 From 19bd38999bd22e2d47cfd84a1616a4eedf1fc90d Mon Sep 17 00:00:00 2001 From: tux3 Date: Tue, 19 May 2015 19:53:55 +0200 Subject: Remove pointless nullity check on array address assoc->self_client_id is always true, therefore we can remove it from that if" -m "The if thus asserts !assoc->self_hash, so we can elide the immediately following if (!assoc->self_hash) --- toxcore/assoc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 3dbeba51..2e03dabe 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c @@ -510,20 +510,18 @@ static uint8_t candidates_create_new(const Assoc *assoc, hash_t hash, const uint static void client_id_self_update(Assoc *assoc) { - if (assoc->self_hash || !assoc->self_client_id) + if (assoc->self_hash) return; - if (!assoc->self_hash) { - size_t i, sum = 0; + size_t i, sum = 0; - for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) - sum |= assoc->self_client_id[i]; + for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) + sum |= assoc->self_client_id[i]; - if (!sum) - return; + if (!sum) + return; - assoc->self_hash = id_hash(assoc, assoc->self_client_id); - } + assoc->self_hash = id_hash(assoc, assoc->self_client_id); LOGGER_DEBUG("id is now set, purging cache of self-references"); @@ -532,7 +530,7 @@ static void client_id_self_update(Assoc *assoc) */ bucket_t b_id = candidates_id_bucket(assoc, assoc->self_client_id); candidates_bucket *cnd_bckt = &assoc->candidates[b_id]; - size_t i, pos = assoc->self_hash % assoc->candidates_bucket_size; + size_t pos = assoc->self_hash % assoc->candidates_bucket_size; for (i = 0; i < HASH_COLLIDE_COUNT; pos = hash_collide(assoc, pos), i++) { Client_entry *entry = &cnd_bckt->list[pos]; -- cgit v1.2.3 From 8e80ced6cea5c50e628c1931f6b3b764b97efb41 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 22 May 2015 18:23:56 -0400 Subject: Move savedata to options struct. Add a way to select the type of savedata (normal savedata, load a secret key, potentially others?) to load. --- auto_tests/encryptsave_test.c | 20 ++++++++++++---- auto_tests/tox_test.c | 25 ++++++++++++-------- auto_tests/toxav_basic_test.c | 6 ++--- auto_tests/toxav_many_test.c | 10 ++++---- other/apidsl/tox.in.h | 43 ++++++++++++++++++++++++++++------ testing/irc_syncbot.c | 2 +- testing/nTox.c | 14 +++++++++-- testing/tox_shell.c | 2 +- testing/tox_sync.c | 2 +- toxcore/tox.c | 54 ++++++++++++++++++++++++++++--------------- toxcore/tox.h | 49 +++++++++++++++++++++++++++++++++------ 11 files changed, 166 insertions(+), 61 deletions(-) diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index a239bcee..b0828964 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -55,8 +55,8 @@ END_TEST START_TEST(test_save_friend) { - Tox *tox1 = tox_new(0, 0, 0, 0); - Tox *tox2 = tox_new(0, 0, 0, 0); + Tox *tox1 = tox_new(0, 0); + Tox *tox2 = tox_new(0, 0); ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); uint32_t to_compare = 974536; tox_callback_friend_request(tox2, accept_friend_request, &to_compare); @@ -75,15 +75,23 @@ START_TEST(test_save_friend) ck_assert_msg(ret, "failed to encrypted save: %u", error1); ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); + struct Tox_Options options; + tox_options_default(&options); + options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + options.savedata_data = enc_data; + options.savedata_length = size2; + TOX_ERR_NEW err2; - Tox *tox3 = tox_new(0, enc_data, size2, &err2); + Tox *tox3 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, TOX_ERR_NEW_LOAD_ENCRYPTED); uint8_t dec_data[size]; TOX_ERR_DECRYPTION err3; ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); ck_assert_msg(ret, "failed to decrypt save: %u", err3); - tox3 = tox_new(0, dec_data, size, &err2); + options.savedata_data = dec_data; + options.savedata_length = size; + tox3 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); uint8_t address2[TOX_PUBLIC_KEY_SIZE]; ret = tox_friend_get_public_key(tox3, 0, address2, 0); @@ -111,7 +119,9 @@ START_TEST(test_save_friend) // and now with the code in use (I only bothered with manually to debug this, and it seems a waste // to remove the manual check now that it's there) - Tox *tox4 = tox_new(0, out1, size, &err2); + options.savedata_data = out1; + options.savedata_length = size; + Tox *tox4 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); uint8_t address5[TOX_PUBLIC_KEY_SIZE]; ret = tox_friend_get_public_key(tox4, 0, address5, 0); diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 40022b0a..22528330 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -286,8 +286,8 @@ void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *use START_TEST(test_one) { - Tox *tox1 = tox_new(0, 0, 0, 0); - Tox *tox2 = tox_new(0, 0, 0, 0); + Tox *tox1 = tox_new(0, 0); + Tox *tox2 = tox_new(0, 0); { TOX_ERR_GET_PORT error; @@ -340,7 +340,12 @@ START_TEST(test_one) tox_kill(tox2); TOX_ERR_NEW err_n; - tox2 = tox_new(0, data, save_size, &err_n); + struct Tox_Options options; + tox_options_default(&options); + options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + options.savedata_data = data; + options.savedata_length = save_size; + tox2 = tox_new(&options, &err_n); ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); @@ -361,11 +366,11 @@ START_TEST(test_few_clients) { long long unsigned int con_time, cur_time = time(NULL); TOX_ERR_NEW t_n_error; - Tox *tox1 = tox_new(0, 0, 0, &t_n_error); + Tox *tox1 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); - Tox *tox2 = tox_new(0, 0, 0, &t_n_error); + Tox *tox2 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); - Tox *tox3 = tox_new(0, 0, 0, &t_n_error); + Tox *tox3 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); @@ -745,7 +750,7 @@ START_TEST(test_many_clients) uint32_t to_comp = 974536; for (i = 0; i < NUM_TOXES; ++i) { - toxes[i] = tox_new(0, 0, 0, 0); + toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); } @@ -832,7 +837,7 @@ START_TEST(test_many_clients_tcp) opts.udp_enabled = 0; } - toxes[i] = tox_new(&opts, 0, 0, 0); + toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; @@ -926,7 +931,7 @@ START_TEST(test_many_clients_tcp_b) opts.udp_enabled = 0; } - toxes[i] = tox_new(&opts, 0, 0, 0); + toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; @@ -1062,7 +1067,7 @@ START_TEST(test_many_group) uint32_t to_comp = 234212; for (i = 0; i < NUM_GROUP_TOX; ++i) { - toxes[i] = tox_new(0, 0, 0, 0); + toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index a43b7c2f..af8d91e9 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -250,9 +250,9 @@ if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) START_TEST(test_AV_flows) { long long unsigned int cur_time = time(NULL); - Tox *bootstrap_node = tox_new(0, 0, 0, 0); - Tox *Alice = tox_new(0, 0, 0, 0); - Tox *Bob = tox_new(0, 0, 0, 0); + Tox *bootstrap_node = tox_new(0, 0); + Tox *Alice = tox_new(0, 0); + Tox *Bob = tox_new(0, 0); ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances"); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 4287118f..6017e526 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -264,12 +264,12 @@ START_TEST(test_AV_three_calls) // void test_AV_three_calls() { long long unsigned int cur_time = time(NULL); - Tox *bootstrap_node = tox_new(0, 0, 0, 0); - Tox *caller = tox_new(0, 0, 0, 0); + Tox *bootstrap_node = tox_new(0, 0); + Tox *caller = tox_new(0, 0); Tox *callees[3] = { - tox_new(0, 0, 0, 0), - tox_new(0, 0, 0, 0), - tox_new(0, 0, 0, 0), + tox_new(0, 0), + tox_new(0, 0), + tox_new(0, 0), }; diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index dd47df23..b769135a 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -340,6 +340,24 @@ enum class PROXY_TYPE { SOCKS5, } +/** + * Type of savedata to create the Tox instance from. + */ +enum class SAVEDATA_TYPE { + /** + * No savedata. + */ + NONE, + /** + * Savedata is one that was obtained from ${savedata.get} + */ + TOX_SAVE, + /** + * Savedata is a secret key of length ${SECRET_KEY_SIZE} + */ + SECRET_KEY, +} + static class options { /** @@ -416,6 +434,23 @@ static class options { * The port to use for the TCP server. If 0, the tcp server is disabled. */ uint16_t tcp_port; + + namespace savedata { + /** + * The type of savedata to load from. + */ + SAVEDATA_TYPE type; + + /** + * The savedata. + */ + const uint8_t[length] data; + + /** + * The length of the savedata. + */ + size_t length; + } } @@ -474,21 +509,15 @@ static class options { * This function will bring the instance into a valid state. Running the event * loop with a new instance will operate correctly. * - * If the data parameter is not NULL, this function will load the Tox instance - * from a byte array previously filled by ${savedata.get}. - * * If loading failed or succeeded only partially, the new or partially loaded * instance is returned and an error code is set. * * @param options An options object as described above. If this parameter is * NULL, the default options are used. - * @param data A byte array containing data previously stored by ${savedata.get}. - * @param length The length of the byte array data. If this parameter is 0, the - * data parameter is ignored. * * @see $iterate for the event loop. */ -static this new(const options_t *options, const uint8_t[length] data) { +static this new(const options_t *options) { NULL, /** * The function was unable to allocate enough memory to store the internal diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index 2d326c4b..a4e2254a 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c @@ -222,7 +222,7 @@ Tox *init_tox(int argc, char *argv[]) exit(0); } - Tox *tox = tox_new(0, 0, 0, 0); + Tox *tox = tox_new(0, 0); if (!tox) exit(1); diff --git a/testing/nTox.c b/testing/nTox.c index 77f812b5..03f17da5 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -942,7 +942,17 @@ static Tox *load_data() return 0; } - Tox *m = tox_new(0, data, size, NULL); + struct Tox_Options options; + + tox_options_default(&options); + + options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + + options.savedata_data = data; + + options.savedata_length = size; + + Tox *m = tox_new(&options, NULL); if (fclose(data_file) < 0) { perror("[!] fclose failed"); @@ -953,7 +963,7 @@ static Tox *load_data() return m; } - return tox_new(0, 0, 0, NULL); + return tox_new(NULL, NULL); } static int save_data(Tox *m) diff --git a/testing/tox_shell.c b/testing/tox_shell.c index 23fa320a..521e9f36 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) printf("error setting flags\n"); } - Tox *tox = tox_new(0, 0, 0, 0); + Tox *tox = tox_new(0, 0); tox_callback_friend_connection_status(tox, print_online, NULL); tox_callback_friend_message(tox, print_message, master); diff --git a/testing/tox_sync.c b/testing/tox_sync.c index be1fe32d..738c2f2d 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -243,7 +243,7 @@ int main(int argc, char *argv[]) exit(0); } - Tox *tox = tox_new(0, 0, 0, 0); + Tox *tox = tox_new(0, 0); tox_callback_file_recv_chunk(tox, write_file, NULL); tox_callback_file_recv_control(tox, file_print_control, NULL); tox_callback_file_recv(tox, file_request_accept, NULL); diff --git a/toxcore/tox.c b/toxcore/tox.c index de615768..3081a226 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -121,33 +121,46 @@ void tox_options_free(struct Tox_Options *options) free(options); } -Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t length, TOX_ERR_NEW *error) +Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) { if (!logger_get_global()) logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore")); - if (data == NULL && length != 0) { - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); - return NULL; - } - - if (data && length) { - if (length < TOX_ENC_SAVE_MAGIC_LENGTH) { - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); - return NULL; - } - - if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); - return NULL; - } - } - Messenger_Options m_options = {0}; + _Bool load_savedata_sk = 0, load_savedata_tox = 0; + if (options == NULL) { m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; } else { + if (options->savedata_type != TOX_SAVEDATA_TYPE_NONE) { + if (options->savedata_data == NULL || options->savedata_length == 0) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); + return NULL; + } + } + + if (options->savedata_type == TOX_SAVEDATA_TYPE_SECRET_KEY) { + if (options->savedata_length != TOX_SECRET_KEY_SIZE) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); + return NULL; + } + + load_savedata_sk = 1; + } else if (options->savedata_type == TOX_SAVEDATA_TYPE_TOX_SAVE) { + if (options->savedata_length < TOX_ENC_SAVE_MAGIC_LENGTH) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); + return NULL; + } + + if (memcmp(options->savedata_data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); + return NULL; + } + + load_savedata_tox = 1; + } + m_options.ipv6enabled = options->ipv6_enabled; m_options.udp_disabled = !options->udp_enabled; m_options.port_range[0] = options->start_port; @@ -208,8 +221,11 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng return NULL; } - if (data && length && messenger_load(m, data, length) == -1) { + if (load_savedata_tox && messenger_load(m, options->savedata_data, options->savedata_length) == -1) { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); + } else if (load_savedata_sk) { + load_secret_key(m->net_crypto, options->savedata_data); + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); } else { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); } diff --git a/toxcore/tox.h b/toxcore/tox.h index 4afdf7c3..b556d138 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -351,6 +351,29 @@ typedef enum TOX_PROXY_TYPE { } TOX_PROXY_TYPE; +/** + * Type of savedata to create the Tox instance from. + */ +typedef enum TOX_SAVEDATA_TYPE { + + /** + * No savedata. + */ + TOX_SAVEDATA_TYPE_NONE, + + /** + * Savedata is one that was obtained from tox_get_savedata + */ + TOX_SAVEDATA_TYPE_TOX_SAVE, + + /** + * Savedata is a secret key of length TOX_SECRET_KEY_SIZE + */ + TOX_SAVEDATA_TYPE_SECRET_KEY, + +} TOX_SAVEDATA_TYPE; + + /** * This struct contains all the startup options for Tox. You can either allocate * this object yourself, and pass it to tox_options_default, or call @@ -432,6 +455,24 @@ struct Tox_Options { */ uint16_t tcp_port; + + /** + * The type of savedata to load from. + */ + TOX_SAVEDATA_TYPE savedata_type; + + + /** + * The savedata. + */ + const uint8_t *savedata_data; + + + /** + * The length of the savedata. + */ + size_t savedata_length; + }; @@ -561,21 +602,15 @@ typedef enum TOX_ERR_NEW { * This function will bring the instance into a valid state. Running the event * loop with a new instance will operate correctly. * - * If the data parameter is not NULL, this function will load the Tox instance - * from a byte array previously filled by tox_get_savedata. - * * If loading failed or succeeded only partially, the new or partially loaded * instance is returned and an error code is set. * * @param options An options object as described above. If this parameter is * NULL, the default options are used. - * @param data A byte array containing data previously stored by tox_get_savedata. - * @param length The length of the byte array data. If this parameter is 0, the - * data parameter is ignored. * * @see tox_iterate for the event loop. */ -Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t length, TOX_ERR_NEW *error); +Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error); /** * Releases all resources associated with the Tox instance and disconnects from -- cgit v1.2.3 From e1a419aafc1a968cebc5ea45d5ed265a4a1b6433 Mon Sep 17 00:00:00 2001 From: urras Date: Sat, 23 May 2015 14:51:11 -0400 Subject: Fix make dist, broken in 422e744 --- Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 995620ef..7d5c788a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,9 +22,9 @@ EXTRA_DIST = \ $(top_srcdir)/docs/updates/Crypto.md \ $(top_srcdir)/docs/updates/Spam-Prevention.md \ $(top_srcdir)/docs/updates/Symmetric-NAT-Transversal.md \ - $(top_srcdir)/tools/README \ - $(top_srcdir)/tools/astylerc \ - $(top_srcdir)/tools/pre-commit + $(top_srcdir)/other/astyle/README \ + $(top_srcdir)/other/astyle/astylerc \ + $(top_srcdir)/other/astyle/pre-commit if BUILD_AV -- cgit v1.2.3 From 441e0073625b7ae9c69e977f510a8295e388a198 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 25 May 2015 15:20:38 -0400 Subject: tox_new returns NULL on failure. --- other/apidsl/tox.in.h | 2 ++ toxcore/tox.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index b769135a..5b371c17 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -516,6 +516,8 @@ static class options { * NULL, the default options are used. * * @see $iterate for the event loop. + * + * @return A new Tox instance pointer on success or NULL on failure. */ static this new(const options_t *options) { NULL, diff --git a/toxcore/tox.h b/toxcore/tox.h index b556d138..038a366f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -609,6 +609,8 @@ typedef enum TOX_ERR_NEW { * NULL, the default options are used. * * @see tox_iterate for the event loop. + * + * @return A new Tox instance pointer on success or NULL on failure. */ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error); -- cgit v1.2.3 From 51c5810d72cd81c0aaec9c10289185294112f3f5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 26 May 2015 12:57:14 -0400 Subject: These parameters should have been const. --- toxencryptsave/toxencryptsave.c | 8 ++++---- toxencryptsave/toxencryptsave.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index e2f28a58..162f530c 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -82,7 +82,7 @@ bool tox_get_salt(const uint8_t *data, uint8_t *salt) * * returns true on success */ -bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, +bool tox_derive_key_from_pass(const uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, TOX_ERR_KEY_DERIVATION *error) { uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; @@ -93,7 +93,7 @@ bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY /* Same as above, except with use the given salt for deterministic key derivation. * The salt must be TOX_PASS_SALT_LENGTH bytes in length. */ -bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, TOX_PASS_KEY *out_key, +bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const uint8_t *salt, TOX_PASS_KEY *out_key, TOX_ERR_KEY_DERIVATION *error) { if (pplength == 0 || !passphrase || !salt || !out_key) { @@ -180,7 +180,7 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const TOX_PASS_K * * returns true on success */ -bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, +bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_ENCRYPTION *error) { TOX_PASS_KEY key; @@ -252,7 +252,7 @@ bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const TOX_PASS_KEY * * returns true on success */ -bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, +bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_DECRYPTION *error) { if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH || pplength == 0) { diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index c077d899..9e28b48e 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -143,7 +143,7 @@ typedef enum TOX_ERR_DECRYPTION { * * returns true on success */ -bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, +bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_ENCRYPTION *error); @@ -155,7 +155,7 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, * * returns true on success */ -bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, +bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_DECRYPTION *error); @@ -183,13 +183,13 @@ typedef struct { * * returns true on success */ -bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, +bool tox_derive_key_from_pass(const uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, TOX_ERR_KEY_DERIVATION *error); /* Same as above, except use the given salt for deterministic key derivation. * The salt must be TOX_PASS_SALT_LENGTH bytes in length. */ -bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, TOX_PASS_KEY *out_key, +bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const uint8_t *salt, TOX_PASS_KEY *out_key, TOX_ERR_KEY_DERIVATION *error); /* This retrieves the salt used to encrypt the given data, which can then be passed to -- cgit v1.2.3 From f7d203925fa450ab6774b1fd712a2d033ab4c044 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 26 May 2015 20:30:24 -0400 Subject: Fixed bug when deleting friend that we are connected to in group chat. --- toxcore/Messenger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index dc0e605a..1288b338 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -384,12 +384,12 @@ int m_delfriend(Messenger *m, int32_t friendnumber) clear_receipts(m, friendnumber); remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk); friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); - kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) { send_offline_packet(m, m->friendlist[friendnumber].friendcon_id); } + kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); uint32_t i; -- cgit v1.2.3 From ce077eeeb3fc418d24176c17bbb07bf47b966021 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 26 May 2015 20:52:09 -0400 Subject: Fixed rare bug where userstatus, name, etc... would not be sent to friend. --- toxcore/Messenger.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 1288b338..4d4b82c1 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -864,6 +864,11 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui if (was_online) { break_files(m, friendnumber); clear_receipts(m, friendnumber); + } else { + m->friendlist[friendnumber].name_sent = 0; + m->friendlist[friendnumber].userstatus_sent = 0; + m->friendlist[friendnumber].statusmessage_sent = 0; + m->friendlist[friendnumber].user_istyping_sent = 0; } m->friendlist[friendnumber].status = status; @@ -1891,10 +1896,6 @@ static int handle_status(void *object, int i, uint8_t status) if (status) { /* Went online. */ send_online_packet(m, i); - m->friendlist[i].name_sent = 0; - m->friendlist[i].userstatus_sent = 0; - m->friendlist[i].statusmessage_sent = 0; - m->friendlist[i].user_istyping_sent = 0; } else { /* Went offline. */ if (m->friendlist[i].status == FRIEND_ONLINE) { set_friend_status(m, i, FRIEND_CONFIRMED); -- cgit v1.2.3 From 3f6a8f10bb519c887d077e79f19700691c5124a9 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 27 May 2015 19:54:04 -0400 Subject: Allow empty keys in toxencryptsave. --- auto_tests/encryptsave_test.c | 4 ++++ toxencryptsave/toxencryptsave.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index b0828964..d187e352 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -164,6 +164,10 @@ START_TEST(test_keys) ck_assert_msg(ret, "generic failure 5: %u", decerr); ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); + ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, NULL, 0, out2, &decerr); + ck_assert_msg(!ret, "Decrypt succeeded with wrong pass"); + ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %u", decerr); + // test that pass_decrypt can decrypt things from pass_key_encrypt ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, "123qweasdzxc", 12, out1, &decerr); ck_assert_msg(ret, "generic failure 6: %u", decerr); diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 162f530c..e6150ce2 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -96,7 +96,7 @@ bool tox_derive_key_from_pass(const uint8_t *passphrase, size_t pplength, TOX_PA bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const uint8_t *salt, TOX_PASS_KEY *out_key, TOX_ERR_KEY_DERIVATION *error) { - if (pplength == 0 || !passphrase || !salt || !out_key) { + if (!salt || !out_key || (!passphrase && pplength != 0)) { SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); return 0; } @@ -255,7 +255,7 @@ bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const TOX_PASS_KEY bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_DECRYPTION *error) { - if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH || pplength == 0) { + if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); return 0; } -- cgit v1.2.3 From 29c37bf2f4f7870e932ea5bf2f9f23a23f3b7cc1 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 28 May 2015 11:37:24 -0400 Subject: Fixed comment. --- other/apidsl/tox.in.h | 2 +- toxcore/tox.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index 5b371c17..87d0ab87 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -1512,7 +1512,7 @@ namespace file { */ DATA, /** - * Avatar filename. This consists of $hash(image). + * Avatar file_id. This consists of $hash(image). * Avatar data. This consists of the image data. * * Avatars can be sent at any time the client wishes. Generally, a client will diff --git a/toxcore/tox.h b/toxcore/tox.h index 038a366f..cf5491af 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1596,7 +1596,7 @@ enum TOX_FILE_KIND { TOX_FILE_KIND_DATA, /** - * Avatar filename. This consists of tox_hash(image). + * Avatar file_id. This consists of tox_hash(image). * Avatar data. This consists of the image data. * * Avatars can be sent at any time the client wishes. Generally, a client will -- cgit v1.2.3 From 5ea703c844b12e86702c35b53b0b798fe5f86634 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 29 May 2015 19:01:14 -0400 Subject: Comment fix. --- other/apidsl/tox.in.h | 9 ++------- toxcore/tox.h | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index 87d0ab87..fc66dfac 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -611,13 +611,8 @@ uint8_t[size] savedata { * Sends a "get nodes" request to the given bootstrap node with IP, port, and * public key to setup connections. * - * This function will attempt to connect to the node using UDP and TCP at the - * same time. - * - * Tox will use the node as a TCP relay in case ${options.this.udp_enabled} was - * false, and also to connect to friends that are in TCP-only mode. Tox will - * also use the TCP connection when NAT hole punching is slow, and later switch - * to UDP if hole punching succeeds. + * This function will attempt to connect to the node using UDP. You must use + * this function even if ${options.this.udp_enabled} was set to false. * * @param address The hostname or IP address (IPv4 or IPv6) of the node. * @param port The port on the host on which the bootstrap Tox instance is diff --git a/toxcore/tox.h b/toxcore/tox.h index cf5491af..e5158915 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -679,13 +679,8 @@ typedef enum TOX_ERR_BOOTSTRAP { * Sends a "get nodes" request to the given bootstrap node with IP, port, and * public key to setup connections. * - * This function will attempt to connect to the node using UDP and TCP at the - * same time. - * - * Tox will use the node as a TCP relay in case Tox_Options.udp_enabled was - * false, and also to connect to friends that are in TCP-only mode. Tox will - * also use the TCP connection when NAT hole punching is slow, and later switch - * to UDP if hole punching succeeds. + * This function will attempt to connect to the node using UDP. You must use + * this function even if Tox_Options.udp_enabled was set to false. * * @param address The hostname or IP address (IPv4 or IPv6) of the node. * @param port The port on the host on which the bootstrap Tox instance is -- cgit v1.2.3 From 240561b5574b0904543df20ea830f84ecbc13b0e Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 30 May 2015 21:06:38 -0400 Subject: Return port error if tcp server failed to init. --- toxcore/tox.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toxcore/tox.c b/toxcore/tox.c index 3081a226..d3b021aa 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -214,6 +214,8 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) if (m_error == MESSENGER_ERROR_PORT) { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); + } else if (m_error == MESSENGER_ERROR_TCP_SERVER) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); } else { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); } -- cgit v1.2.3 From b072c692e7cc38a123a465d00fc4ea9145d063b2 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 31 May 2015 20:10:38 -0400 Subject: Congestion control tweaks. --- toxcore/net_crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 6d4f6a9b..96be059d 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2006,7 +2006,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet #define PACKET_RESEND_MULTIPLIER 2 /* Timeout for increasing speed after congestion event (in ms). */ -#define CONGESTION_EVENT_TIMEOUT 4000 +#define CONGESTION_EVENT_TIMEOUT 2000 static void send_crypto_packets(Net_Crypto *c) { @@ -2086,7 +2086,7 @@ static void send_crypto_packets(Net_Crypto *c) PACKET_COUNTER_AVERAGE_INTERVAL)); if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { - conn->packet_send_rate = min_speed * 1.2; + conn->packet_send_rate = min_speed * 1.25; } else { conn->packet_send_rate = min_speed; } -- cgit v1.2.3 From 17f73765811e4d13d82cc6dceb864225779e0058 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 1 Jun 2015 20:16:03 -0400 Subject: Add a test for loading with a secret key. --- auto_tests/tox_test.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 22528330..501c93dc 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -357,6 +357,23 @@ START_TEST(test_one) tox_self_get_name(tox2, new_name); ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); + uint8_t sk[TOX_SECRET_KEY_SIZE]; + tox_self_get_secret_key(tox2, sk); + tox_kill(tox2); + + tox_options_default(&options); + options.savedata_type = TOX_SAVEDATA_TYPE_SECRET_KEY; + options.savedata_data = sk; + options.savedata_length = sizeof(sk); + tox2 = tox_new(&options, &err_n); + ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); + uint8_t address3[TOX_ADDRESS_SIZE]; + tox_self_get_address(tox2, address3); + ck_assert_msg(memcmp(address3, address, TOX_PUBLIC_KEY_SIZE) == 0, "Wrong public key."); + uint8_t pk[TOX_PUBLIC_KEY_SIZE]; + tox_self_get_public_key(tox2, pk); + ck_assert_msg(memcmp(pk, address, TOX_PUBLIC_KEY_SIZE) == 0, "Wrong public key."); + tox_kill(tox1); tox_kill(tox2); } @@ -1194,7 +1211,7 @@ Suite *tox_suite(void) DEFTESTCASE(one); DEFTESTCASE_SLOW(few_clients, 50); - DEFTESTCASE_SLOW(many_clients, 150); + DEFTESTCASE_SLOW(many_clients, 80); DEFTESTCASE_SLOW(many_clients_tcp, 20); DEFTESTCASE_SLOW(many_clients_tcp_b, 20); DEFTESTCASE_SLOW(many_group, 100); -- cgit v1.2.3 From 097422a02c3f67edd98833f65e57d76f06c18766 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 2 Jun 2015 19:56:12 -0400 Subject: Small change. --- toxcore/group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toxcore/group.c b/toxcore/group.c index c688ccff..af2cb492 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1149,7 +1149,7 @@ int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_n * return 0 on success * return -1 on failure */ -int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) +static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) { uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; -- cgit v1.2.3 From 99a678dd2670a5b7f71b5821db7b6dc2eb9be28d Mon Sep 17 00:00:00 2001 From: Zetok Zalbavar Date: Wed, 3 Jun 2015 09:35:58 +0100 Subject: Update INSTALL.md a bit * add install instructions for Gentoo * adjust build instructions for presence of libsodium in some distros --- INSTALL.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 549a3a4f..b7f1e5a0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,6 +2,9 @@ - [Installation](#installation) - [Unix like](#unix) + - [Quick install](#quick-install) + - [Build manually](#build-manually) + - [Compile toxcore](#compile-toxcore) - [OS X](#osx) - [Homebrew](#homebrew) - [Non-Homebrew](#non-homebrew) @@ -24,16 +27,33 @@ ###Most Unix like OSes: +#### Quick install: + +On Gentoo: +``` +# layman -f && layman -a tox-overlay && emerge net-libs/tox +``` + +And you're done `:)`
+If you happen to run some other distro which isn't made for compiling, there are steps below: + +#### Build manually + Build dependencies: Note: package fetching commands may vary by OS. -On Ubuntu: +On Ubuntu `< 15.04` / Debian `< 8`: ```bash sudo apt-get install build-essential libtool autotools-dev automake checkinstall check git yasm ``` +On Ubuntu `>= 15.04` / Debian `>= 8`: +```bash +sudo apt-get install build-essential libtool autotools-dev automake checkinstall check git yasm libsodium13 libsodium-dev +``` + On Fedora: ```bash @@ -55,7 +75,7 @@ Note, if you install from ports select NaCl for performance, and sodium if you w **For A/V support, also install the dependences listed in the [libtoxav] (#libtoxav) section.** -You should get and install [libsodium](https://github.com/jedisct1/libsodium): +You should get and install [libsodium](https://github.com/jedisct1/libsodium). If you have installed `libsodium` from repo, ommit this step, and jump directly to [compiling toxcore](#compile-toxcore): ```bash git clone git://github.com/jedisct1/libsodium.git cd libsodium @@ -88,7 +108,9 @@ echo '/usr/local/lib/' | sudo tee -a /etc/ld.so.conf.d/locallib.conf sudo ldconfig ``` -Then clone this repo and generate makefile: +##### Compile toxcore + +Then clone this repo, generate makefile, and install `toxcore` system-wide: ```bash git clone git://github.com/irungentoo/toxcore.git cd toxcore -- cgit v1.2.3 From 6d883f488ff59b2394982b62895d50b1d1d55bf4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 3 Jun 2015 19:56:12 -0400 Subject: Return error if file_id parameter is NULL. --- other/apidsl/tox.in.h | 1 + toxcore/tox.c | 5 +++++ toxcore/tox.h | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index fc66dfac..30c78e44 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -1651,6 +1651,7 @@ namespace file { error for get { + NULL, /** * The friend_number passed did not designate a valid friend. */ diff --git a/toxcore/tox.c b/toxcore/tox.c index d3b021aa..3e9db766 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -1011,6 +1011,11 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, TOX_ERR_FILE_GET *error) { + if (!file_id) { + SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); + return 0; + } + const Messenger *m = tox; int ret = file_get_id(m, friend_number, file_number, file_id); diff --git a/toxcore/tox.h b/toxcore/tox.h index e5158915..14c9f616 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1780,6 +1780,11 @@ typedef enum TOX_ERR_FILE_GET { */ TOX_ERR_FILE_GET_OK, + /** + * One of the arguments to the function was NULL when it was not expected. + */ + TOX_ERR_FILE_GET_NULL, + /** * The friend_number passed did not designate a valid friend. */ -- cgit v1.2.3