All Projects → TokTok → c-toxcore

TokTok / c-toxcore

Licence: GPL-3.0 license
The future of online communications.

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
shell
77523 projects
M4
1887 projects
CMake
9771 projects
Starlark
911 projects

Projects that are alternatives of or similar to c-toxcore

pop
Run a point-of-presence within Myel, the community powered content delivery network.
Stars: ✭ 28 (-98.38%)
Mutual labels:  p2p
lens
The official network explorer for Wavelet.
Stars: ✭ 28 (-98.38%)
Mutual labels:  p2p
squeaknode
Peer-to-peer status feed 📜 with posts unlocked by Lightning ⚡
Stars: ✭ 29 (-98.32%)
Mutual labels:  p2p
husarnet
Husarnet is a Peer-to-Peer VPN to connect your laptops, servers and microcontrollers over the Internet with zero configuration.
Stars: ✭ 128 (-92.6%)
Mutual labels:  p2p
dat-workshop
How to build web apps using Dat. A workshop by GEUT.
Stars: ✭ 50 (-97.11%)
Mutual labels:  p2p
matchbox
Painless peer-to-peer WebRTC networking for rust wasm
Stars: ✭ 276 (-84.05%)
Mutual labels:  p2p
p2psec
research on privacy and security in p2p and decentralised systems
Stars: ✭ 38 (-97.8%)
Mutual labels:  p2p
bittensor
Internet-scale Neural Networks
Stars: ✭ 97 (-94.39%)
Mutual labels:  p2p
webrtc-lab
WebRTC 연구실 🌎
Stars: ✭ 55 (-96.82%)
Mutual labels:  p2p
Horizon
A ZeroNet search engine
Stars: ✭ 15 (-99.13%)
Mutual labels:  p2p
go-pdu
Parallel Digital Universe - A decentralized social networking service
Stars: ✭ 39 (-97.75%)
Mutual labels:  p2p
SentryPeer
A distributed peer to peer list of bad actor IP addresses and phone numbers collected via a SIP Honeypot.
Stars: ✭ 108 (-93.76%)
Mutual labels:  p2p
spec
Tox Protocol Specification
Stars: ✭ 29 (-98.32%)
Mutual labels:  toxcore
namecoin-core
Namecoin full node + wallet based on the current Bitcoin Core codebase.
Stars: ✭ 425 (-75.43%)
Mutual labels:  p2p
rdoc
Conflict-free replicated JSON implementation in native Go
Stars: ✭ 76 (-95.61%)
Mutual labels:  p2p
hybrixd
hybrix-daemon: the network agent for the hybrix node: https://api.hybrix.io/help/hybrixd
Stars: ✭ 28 (-98.38%)
Mutual labels:  p2p
fengming
No description or website provided.
Stars: ✭ 14 (-99.19%)
Mutual labels:  p2p
nkn-shell-daemon
NKN shell daemon
Stars: ✭ 29 (-98.32%)
Mutual labels:  p2p
workshop-todo-dapp
A workshop into adding realtime collaboration in a typical To-do app
Stars: ✭ 29 (-98.32%)
Mutual labels:  p2p
tensorpeers
p2p peer-to-peer training of tensorflow models
Stars: ✭ 57 (-96.71%)
Mutual labels:  p2p

Project Tox

Current Coverage: coverage

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

IRC Channels: Users: #[email protected], Developers: #[email protected]

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 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 NaCl 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.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].