The future of online communications.
 
 
 
 
 
 
Go to file
iphydf ed2b60c217
chore: Use a specific non-broken slimcc version.
7b7c98604a broke it.
2024-02-28 15:51:36 +00:00
.circleci test: Add more unit tests for `add_to_list`. 2024-01-10 02:58:13 +00:00
.clusterfuzzlite fix: Make all the fuzzers work again, and add a test for protodump. 2024-01-13 15:06:30 +00:00
.devcontainer chore: Add devcontainer setup for codespaces. 2023-08-30 09:51:14 +00:00
.github chore: Update github actions. 2024-02-23 16:01:25 +00:00
auto_tests chore: Remove mod and founder from group API naming scheme 2024-02-23 00:29:48 -05:00
build test: Add a simple test for `ip_ntoa`. 2021-12-09 20:51:15 +00:00
cmake test: Add fuzz tests to the coverage run. 2024-01-12 12:33:41 +00:00
docs docs: Run prettier-markdown on markdown files. 2024-02-09 02:49:21 +00:00
m4 Build system now automatically enables epoll support in TCP server 2014-07-17 20:44:49 -04:00
other chore: Use a specific non-broken slimcc version. 2024-02-28 15:51:36 +00:00
super_donators cleanup: Remove explicit layering_check feature. 2023-11-23 23:55:57 +00:00
testing refactor: Use strong typedef instead of struct for `Socket`. 2024-02-09 01:10:06 +00:00
third_party docs: Add more documentation to crypto_core. 2024-02-06 22:02:55 +00:00
toxav cleanup: Remove implicit bool conversions. 2024-02-02 01:31:54 +00:00
toxcore chore: Remove mod and founder from group API naming scheme 2024-02-23 00:29:48 -05:00
toxencryptsave chore: Reformat sources with astyle. 2024-02-02 01:31:32 +00:00
.cirrus.yml test: Add FreeBSD VM action on GitHub. 2024-02-19 20:15:18 +00:00
.clang-format test: Add fuzzer tests to the bazel build. 2022-03-25 18:48:41 +00:00
.clang-tidy refactor: Use strong typedef instead of struct for `Socket`. 2024-02-09 01:10:06 +00:00
.dockerignore test: Add an s390x build (on alpine) for CI. 2023-11-22 18:29:26 +00:00
.editorconfig Add .editorconfig 2017-12-25 10:55:04 -06:00
.gitignore chore: add clangd files to .gitignore 2024-01-15 12:12:28 +01:00
.gitmodules chore(deps): Use upstream cmp directly instead of our fork. 2022-04-03 09:02:31 +00:00
.hadolint.yaml feat: Add binary packing functions for tox events. 2022-02-07 02:43:24 +00:00
.restyled.yaml docs: Run prettier-markdown on markdown files. 2024-02-09 02:49:21 +00:00
BUILD.bazel chore: Use GPL license with https. 2024-01-01 11:43:27 +00:00
CHANGELOG.md Release 0.2.18 2022-04-18 20:12:07 +02:00
CMakeLists.txt docs: Update the list of CMake options 2024-02-23 08:22:31 -05:00
CMakePresets.json chore: Simplify msvc build using vcpkg. 2024-01-06 12:27:31 +00:00
DONATORS If we receive a packet from a node we are searching for, ping it. 2015-12-08 15:43:03 -05:00
INSTALL.md docs: Update the list of CMake options 2024-02-23 08:22:31 -05:00
LICENSE chore: Use GPL license with https. 2024-01-01 11:43:27 +00:00
Makefile.am fix broken and unmaintained autotools build 2018-04-18 00:13:15 +02:00
README.md docs: Add static analysis tool list to README. 2024-02-09 02:49:34 +00:00
autogen.sh Some configuration/build fixes, so building basicaly everything else than the library can be disabled 2013-10-07 02:01:16 +02:00
azure-pipelines.yml chore: Cancel old PR builds on docker and sonar-scan workflows. 2023-11-22 23:38:50 +00:00
codecov.yml refactor: Add `mem` module to allow tests to override allocators. 2023-08-30 22:55:05 +00:00
conanfile.py chore: Set a timeout for tests started using Conan 2023-08-29 13:26:12 +00:00
configure.ac cleanup: Remove NaCl support. 2023-12-25 00:36:38 +00:00
libtoxav.pc.in Build system fixes. 2014-12-18 10:04:31 -05:00
libtoxcore.pc.in cleanup: Remove NaCl support. 2023-12-25 00:36:38 +00:00
netlify.toml cleanup: Add more nonnull and nullable annotations. 2022-02-09 20:03:34 +00:00
so.version Release 0.2.18 2022-04-18 20:12:07 +02:00
sonar-project.properties test: Add more unit tests for `add_to_list`. 2024-01-10 02:58:13 +00:00
tox.spec.in Use the markdown GPLv3 license in the c-toxcore repo. 2018-02-08 16:08:09 +00:00
vcpkg.json chore: Simplify msvc build using vcpkg. 2024-01-06 12:27:31 +00:00

README.md

Project Tox

Current Coverage: coverage

Website | Wiki | Blog | FAQ | Binaries/Downloads | Clients | Compiling

What is Tox

Tox is a peer to peer (serverless) instant messenger aimed at making security and privacy easy to obtain for regular users. It uses libsodium (based on NaCl) for its encryption and authentication.

IMPORTANT!

Danger: Experimental

This is an experimental cryptographic network library. It has not been formally audited by an independent third party that specializes in cryptography or cryptanalysis. Use this library at your own risk.

The underlying crypto library libsodium provides reliable encryption, but the security model has not yet been fully specified. See issue 210 for a discussion on developing a threat model. See other issues for known weaknesses (e.g. issue 426 describes what can happen if your secret key is stolen).

Toxcore Development Roadmap

The roadmap and changelog are generated from GitHub issues. You may view them on the website, where they are updated at least once every 24 hours:

Installing toxcore

Detailed installation instructions can be found in INSTALL.md.

Be advised that due to the addition of cmp as a submodule, you now also need to initialize the git submodules required by toxcore. This can be done by cloning the repo with the following command: git clone --recurse-submodules https://github.com/Toktok/c-toxcore or by running git submodule update --init in the root directory of the repo.

In a nutshell, if you have libsodium installed, run:

mkdir _build && cd _build
cmake ..
make
sudo make install

If you have libvpx and opus installed, the above will also build the A/V library for multimedia chats.

Using toxcore

The simplest "hello world" example could be an echo bot. Here we will walk through the implementation of a simple bot.

Creating the tox instance

All toxcore API functions work with error parameters. They are enums with one OK value and several error codes that describe the different situations in which the function might fail.

TOX_ERR_NEW err_new;
Tox *tox = tox_new(NULL, &err_new);
if (err_new != TOX_ERR_NEW_OK) {
  fprintf(stderr, "tox_new failed with error code %d\n", err_new);
  exit(1);
}

Here, we simply exit the program, but in a real client you will probably want to do some error handling and proper error reporting to the user. The NULL argument given to the first parameter of tox_new is the Tox_Options. It contains various write-once network settings and allows you to load a previously serialised instance. See toxcore/tox.h for details.

Setting up callbacks

Toxcore works with callbacks that you can register to listen for certain events. Examples of such events are "friend request received" or "friend sent a message". Search the API for tox_callback_* to find all of them.

Here, we will set up callbacks for receiving friend requests and receiving messages. We will always accept any friend request (because we're a bot), and when we receive a message, we send it back to the sender.

tox_callback_friend_request(tox, handle_friend_request);
tox_callback_friend_message(tox, handle_friend_message);

These two function calls set up the callbacks. Now we also need to implement these "handle" functions.

Handle friend requests

static void handle_friend_request(
  Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length,
  void *user_data) {
  // Accept the friend request:
  TOX_ERR_FRIEND_ADD err_friend_add;
  tox_friend_add_norequest(tox, public_key, &err_friend_add);
  if (err_friend_add != TOX_ERR_FRIEND_ADD_OK) {
    fprintf(stderr, "unable to add friend: %d\n", err_friend_add);
  }
}

The tox_friend_add_norequest function adds the friend without sending them a friend request. Since we already got a friend request, this is the right thing to do. If you wanted to send a friend request yourself, you would use tox_friend_add, which has an extra parameter for the message.

Handle messages

Now, when the friend sends us a message, we want to respond to them by sending them the same message back. This will be our "echo".

static void handle_friend_message(
  Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type,
  const uint8_t *message, size_t length,
  void *user_data) {
  TOX_ERR_FRIEND_SEND_MESSAGE err_send;
  tox_friend_send_message(tox, friend_number, type, message, length,
    &err_send);
  if (err_send != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
    fprintf(stderr, "unable to send message back to friend %d: %d\n",
      friend_number, err_send);
  }
}

That's it for the setup. Now we want to actually run the bot.

Main event loop

Toxcore works with a main event loop function tox_iterate that you need to call at a certain frequency dictated by tox_iteration_interval. This is a polling function that receives new network messages and processes them.

while (true) {
  usleep(1000 * tox_iteration_interval(tox));
  tox_iterate(tox, NULL);
}

That's it! Now you have a working echo bot. The only problem is that since Tox works with public keys, and you can't really guess your bot's public key, you can't add it as a friend in your client. For this, we need to call another API function: tox_self_get_address(tox, address). This will fill the 38 byte friend address into the address buffer. You can then display that binary string as hex and input it into your client. Writing a bin2hex function is left as exercise for the reader.

We glossed over a lot of details, such as the user data which we passed to tox_iterate (passing NULL), bootstrapping into an actual network (this bot will work in the LAN, but not on an internet server) and the fact that we now have no clean way of stopping the bot (while (true)). If you want to write a real bot, you will probably want to read up on all the API functions. Consult the API documentation in toxcore/tox.h for more information.

Other resources

SAST Tools

This project uses various tools supporting Static Application Security Testing:

  • clang-tidy: A clang-based C++ "linter" tool.
  • Coverity: A cloud-based static analyzer service for Java, C/C++, C#, JavaScript, Ruby, or Python that is free for open source projects.
  • cppcheck: A static analyzer for C/C++ code.
  • cpplint: Static code checker for C++
  • goblint: A static analyzer for multi-threaded C programs, specializing in finding concurrency bugs.
  • infer: A static analyzer for Java, C, C++, and Objective-C.
  • PVS-Studio: A static analyzer for C, C++, C#, and Java code.
  • tokstyle: A style checker for TokTok C projects.