Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
developers:client_examples:echo_bot [2016/11/13 08:46] – Updated the example to use TokTok/c-toxcore nurupo | developers:client_examples:echo_bot [2020/03/23 22:08] (current) – Minor code fixes nurupo | ||
---|---|---|---|
Line 68: | Line 68: | ||
Now we know that to be online in the context of Tox it means to connect to the DHT, so let's do that. First we need to know IP and port of a DHT node, as well as its public key, to be able to protect the communication. In Tox, every peer who has UDP connections enabled is a DHT node, even our Echo Bot. This means that it is possible for someone to connect to the DHT (i.e. to bootstrap) through our bot. However, in contrast to regular Tox peers, users using Tox to communicate with their friends, DHT nodes can be dedicated, i.e. have a more permanent IP address and be online most of the time, which means that knowing IP, port and public key of just few nodes is generally enough to be able to always connect to the DHT network. Because using dedicated DHT nodes to connect to the DHT is more reliable, since they are more likely to be online when we want to bootstrap into the DHT, that's what we will be using. Tox's wiki contains [[https:// | Now we know that to be online in the context of Tox it means to connect to the DHT, so let's do that. First we need to know IP and port of a DHT node, as well as its public key, to be able to protect the communication. In Tox, every peer who has UDP connections enabled is a DHT node, even our Echo Bot. This means that it is possible for someone to connect to the DHT (i.e. to bootstrap) through our bot. However, in contrast to regular Tox peers, users using Tox to communicate with their friends, DHT nodes can be dedicated, i.e. have a more permanent IP address and be online most of the time, which means that knowing IP, port and public key of just few nodes is generally enough to be able to always connect to the DHT network. Because using dedicated DHT nodes to connect to the DHT is more reliable, since they are more likely to be online when we want to bootstrap into the DHT, that's what we will be using. Tox's wiki contains [[https:// | ||
- | ^ IP ^ Port ^ Public Key ^ | + | ^ IP ^ Port |
- | | 178.62.250.138 | 33445 | '' | + | | 85.143.221.42 | 33445 | '' |
- | | 2a03:b0c0:2:d0::16:1 | 33445 | '' | + | | 2a04:ac00:1:9f00:5054:ff:fe01: |
- | | tox.zodiaclabs.org | 33445 | '' | + | | 78.46.73.141 |
- | | 163.172.136.118 | + | | 2a01: |
- | | 2001: | + | | tox.initramfs.io |
- | | 128.199.199.197 | + | | tox2.abilinski.com |
- | | 2400: | + | | 205.185.115.131 |
- | | biribiri.org | 33445 | '' | + | | tox.kurnevsky.net | 33445 | '' |
We will use '' | We will use '' | ||
Line 106: | Line 106: | ||
uint16_t port; | uint16_t port; | ||
const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; // 1 for null terminator | const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; // 1 for null terminator | ||
- | unsigned char key_bin[TOX_PUBLIC_KEY_SIZE]; | ||
} DHT_node; | } DHT_node; | ||
Line 113: | Line 112: | ||
DHT_node nodes[] = | DHT_node nodes[] = | ||
{ | { | ||
- | {"178.62.250.138", | + | {"85.143.221.42", |
- | {"2a03:b0c0:2:d0::16:1", | + | {"2a04:ac00:1:9f00:5054:ff:fe01:becd", 33445, "DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43"}, |
- | {"tox.zodiaclabs.org", | + | {"78.46.73.141", |
- | {"163.172.136.118", | + | {"2a01: |
- | {"2001: | + | {"tox.initramfs.io", |
- | {"128.199.199.197", | + | {"tox2.abilinski.com", |
- | {"2400: | + | {"205.185.115.131", |
- | {"biribiri.org", | + | {"tox.kurnevsky.net", |
}; | }; | ||
for (size_t i = 0; i < sizeof(nodes)/ | for (size_t i = 0; i < sizeof(nodes)/ | ||
- | sodium_hex2bin(nodes[i].key_bin, sizeof(nodes[i].key_bin), | + | |
- | nodes[i].key_hex, | + | |
- | tox_bootstrap(tox, | + | NULL, NULL, NULL); |
+ | tox_bootstrap(tox, | ||
} | } | ||
</ | </ | ||
Line 319: | Line 319: | ||
uint16_t port; | uint16_t port; | ||
const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; | const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; | ||
- | unsigned char key_bin[TOX_PUBLIC_KEY_SIZE]; | ||
} DHT_node; | } DHT_node; | ||
void friend_request_cb(Tox *tox, const uint8_t *public_key, | void friend_request_cb(Tox *tox, const uint8_t *public_key, | ||
- | void *user_data) | + | void *user_data) |
{ | { | ||
tox_friend_add_norequest(tox, | tox_friend_add_norequest(tox, | ||
Line 329: | Line 328: | ||
void friend_message_cb(Tox *tox, uint32_t friend_number, | void friend_message_cb(Tox *tox, uint32_t friend_number, | ||
- | size_t length, void *user_data) | + | size_t length, void *user_data) |
{ | { | ||
tox_friend_send_message(tox, | tox_friend_send_message(tox, | ||
Line 361: | Line 360: | ||
DHT_node nodes[] = | DHT_node nodes[] = | ||
{ | { | ||
- | {"178.62.250.138", | + | {"85.143.221.42", |
- | {"2a03:b0c0:2:d0::16:1", | + | {"2a04:ac00:1:9f00:5054:ff:fe01:becd", 33445, "DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43"}, |
- | {"tox.zodiaclabs.org", | + | {"78.46.73.141", |
- | {"163.172.136.118", | + | {"2a01: |
- | {"2001: | + | {"tox.initramfs.io", |
- | {"128.199.199.197", | + | {"tox2.abilinski.com", |
- | {"2400: | + | {"205.185.115.131", |
- | {"biribiri.org", | + | {"tox.kurnevsky.net", |
}; | }; | ||
for (size_t i = 0; i < sizeof(nodes)/ | for (size_t i = 0; i < sizeof(nodes)/ | ||
- | sodium_hex2bin(nodes[i].key_bin, sizeof(nodes[i].key_bin), | + | |
- | nodes[i].key_hex, | + | |
- | tox_bootstrap(tox, | + | NULL, NULL, NULL); |
+ | tox_bootstrap(tox, | ||
} | } | ||
Line 393: | Line 393: | ||
tox_callback_self_connection_status(tox, | tox_callback_self_connection_status(tox, | ||
+ | |||
+ | printf(" | ||
while (1) { | while (1) { | ||
Line 417: | Line 419: | ||
$ ./echo_bot | $ ./echo_bot | ||
Tox ID: 4F8E7814B40B22F7DBB8B18B8518EBB369F45DE6B40309F43F39AFECF340FD7624FC706CE668 | Tox ID: 4F8E7814B40B22F7DBB8B18B8518EBB369F45DE6B40309F43F39AFECF340FD7624FC706CE668 | ||
+ | Connecting... | ||
Online, using UDP | Online, using UDP | ||
</ | </ | ||
Line 472: | Line 475: | ||
uint16_t port; | uint16_t port; | ||
const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; | const char key_hex[TOX_PUBLIC_KEY_SIZE*2 + 1]; | ||
- | unsigned char key_bin[TOX_PUBLIC_KEY_SIZE]; | ||
} DHT_node; | } DHT_node; | ||
Line 492: | Line 494: | ||
fseek(f, 0, SEEK_SET); | fseek(f, 0, SEEK_SET); | ||
- | | + | |
fread(savedata, | fread(savedata, | ||
Line 514: | Line 516: | ||
{ | { | ||
size_t size = tox_get_savedata_size(tox); | size_t size = tox_get_savedata_size(tox); | ||
- | | + | |
tox_get_savedata(tox, | tox_get_savedata(tox, | ||
Line 530: | Line 532: | ||
DHT_node nodes[] = | DHT_node nodes[] = | ||
{ | { | ||
- | {"178.62.250.138", | + | {"85.143.221.42", |
- | {"2a03:b0c0:2:d0::16:1", | + | {"2a04:ac00:1:9f00:5054:ff:fe01:becd", 33445, "DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43"}, |
- | {"tox.zodiaclabs.org", | + | {"78.46.73.141", |
- | {"163.172.136.118", | + | {"2a01: |
- | {"2001: | + | {"tox.initramfs.io", |
- | {"128.199.199.197", | + | {"tox2.abilinski.com", |
- | {"2400: | + | {"205.185.115.131", |
- | {"biribiri.org", | + | {"tox.kurnevsky.net", |
}; | }; | ||
for (size_t i = 0; i < sizeof(nodes)/ | for (size_t i = 0; i < sizeof(nodes)/ | ||
- | sodium_hex2bin(nodes[i].key_bin, sizeof(nodes[i].key_bin), | + | |
- | nodes[i].key_hex, | + | |
- | tox_bootstrap(tox, | + | NULL, NULL, NULL); |
+ | tox_bootstrap(tox, | ||
} | } | ||
} | } | ||
Line 563: | Line 566: | ||
void friend_request_cb(Tox *tox, const uint8_t *public_key, | void friend_request_cb(Tox *tox, const uint8_t *public_key, | ||
- | void *user_data) | + | void *user_data) |
{ | { | ||
tox_friend_add_norequest(tox, | tox_friend_add_norequest(tox, | ||
Line 571: | Line 574: | ||
void friend_message_cb(Tox *tox, uint32_t friend_number, | void friend_message_cb(Tox *tox, uint32_t friend_number, | ||
- | size_t length, void *user_data) | + | size_t length, void *user_data) |
{ | { | ||
tox_friend_send_message(tox, | tox_friend_send_message(tox, | ||
Line 611: | Line 614: | ||
update_savedata_file(tox); | update_savedata_file(tox); | ||
+ | |||
+ | printf(" | ||
while (1) { | while (1) { |