summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-14 20:47:20 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-01-18 18:13:31 +0000
commit6d6a4e1e3a96c6fa3e5e07ed57912baf67691ff2 (patch)
tree0f7a6d6718d3b8915c2143ee74e15af6bf0403e6 /README.md
parenta22f5e7c6ff5607c6d5b4c5b843bbe9460ad199b (diff)
Add tutorial and "danger: experimental" banner to README.
Diffstat (limited to 'README.md')
-rw-r--r--README.md207
1 files changed, 159 insertions, 48 deletions
diff --git a/README.md b/README.md
index 97bcd6b8..7a1ffe7f 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
1![Project Tox](https://raw.github.com/TokTok/toxcore/master/other/tox.png "Project Tox") 1# ![Project Tox](https://raw.github.com/TokTok/toxcore/master/other/tox.png "Project Tox")
2***
3 2
4**Current build status:** [![Build Status](https://travis-ci.org/TokTok/c-toxcore.svg?branch=master)](https://travis-ci.org/TokTok/c-toxcore) 3**Current build status:** [![Build Status](https://travis-ci.org/TokTok/c-toxcore.svg?branch=master)](https://travis-ci.org/TokTok/c-toxcore)
5**Current Coverage:** [![Coverage Status](https://coveralls.io/repos/github/TokTok/toxcore/badge.svg?branch=master)](https://coveralls.io/github/TokTok/toxcore?branch=master) 4**Current Coverage:** [![Coverage Status](https://coveralls.io/repos/github/TokTok/toxcore/badge.svg?branch=master)](https://coveralls.io/github/TokTok/toxcore?branch=master)
@@ -8,56 +7,168 @@
8 7
9**IRC Channels:** Users: [#tox@freenode](https://webchat.freenode.net/?channels=tox), Developers: [#toktok@freenode](https://webchat.freenode.net/?channels=toktok) 8**IRC Channels:** Users: [#tox@freenode](https://webchat.freenode.net/?channels=tox), Developers: [#toktok@freenode](https://webchat.freenode.net/?channels=toktok)
10 9
11## Toxcore Development Roadmap 10## What is Tox
12This Roadmap is somewhat tentative, but should give you a good idea of where
13we're going, and where we've been.
14
15Currently unsorted, the following is intended to function as a discussion guide
16to developers/contributors.
17
18### In Progress
19- [ ] Toxcore
20 - [ ] 100% unit testing
21 - [ ] Make ToxAV stateless
22 - [ ] Allow a single toxcore instance to handle multiple keypairs (or 'clients')
23 - [ ] Consistent naming scheme throughout toxcore
24 - [X] Make toxcore stateless
25- [ ] Messenger
26 - [ ] Improve group chat implementation
27 - [ ] Improve A/V implementation
28 - [ ] Multiple device support
29
30### Done
31- [X] Create Toxcore
32- [X] Create DHT
33- [X] Create Onion
34- [X] Implement Crypto
35- [X] Create Messenger
36
37## Q&A:
38 11
39### What is Tox? 12Tox is a peer to peer (serverless) instant messenger aimed at making security
13and privacy easy to obtain for regular users. It uses
14[NaCl](https://nacl.cr.yp.to/) for its encryption and authentication.
40 15
41Tox is a fully encrypted, censor resistant, private, distributed network library with a focus on personal communications. 16## IMPORTANT!
42 17
43### No, really, what's Tox? 18### ![Danger: Experimental](other/tox-warning.png)
44 19
45It's a VERY secure Instant Messenger that supports Text, Audio/Video calls, group chats, audio group chats, and file transfers. There's dozens, but our advantage is we put security first, from day 1. We didn't decide to add it in after. 20This is an **experimental** cryptographic network library. It has not been
21formally audited by an independent third party that specializes in
22cryptography or cryptanalysis. **Use this library at your own risk.**
46 23
47### What are your goals with Tox? 24The underlying crypto library [NaCl](https://nacl.cr.yp.to/install.html)
25provides reliable encryption, but the security model has not yet been fully
26specified. See [issue 210](https://github.com/TokTok/c-toxcore/issues/210) for
27a discussion on developing a threat model. See other issues for known
28weaknesses (e.g. [issue 426](https://github.com/TokTok/c-toxcore/issues/426)
29describes what can happen if your secret key is stolen).
48 30
49We want Tox to be as simple as possible while remaining as secure as possible. 31## Toxcore Development Roadmap
50
51## Documentation:
52- [Compiling](/INSTALL.md)
53- [DHT Protocol](/docs/updates/DHT.md)<br />
54- [Crypto](/docs/updates/Crypto.md)<br />
55
56## The Complex Stuff:
57### UDP vs. TCP
58Tox must use UDP simply because [hole punching](https://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
59However, Tox does use [TCP relays](/docs/TCP_Network.txt) as a fallback if it encounters a firewall that prevents UDP hole punching.
60
61### Connecting & Communicating
62Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key [Tox ID] of the peer). By using torrent-style DHT, peers can find the IP of other peers by using their Tox ID. Once the IP is obtained, peers can initiate a [secure](/docs/updates/Crypto.md) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications.
63 32
33The roadmap and changelog are generated from GitHub issues. You may view them
34on the website, where they are updated at least once every 24 hours:
35
36- Changelog: https://toktok.ltd/changelog/c-toxcore
37- Roadmap: https://toktok.ltd/roadmap/c-toxcore
38
39## Installing toxcore
40
41Detailed installation instructions can be found in [INSTALL.md](INSTALL.md).
42
43In a nutshell, if you have [libsodium](https://github.com/jedisct1/libsodium)
44or [nacl](https://nacl.cr.yp.to/install.html) installed, run:
45
46```sh
47autoreconf -fi
48mkdir _build && cd _build
49../configure
50make
51sudo make install
52```
53
54If you have [libvpx](https://github.com/webmproject/libvpx) and
55[opus](https://github.com/xiph/opus) installed, the above will also build the
56A/V library for multimedia chats.
57
58## Using toxcore
59
60The simplest "hello world" example could be an echo bot. Here we will walk
61through the implementation of a simple bot.
62
63### Creating the tox instance
64
65All toxcore API functions work with error parameters. They are enums with one
66`OK` value and several error codes that describe the different situations in
67which the function might fail.
68
69```c
70TOX_ERR_NEW err_new;
71Tox *tox = tox_new(NULL, &err_new);
72if (err_new != TOX_ERR_NEW_OK) {
73 fprintf(stderr, "tox_new failed with error code %d\n", err_new);
74 exit(1);
75}
76```
77
78Here, we simply exit the program, but in a real client you will probably want
79to do some error handling and proper error reporting to the user. The `NULL`
80argument given to the first parameter of `tox_new` is the `Tox_Options`. It
81contains various write-once network settings and allows you to load a
82previously serialised instance. See [toxcore/tox.h](tox.h) for details.
83
84### Setting up callbacks
85
86Toxcore works with callbacks that you can register to listen for certain
87events. Examples of such events are "friend request received" or "friend sent
88a message". Search the API for `tox_callback_*` to find all of them.
89
90Here, we will set up callbacks for receiving friend requests and receiving
91messages. We will always accept any friend request (because we're a bot), and
92when we receive a message, we send it back to the sender.
93
94```c
95tox_callback_friend_request(tox, handle_friend_request);
96tox_callback_friend_message(tox, handle_friend_message);
97```
98
99These two function calls set up the callbacks. Now we also need to implement
100these "handle" functions.
101
102### Handle friend requests
103
104```c
105static void handle_friend_request(
106 Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length,
107 void *user_data) {
108 // Accept the friend request:
109 TOX_ERR_FRIEND_ADD err_friend_add;
110 tox_friend_add_norequest(tox, public_key, &err_friend_add);
111 if (err_friend_add != TOX_ERR_FRIEND_ADD_OK) {
112 fprintf(stderr, "unable to add friend: %d\n", err_friend_add);
113 }
114}
115```
116
117The `tox_friend_add_norequest` function adds the friend without sending them a
118friend request. Since we already got a friend request, this is the right thing
119to do. If you wanted to send a friend request yourself, you would use
120`tox_friend_add`, which has an extra parameter for the message.
121
122### Handle messages
123
124Now, when the friend sends us a message, we want to respond to them by sending
125them the same message back. This will be our "echo".
126
127```c
128static void handle_friend_message(
129 Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type,
130 const uint8_t *message, size_t length,
131 void *user_data) {
132 TOX_ERR_FRIEND_SEND_MESSAGE err_send;
133 tox_friend_send_message(tox, friend_number, type, message, length,
134 &err_send);
135 if (err_send != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
136 fprintf(stderr, "unable to send message back to friend %d: %d\n",
137 friend_number, err_send);
138 }
139}
140```
141
142That's it for the setup. Now we want to actually run the bot.
143
144### Main event loop
145
146Toxcore works with a main event loop function `tox_iterate` that you need to
147call at a certain frequency dictated by `tox_iteration_interval`. This is a
148polling function that receives new network messages and processes them.
149
150```c
151while (true) {
152 usleep(1000 * tox_iteration_interval(tox));
153 tox_iterate(tox, NULL);
154}
155```
156
157That's it! Now you have a working echo bot. The only problem is that since Tox
158works with public keys, and you can't really guess your bot's public key, you
159can't add it as a friend in your client. For this, we need to call another API
160function: `tox_self_get_address(tox, address)`. This will fill the 38 byte
161friend address into the `address` buffer. You can then display that binary
162string as hex and input it into your client. Writing a `bin2hex` function is
163left as exercise for the reader.
164
165We glossed over a lot of details, such as the user data which we passed to
166`tox_iterate` (passing `NULL`), bootstrapping into an actual network (this bot
167will work in the LAN, but not on an internet server) and the fact that we now
168have no clean way of stopping the bot (`while (true)`). If you want to write a
169real bot, you will probably want to read up on all the API functions. Consult
170the API documentation in [toxcore/tox.h](tox.h) for more information.
171
172### Other resources
173
174- [Another echo bot](https://wiki.tox.chat/developers/client_examples/echo_bot)